YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Real vs Synthetic Face Classifier
This package contains tools to classify images as Real or Synthetic (AI-Generated). It specifically targets high-quality generations (e.g., from ComfyUI/Flux) that are often difficult to detect.
Models
There are two trained models available. When uploading, you can choose one or both.
trained_classifier_random(Baselne ResNet):- Trained on standard dataset.
- Good for general detection, but might miss high-quality "hard" fakes.
trained_classifier_densenet_hard_mining(Recommended):- Trained on an expanded dataset including "Hard Negatives" (high-quality fakes that fooled the baseline).
- Architecture: DenseNet121.
- Higher robustness.
How to Share/Upload
Option A: Hugging Face (Simplest for Sharing)
- Create a new Model repository on Hugging Face.
- Upload the contents of this
deploymentfolder to the repo. - Crucial: You must also upload the
model_weights.pthandmodel_info.jsonfrom the trained model folder (e.g.,trained_classifier_densenet_hard_mining) into the root of your Hugging Face repo (or a subfolder).
Option B: GitHub
- Create a new repo.
- Commit this
deploymentfolder. - Warning: The
.pthweight files are large (~30-50MB). GitHub standard file limit is 100MB, so they should fit. If they are larger, you need Git LFS.git lfs installgit lfs track "*.pth"
Usage Guide (For your Users)
1. Installation
pip install -r requirements.txt
2. Run Inference
Use the inference.py script to classify a single image.
Command:
python inference.py path/to/image.jpg --model path/to/model_folder
Example:
# Assuming you downloaded the model weights into a folder named 'my_model'
python inference.py test_image.png --model my_model
3. Output
The script will print the confidence scores for both "Real" and "Synthetic".
It automatically handles background removal (using rembg) before classification, matching the training pipeline.