Spaces:
Runtime error
Runtime error
Duplicate from Ron0420/EfficientNetV2_Deepfakes_Image_Detector
Browse filesCo-authored-by: Ron Lee <Ron0420@users.noreply.huggingface.co>
- .gitattributes +27 -0
- FINAL-EFFICIENTNETV2-B0.zip +3 -0
- FINAL-EFFICIENTNETV2-S.zip +3 -0
- Fake-1.png +0 -0
- Fake-2.png +0 -0
- Fake-3.png +0 -0
- Fake-4.png +0 -0
- Fake-5.png +0 -0
- README.md +38 -0
- Real-1.png +0 -0
- Real-2.png +0 -0
- Real-3.png +0 -0
- Real-4.png +0 -0
- Real-5.png +0 -0
- app.py +92 -0
- deepfakes-test-images.zip +3 -0
- packages.txt +3 -0
- references.txt +22 -0
- requirements.txt +7 -0
.gitattributes
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
FINAL-EFFICIENTNETV2-B0.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2006d2344a1804c269dd6c686181ee0e28213db5c52b73abfbfacf99e0d604e2
|
| 3 |
+
size 22914217
|
FINAL-EFFICIENTNETV2-S.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:44455a5ba75a17be9b6079b0691dc6553e120192556fc6acfc20786bc3d3720e
|
| 3 |
+
size 77090136
|
Fake-1.png
ADDED
|
Fake-2.png
ADDED
|
Fake-3.png
ADDED
|
Fake-4.png
ADDED
|
Fake-5.png
ADDED
|
README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: EfficientNetV2_Deepfakes_Image_Detector
|
| 3 |
+
emoji: 🌖
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
duplicated_from: Ron0420/EfficientNetV2_Deepfakes_Image_Detector
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Configuration
|
| 13 |
+
|
| 14 |
+
`title`: _string_
|
| 15 |
+
Display title for the Space
|
| 16 |
+
|
| 17 |
+
`emoji`: _string_
|
| 18 |
+
Space emoji (emoji-only character allowed)
|
| 19 |
+
|
| 20 |
+
`colorFrom`: _string_
|
| 21 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 22 |
+
|
| 23 |
+
`colorTo`: _string_
|
| 24 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 25 |
+
|
| 26 |
+
`sdk`: _string_
|
| 27 |
+
Can be either `gradio`, `streamlit`, or `static`
|
| 28 |
+
|
| 29 |
+
`sdk_version` : _string_
|
| 30 |
+
Only applicable for `streamlit` SDK.
|
| 31 |
+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
| 32 |
+
|
| 33 |
+
`app_file`: _string_
|
| 34 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code, or `static` html code).
|
| 35 |
+
Path is relative to the root of the repository.
|
| 36 |
+
|
| 37 |
+
`pinned`: _boolean_
|
| 38 |
+
Whether the Space stays on top of your list.
|
Real-1.png
ADDED
|
Real-2.png
ADDED
|
Real-3.png
ADDED
|
Real-4.png
ADDED
|
Real-5.png
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
import cv2
|
| 4 |
+
from mtcnn.mtcnn import MTCNN
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import tensorflow_addons
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import zipfile
|
| 11 |
+
|
| 12 |
+
local_zip = "FINAL-EFFICIENTNETV2-B0.zip"
|
| 13 |
+
zip_ref = zipfile.ZipFile(local_zip, 'r')
|
| 14 |
+
zip_ref.extractall('FINAL-EFFICIENTNETV2-B0')
|
| 15 |
+
zip_ref.close()
|
| 16 |
+
|
| 17 |
+
model = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-B0")
|
| 18 |
+
|
| 19 |
+
detector = MTCNN()
|
| 20 |
+
|
| 21 |
+
def deepfakespredict(input_img ):
|
| 22 |
+
|
| 23 |
+
labels = ['real', 'fake']
|
| 24 |
+
pred = [0, 0]
|
| 25 |
+
text =""
|
| 26 |
+
text2 =""
|
| 27 |
+
|
| 28 |
+
face = detector.detect_faces(input_img)
|
| 29 |
+
|
| 30 |
+
if len(face) > 0:
|
| 31 |
+
x, y, width, height = face[0]['box']
|
| 32 |
+
x2, y2 = x + width, y + height
|
| 33 |
+
|
| 34 |
+
cv2.rectangle(input_img, (x, y), (x2, y2), (0, 255, 0), 2)
|
| 35 |
+
|
| 36 |
+
face_image = input_img[y:y2, x:x2]
|
| 37 |
+
face_image2 = cv2.cvtColor(face_image, cv2.COLOR_BGR2RGB)
|
| 38 |
+
face_image3 = cv2.resize(face_image2, (224, 224))
|
| 39 |
+
face_image4 = face_image3/255
|
| 40 |
+
|
| 41 |
+
pred = model.predict(np.expand_dims(face_image4, axis=0))[0]
|
| 42 |
+
|
| 43 |
+
if pred[1] >= 0.6:
|
| 44 |
+
text = "The image is FAKE."
|
| 45 |
+
elif pred[0] >= 0.6:
|
| 46 |
+
text = "The image is REAL."
|
| 47 |
+
else:
|
| 48 |
+
text = "The image may be REAL or FAKE."
|
| 49 |
+
|
| 50 |
+
else:
|
| 51 |
+
text = "Face is not detected in the image."
|
| 52 |
+
|
| 53 |
+
text2 = "REAL: " + str(np.round(pred[0]*100, 2)) + "%, FAKE: " + str(np.round(pred[1]*100, 2)) + "%"
|
| 54 |
+
|
| 55 |
+
return input_img, text, text2, {labels[i]: float(pred[i]) for i in range(2)}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
title="EfficientNetV2 Deepfakes Image Detector"
|
| 59 |
+
description="This is a demo implementation of EfficientNetV2 Deepfakes Image Detector. \
|
| 60 |
+
To use it, simply upload your image, or click one of the examples to load them. \
|
| 61 |
+
This demo and model represent the Final Year Project titled \"Achieving Face Swapped Deepfakes Detection Using EfficientNetV2\" by a CS undergraduate Lee Sheng Yeh. \
|
| 62 |
+
The examples were extracted from Celeb-DF(V2)(Li et al, 2020) and FaceForensics++(Rossler et al., 2019). Full reference detail is available in \"references.txt.\" \
|
| 63 |
+
The examples are used under fair use to demo the working of the model only. If any copyright is infringed, please contact the researcher via this email: tp054565@mail.apu.edu.my.\
|
| 64 |
+
"
|
| 65 |
+
|
| 66 |
+
examples = [
|
| 67 |
+
['Fake-1.png'],
|
| 68 |
+
['Fake-2.png'],
|
| 69 |
+
['Fake-3.png'],
|
| 70 |
+
['Fake-4.png'],
|
| 71 |
+
['Fake-5.png'],
|
| 72 |
+
|
| 73 |
+
['Real-1.png'],
|
| 74 |
+
['Real-2.png'],
|
| 75 |
+
['Real-3.png'],
|
| 76 |
+
['Real-4.png'],
|
| 77 |
+
['Real-5.png']
|
| 78 |
+
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
gr.Interface(deepfakespredict,
|
| 83 |
+
inputs = ["image"],
|
| 84 |
+
outputs=[gr.outputs.Image(type="pil", label="Detected face"),
|
| 85 |
+
"text",
|
| 86 |
+
"text",
|
| 87 |
+
gr.outputs.Label(num_top_classes=None, type="auto", label="Confidence")],
|
| 88 |
+
title=title,
|
| 89 |
+
description=description,
|
| 90 |
+
examples = examples,
|
| 91 |
+
examples_per_page = 5
|
| 92 |
+
).launch()
|
deepfakes-test-images.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6607487fcd81fd26924917811602e5413cfe08e30fe81be5773009412a4e8557
|
| 3 |
+
size 5417905
|
packages.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
| 2 |
+
libsm6
|
| 3 |
+
libxext6
|
references.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Dataset References
|
| 2 |
+
|
| 3 |
+
Celeb-DF (V2)
|
| 4 |
+
|
| 5 |
+
@inproceedings{Celeb_DF_cvpr20,
|
| 6 |
+
author = {Yuezun Li and Xin Yang and Pu Sun and Honggang Qi and Siwei Lyu},
|
| 7 |
+
title = {Celeb-DF: A Large-scale Challenging Dataset for DeepFake Forensics},
|
| 8 |
+
booktitle= {IEEE Conference on Computer Vision and Patten Recognition (CVPR)},
|
| 9 |
+
year = {2020}}
|
| 10 |
+
|
| 11 |
+
FaceForensics++ Dataset
|
| 12 |
+
|
| 13 |
+
@inproceedings{roessler2019faceforensicspp,
|
| 14 |
+
author = {Andreas R\"ossler and Davide Cozzolino and Luisa Verdoliva and Christian Riess and Justus Thies and Matthias Nie{\ss}ner},
|
| 15 |
+
title = {Face{F}orensics++: Learning to Detect Manipulated Facial Images},
|
| 16 |
+
booktitle= {International Conference on Computer Vision (ICCV)},
|
| 17 |
+
year = {2019} }
|
| 18 |
+
|
| 19 |
+
@MISC{DDD_GoogleJigSaw2019,
|
| 20 |
+
AUTHOR = {Dufour, Nicholas and Gully, Andrew and Karlsson, Per and Vorbyov, Alexey Victor and Leung, Thomas and Childs, Jeremiah and Bregler, Christoph},
|
| 21 |
+
DATE = {2019-09},
|
| 22 |
+
TITLE = {DeepFakes Detection Dataset by Google & JigSaw}}
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
tensorflow-addons
|
| 3 |
+
facenet_pytorch
|
| 4 |
+
numpy
|
| 5 |
+
opencv-python
|
| 6 |
+
opencv-python-headless
|
| 7 |
+
mtcnn
|