YOLOv8 Gender Classification Model
This repository contains a YOLOv8 classification model trained to identify gender (Male/Female) using the
Gender Classification Dataset.
Model Overview
-
Architecture: YOLOv8n-cls (Nano Classification)
-
Task: Single-label Image Classification
-
Classes: 2 (Male, Female)
-
Framework: Ultralytics YOLOv8
Dataset Information
The model was trained on the Gender Classification Dataset from Kaggle.
-
Train Images: 47,009
-
Validation Images: 11,649
-
Structure: Folder-based classification (each class in its own subdirectory).
⚖️ Privacy & Ethical Note
The dataset used for this training (
Gender Classification Dataset) does not provide explicit citations or provenance for the images included.
-
Privacy: Be aware that this dataset contains biometric data (faces). Use of this model should comply with local privacy laws (e.g., GDPR, CCPA).
-
Bias: Classification models trained on facial data can inherit biases present in the source imagery.
-
Proper Use: This model is intended for educational and research purposes.
Training Performance
The model reached high accuracy within 10 epochs.
| |
|---|
| Metric | Value |
| Top-1 Accuracy | 0.977 (97.7%) |
| Top-5 Accuracy | 1.0 |
| Training Time | ~0.636 hours (Tesla T4) |
| Model Size | 3.0 MB (FP16) |
🚀 Official Ultralytics Usage
1. Installation
Ensure you have the latest Ultralytics package installed.
pip install ultralytics
2. Python Inference (Official Example)
This is the recommended way to run inference using the official ultralytics API.
from ultralytics import YOLO
# 1. Load your custom-trained model
model = YOLO("best.pt")
# 2. Run inference on an image
# source can be a path, URL, PIL image, or OpenCV array
results = model.predict(source="path/to/image.jpg", imgsz=224)
# 3. Process results
for result in results:
# Print the top-1 class name and confidence
top1_idx = result.probs.top1
top1_conf = result.probs.top1conf.item()
print(f"Predicted Class: {result.names[top1_idx]} with {top1_conf:.4f} confidence")
# Optional: Display or save the annotated image
# result.show()
# result.save(filename='result.jpg')
3. CLI Inference
You can also run predictions directly from your terminal:
yolo classify predict model=best.pt source='path/to/image.jpg'
Training Configuration
For reproducibility, the following parameters were used during training:
from ultralytics import YOLO
import torch
# Load a pretrained YOLOv8n-cls model
model = YOLO("yolov8n-cls.pt")
# Start training
model.train(
data="path/to/dataset", # Root directory of your dataset
epochs=10,
batch=128,
imgsz=224,
device="cuda" if torch.cuda.is_available() else "cpu",
verbose=True
)
Export
To use this model in mobile or web applications, you can export it to various formats:
model.export(format="onnx") # ONNX for general deployment
model.export(format="tflite") # TFLite for mobile/Android
model.export(format="coreml") # CoreML for iOS