muneebnadeem1870's picture
Update README.md
e9cdba4 verified
metadata
language: en
tags:
  - deepfake
  - image-classification
  - computer-vision
  - swin-transformer
  - efficientnet
  - deep-learning
license: mit
datasets:
  - custom
metrics:
  - accuracy
model-index:
  - name: DeepFake Detection Swin-EfficientNet Hybrid
    results:
      - task:
          type: image-classification
          name: Image Classification
        dataset:
          name: Custom DeepFake Dataset
          type: images
        metrics:
          - type: accuracy
            value: 0.9867

🧠 Deepfake Detection using Swin Transformer

A robust deepfake detection model leveraging the microsoft/swin-base-patch4-window7-224 architecture. Built and trained on the "Hemg/deepfake-and-real-images" dataset with oversampling and image augmentations to ensure class balance and improved generalization.


πŸ“Œ Table of Contents


πŸ“¦ Cell1: Install Required Packages

pip install -q datasets transformers evaluate imbalanced-learn
pip install -U transformers

πŸ“₯ Cell2: Load Dataset & Apply Oversampling

Used the Hemg/deepfake-and-real-images dataset and applied RandomOverSampler from imblearn to balance the Real and Fake class distribution.


🏷️ Cell3: Label Mapping + Split Dataset

Mapped class labels to integers using ClassLabel and split the dataset using stratification into 60% training and 40% testing.


🧠 Cell4: Load Swin Transformer + Transforms

  • Loaded Swin Transformer from Hugging Face Transformers.
  • Defined different transforms for training and evaluation using torchvision.transforms.

πŸ“Š Cell5: Collator + Metrics + CSV/Plot Export

  • Used a custom collator to batch image tensors and labels.
  • Saved evaluation metrics (accuracy, precision, recall, f1) and confusion matrix as .csv and .png.

βš™οΈ Cell6: Training Arguments + Trainer Setup

  • Trained using Hugging Face Trainer.
  • Setup to run for 2 epochs with the best model saved based on the highest F1 score.

πŸš€ Cell7: Train and Evaluate

Executed training and evaluation using the following:

trainer.train()
trainer.evaluate()

πŸ“ˆ Cell8: Loss & Accuracy Plots

Post-training visualizations generated: Confusion Matrix

Loss vs Epochs

Accuracy vs Epochs

Loss vs Steps

Accuracy vs Steps


πŸ“‚ Files and Artifacts

  • classification_report.csv
  • confusion_matrix.csv
  • confusion_matrix_plot.png
  • loss_vs_steps.png
  • accuracy_vs_steps.png
  • loss_vs_epoch.png
  • accuracy_vs_epoch.png
  • loss_vs_walltime.png
  • accuracy_vs_walltime.png

🧩 Model Details

  • Backbone: microsoft/swin-base-patch4-window7-224
  • Task: Binary Image Classification (Real vs Fake)
  • Augmentation: Rotation, Sharpness
  • Metrics: Accuracy, Precision, Recall, F1

πŸ“œ License

MIT License