truens66 commited on
Commit
4b2a093
·
verified ·
1 Parent(s): 89f376f

Update pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +32 -0
pipeline.py CHANGED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import tensorflow as tf
4
+
5
+ # Load model
6
+ model = tf.keras.models.load_model("efficientnet-b0/")
7
+
8
+ class DetectionPipeline:
9
+ def __init__(self, batch_size=1):
10
+ self.batch_size = batch_size
11
+
12
+ def __call__(self, filename):
13
+ print('Processing image...')
14
+ image = cv2.cvtColor(filename, cv2.COLOR_BGR2RGB)
15
+ image = cv2.resize(image, (224, 224))
16
+ return image
17
+
18
+ # Initialize image detection pipeline
19
+ detection_image_pipeline = DetectionPipeline()
20
+
21
+ def deepfakes_image_predict(input_image):
22
+ face = detection_image_pipeline(input_image)
23
+ face2 = face / 255.0
24
+ pred = model.predict(np.expand_dims(face2, axis=0))[0]
25
+ real, fake = pred[0], pred[1]
26
+
27
+ if real > 0.5:
28
+ text = f"The image is REAL. \n Deepfakes Confidence: {round(100 - (real * 100), 3)}%"
29
+ else:
30
+ text = f"The image is FAKE. \n Deepfakes Confidence: {round(fake * 100, 3)}%"
31
+
32
+ return text