Views
No views yet
google/efficientnet-b1 and mobilint/RegNet_Y_800MF.tv2_in1k feature extractors, trained on the ThinothW/Deepfake-Identity-Isolated-Dataset-PreP dataset.google/efficientnet-b1, mobilint/RegNet_Y_800MF.tv2_in1kfake vs real)sklearn balanced class weights applied to account for class imbalance.onnx graph loads its weights from the .onnx.data file alongside it at runtime:deepfake_hybrid_final.onnx — the ONNX graphdeepfake_hybrid_final.onnx.data — the external weights filepip install onnxruntime huggingface_hub pillow numpy1import numpy as np
2import onnxruntime as ort
3from PIL import Image
4from huggingface_hub import hf_hub_download
5
6REPO_ID = "nihal4/Deep_Fake_Hybrid_Model"
7IMG_SIZE = 260
8IMAGENET_MEAN = np.array([0.485, 0.456, 0.406], dtype=np.float32)
9IMAGENET_STD = np.array([0.229, 0.224, 0.225], dtype=np.float32)
10LABEL_MAP = {0: "fake", 1: "real"}
11
12# Downloads both files into the same local cache folder — required, since the
13# .onnx graph references .onnx.data by relative path at load time.
14onnx_path = hf_hub_download(repo_id=REPO_ID, filename="deepfake_hybrid_final.onnx")
15hf_hub_download(repo_id=REPO_ID, filename="deepfake_hybrid_final.onnx.data")
16
17session = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])
18input_name = session.get_inputs()[0].name
19output_name = session.get_outputs()[0].name
20
21def preprocess_pil(img: Image.Image) -> np.ndarray:
22 img = img.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
23 arr = np.asarray(img, dtype=np.float32) / 255.0 # HWC, [0,1]
24 arr = (arr - IMAGENET_MEAN) / IMAGENET_STD # normalize, same stats as training
25 return arr.transpose(2, 0, 1) # HWC -> CHW
26
27def softmax(x: np.ndarray) -> np.ndarray:
28 e = np.exp(x - x.max(axis=1, keepdims=True))
29 return e / e.sum(axis=1, keepdims=True)
30
31def predict(image_path: str):
32 image = Image.open(image_path)
33 x = preprocess_pil(image)[np.newaxis, ...].astype(np.float32)
34 logits = session.run([output_name], {input_name: x})[0]
35 probs = softmax(logits)[0]
36 label = LABEL_MAP[int(probs.argmax())]
37 return label, probs
38
39label, probs = predict("path/to/face.jpg")
40print(f"Prediction: {label} (p_fake={probs[0]:.3f}, p_real={probs[1]:.3f})")1image_paths = ["face1.jpg", "face2.jpg", "face3.jpg"]
2
3batch = np.stack([preprocess_pil(Image.open(p)) for p in image_paths]).astype(np.float32)
4logits = session.run([output_name], {input_name: batch})[0]
5probs = softmax(logits)
6preds = probs.argmax(axis=1)
7
8for path, pred, p in zip(image_paths, preds, probs):
9 print(f"{path}: {LABEL_MAP[int(pred)]} (p_fake={p[0]:.3f}, p_real={p[1]:.3f})")For GPU inference, installonnxruntime-gpuinstead and passproviders=["CUDAExecutionProvider", "CPUExecutionProvider"]when creating the session.
ThinothW/Deepfake-Identity-Isolated-Dataset-PreP dataset.0 = fake, 1 = real[0.485, 0.456, 0.406], std [0.229, 0.224, 0.225])sklearn balanced class weights applied in the loss function to address train-set class imbalance
| Class | Precision | Recall | F1-score | Support |
|---|---|---|---|---|
| fake | 0.95 | 0.96 | 0.95 | 10,706 |
| real | 0.96 | 0.95 | 0.95 | 10,610 |
| accuracy | 0.9539 | 21,316 | ||
| macro avg | 0.95 | 0.95 | 0.95 | 21,316 |
| weighted avg | 0.95 | 0.95 | 0.95 | 21,316 |


@misc{deepfake-hybrid-detector,
title = {Detecting Deepfake Faces: An Image Classification Approach to Safeguarding Digital Identity},
author = {S. M. Nihal Ahmed},
year = {2026},
note = {Course project, AI Lab (SE334), Daffodil International University}
}