Upload 7 files
Browse filesFiles changed (7)
- README.mdAdded+160
- config (1).jsonAdded+1
- model (2).safetensorsAdded+3
- pytorch_model.binAdded+3
- special_tokens_map (1).jsonAdded+1
- tokenizer_config (1).jsonAdded+1
- vocab (1).txtAdded+7
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160# Gender Classification Quantized Model
This repository hosts a quantized version of a feedforward neural network model, fine-tuned for gender classification tasks. The model has been optimized for efficient deployment while maintaining high accuracy, making it suitable for resource-constrained environments.
---
## Model Details
- **Model Name:** Gender Classifier
- **Model Architecture:** 2-layer MLP (Multi-Layer Perceptron)
- **Task:** Gender Classification
- **Dataset:** Gender Classification Dataset v7
- **Quantization:** QInt8 (Dynamic Quantization)
- **Framework:** PyTorch
---
## Usage
### Installation
```bash
pip install torch pandas scikit-learn numpy
```
### Loading the Quantized Model
```python
import torch
import torch.nn as nn
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler, LabelEncoder
import json
# Define the model architecture
class GenderClassifier(nn.Module):
def __init__(self):
super().__init__()
self.fc = nn.Sequential(
nn.Linear(7, 32),
nn.ReLU(),
nn.Linear(32, 2)
)
def forward(self, x):
return self.fc(x)
# Load the quantized model
model = GenderClassifier()
quantized_model = torch.quantization.quantize_dynamic(model, {nn.Linear}, dtype=torch.qint8)
quantized_model.load_state_dict(torch.load("quantized_model/pytorch_model.bin"))
# Load configuration
with open("quantized_model/config.json", "r") as f:
config = json.load(f)
# Example usage
# Prepare your input data (7 features)
input_data = np.array([[feature1, feature2, feature3, feature4, feature5, feature6, feature7]])
# Normalize using StandardScaler (you'll need to fit this on your training data)
scaler = StandardScaler()
# scaler.fit(your_training_data) # Fit on your training data
input_normalized = scaler.transform(input_data)
# Convert to tensor
input_tensor = torch.tensor(input_normalized, dtype=torch.float32)
# Inference
with torch.no_grad():
outputs = quantized_model(input_tensor)
# Get predicted label
predicted_class = outputs.argmax(dim=1).item()
# Map label using label encoder classes
label_mapping = {0: config["label_classes"][0], 1: config["label_classes"][1]}
print(f"Predicted Gender: {label_mapping[predicted_class]}")
```
---
## Performance Metrics
- **Model Size:** Reduced through QInt8 quantization
- **Input Features:** 7 numerical features
- **Output Classes:** 2 (Binary gender classification)
- **Training Split:** 80% train, 20% validation
---
## Training Details
### Dataset
The model was trained on the Gender Classification Dataset v7, featuring:
- 7 numerical input features
- Binary gender classification labels
- Preprocessed and normalized data
### Training Configuration
- **Epochs:** 10
- **Batch Size:** 32
- **Learning Rate:** 0.001
- **Optimizer:** Adam
- **Loss Function:** CrossEntropyLoss
- **Normalization:** StandardScaler
### Model Architecture
- **Input Layer:** 7 features
- **Hidden Layer:** 32 neurons with ReLU activation
- **Output Layer:** 2 neurons (binary classification)
- **Total Parameters:** Approximately 288 parameters
### Quantization
Post-training dynamic quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency with QInt8 precision.
---
## Repository Structure
```
.
βββ quantized_model/
β βββ config.json # Model configuration
β βββ pytorch_model.bin # Quantized model weights
β βββ model.safetensors # Alternative model format
β βββ vocab.txt # Feature names
β βββ tokenizer_config.json # Scaler configuration
β βββ special_tokens_map.json # Label encoder metadata
βββ gender-classification.ipynb # Training notebook
βββ README.md # Model documentation
```
---
## Input Features
The model expects 7 numerical features as input. The exact feature names and preprocessing requirements are stored in the configuration files.
---
## Limitations
- The model is designed for binary gender classification only
- Performance depends on the similarity between inference data and training data distribution
- Quantization may result in minor accuracy changes compared to full-precision models
- Requires proper feature scaling using StandardScaler fitted on training data
---
## Contributing
Contributions are welcome! Feel free to open an issue or PR for improvements, fixes, or feature extensions.
---1{"input_features": ["long_hair", "forehead_width_cm", "forehead_height_cm", "nose_wide", "nose_long", "lips_thin", "distance_nose_to_lip_long"], "label_classes": ["Female", "Male"], "scaling": "StandardScaler", "model_architecture": "2-layer MLP"}123version https://git-lfs.github.com/spec/v1oid sha256:bb4973410ad93309f22dd9cda9cc407d625865c62295ca22521a4d5bd0994620size 296123version https://git-lfs.github.com/spec/v1oid sha256:59b193ba017a4a9e58cbb4b97855d7cd34cd381dea45f04b1e5a237a2be9de32size 39121{"label_encoder": "sklearn.LabelEncoder"}1{"scaler": "StandardScaler"}1234567long_hairforehead_width_cmforehead_height_cmnose_widenose_longlips_thindistance_nose_to_lip_longREADME.mdAdded+160
config (1).jsonAdded+1
model (2).safetensorsAdded+3
pytorch_model.binAdded+3
special_tokens_map (1).jsonAdded+1
tokenizer_config (1).jsonAdded+1
vocab (1).txtAdded+7