forked from Piyush-Sharma788/PixelTruth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
33 lines (29 loc) · 1.1 KB
/
Copy pathpredict.py
File metadata and controls
33 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
import cv2
import os
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import img_to_array
model = load_model('deepfake_detection_model.h5')
def preprocess_image(image_path):
image = cv2.imread(image_path)
if image is None:
raise FileNotFoundError(f"Image nahi mili: {image_path}")
image = cv2.resize(image, (96, 96))
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
image = image / 255.0
return image
def predict_image(image_path):
image = preprocess_image(image_path)
prediction = model.predict(image, verbose=0)
print(f"Raw prediction: {prediction}")
class_label = np.argmax(prediction, axis=1)[0]
confidence = float(np.max(prediction)) * 100
# Class 1 = Fake, Class 0 = Real (dataset mapping)
label = "Fake" if class_label == 1 else "Real"
print(f"Prediction : {label}")
print(f"Confidence : {confidence:.1f}%")
return label
# Fake image test
image_path = "real_and_fake_face_detection/real_vs_fake/real-vs-fake/train/fake/001DDU0NI4.jpg"
predict_image(image_path)