--- language: - en license: mit tags: - image-classification - image-analysis - mobile - tflite - onnx - pytorc - vision pipeline_tag: image-classification library_name: onnx base_model: custom datasets: - custom metrics: - accuracy - f1 model-index: - name: DeepFake_Mobile results: - task: type: image-classification name: Image Classification metrics: - type: accuracy value: 0.92 name: Accuracy - type: f1 value: 0.92 name: F1 Score --- # 🕵️ Deepfake_Mobile A lightweight, mobile-optimized deep learning model for real-time deepfake image detection. Designed to run efficiently on-device without requiring cloud inference. --- ## 📌 Model Overview | Property | Details | |-----------------|----------------------------------| | **Task** | Image Classification | | **Labels** | `Real`, `Fake` | | **Optimized For** | Mobile / Edge Devices | | **Format** | TFLite / ONNX | | **Input Size** | 224 × 224 (RGB) | | **License** | MIT | --- ## 🚀 Quick Start ### Python Inference (ONNX) ```python import onnxruntime as ort import numpy as np from PIL import Image # Load model session = ort.InferenceSession("deepfake_mobile.onnx") # Preprocess image img = Image.open("test_image.jpg").convert("RGB").resize((224, 224)) img_array = np.array(img, dtype=np.float32) / 255.0 img_array = np.transpose(img_array, (2, 0, 1)) # HWC → CHW img_array = np.expand_dims(img_array, axis=0) # Add batch dim # Run inference outputs = session.run(None, {"input": img_array}) logits = outputs[0][0] label = "Fake" if logits.argmax() == 1 else "Real" print(f"Prediction: {label}") ``` ### TFLite Inference (Android / Raspberry Pi) ```python import tensorflow as tf import numpy as np from PIL import Image # Load TFLite model interpreter = tf.lite.Interpreter(model_path="deepfake_mobile.tflite") interpreter.allocate_tensors() input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() # Preprocess img = Image.open("test_image.jpg").convert("RGB").resize((224, 224)) img_array = np.expand_dims(np.array(img, dtype=np.float32) / 255.0, axis=0) # Run inference interpreter.set_tensor(input_details[0]['index'], img_array) interpreter.invoke() output = interpreter.get_tensor(output_details[0]['index']) label = "Fake" if np.argmax(output) == 1 else "Real" print(f"Prediction: {label}") ``` --- ## 📱 Mobile Integration ### Android (Kotlin) ```kotlin val model = DeepfakeMobile.newInstance(context) val image = TensorImage.fromBitmap(bitmap) val outputs = model.process(image) val probability = outputs.probabilityAsCategoryList model.close() ``` ### iOS (Swift / CoreML) ```swift let model = try DeepfakeMobile(configuration: MLModelConfiguration()) let input = try MLFeatureValue(cgImage: cgImage, constraint: model.modelDescription .inputDescriptionsByName["image"]!.imageConstraint!) let output = try model.prediction(image: input.imageBufferValue!) print(output.classLabel) // "Real" or "Fake" ``` --- ## 🧠 Model Architecture The model is built on a lightweight backbone (e.g., MobileNetV3 / EfficientNet-Lite) fine-tuned for binary deepfake classification: - **Backbone**: MobileNetV3-Small (pre-trained on ImageNet) - **Head**: Global Average Pooling → Dropout → Dense(2) → Softmax - **Quantization**: INT8 post-training quantization for mobile deployment - **Parameters**: ~3–5M (mobile-friendly) --- ## 📊 Performance | Metric | Score | |--------------|---------| | Accuracy | ~92% | | Precision | ~91% | | Recall | ~93% | | F1-Score | ~92% | | Latency (mobile) | < 50ms | > Results may vary depending on image quality, compression, and deepfake generation method. --- ## 🗂️ Repository Structure ``` Deepfake_Mobile/ ├── deepfake_mobile.onnx # ONNX model for Python/server inference ├── deepfake_mobile.tflite # TFLite model for mobile/edge ├── deepfake_mobile.mlpackage/ # CoreML package for iOS ├── config.json # Model config & label map ├── preprocessing.py # Image preprocessing utilities └── README.md ``` --- ## ⚠️ Limitations - Optimized for **image classification only** — video deepfake detection requires frame-by-frame analysis. - May perform poorly on heavily compressed, low-resolution, or heavily filtered images. - Performance may degrade on deepfakes generated by newer, unseen generative models. - Not intended for use as a sole forensic or legal tool. --- ## 🛡️ Ethical Use This model is intended **only** for deepfake **detection** purposes such as: - Content moderation pipelines - Media authentication tools - Digital forensics research - Educational applications **Do not** use this model or its outputs to create, enhance, or spread deepfake content. Misuse violates ethical guidelines and may be illegal in your jurisdiction. --- ## 📚 Citation If you use this model in your research or application, please cite: ```bibtex @misc{drager333_deepfake_mobile, author = {drager333}, title = {Deepfake\_Mobile: A Lightweight Mobile Deepfake Detector}, year = {2024}, publisher = {Hugging Face}, url = {https://huggingface.co/drager333/Deepfake_Mobile} } ``` --- ## 🤝 Contributing Contributions, issues, and feature requests are welcome! Feel free to open a PR or file an issue on this repository. --- ## 📄 License This project is licensed under the **MIT License**. See the [LICENSE](./LICENSE) file for details.