Zell commited on
Commit
853a9c8
·
1 Parent(s): c3a06b9

Fix loading of model

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. app.py +15 -1
  3. requirements.txt +1 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py CHANGED
@@ -1,9 +1,23 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
 
 
4
 
5
  # 1. Load your model
6
- model = tf.keras.models.load_model("facenet_real_fake_classifier_final.keras")
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # 2. Define your inference function
9
  def detect_forgery(image):
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
4
+ from tensorflow.keras.models import load_model
5
+ import keras
6
 
7
  # 1. Load your model
8
+ @keras.saving.register_keras_serializable()
9
+ def scaling(x, scale=255.0, **kwargs):
10
+ return x * scale
11
+
12
+ @keras.saving.register_keras_serializable()
13
+ def l2_normalize(x, axis=-1, epsilon=1e-10):
14
+ return tf.nn.l2_normalize(x, axis=axis, epsilon=epsilon)
15
+
16
+ # Pass the registered functions explicitly
17
+ custom_objects = {"scaling": scaling, "l2_normalize": l2_normalize}
18
+
19
+ # Load the model with custom_objects
20
+ model = load_model("facenet_real_fake_classifier_final.keras", custom_objects=custom_objects)
21
 
22
  # 2. Define your inference function
23
  def detect_forgery(image):
requirements.txt CHANGED
@@ -2,3 +2,4 @@
2
  gradio==3.25.0
3
  numpy<2.0
4
  tensorflow-cpu==2.11.*
 
 
2
  gradio==3.25.0
3
  numpy<2.0
4
  tensorflow-cpu==2.11.*
5
+ keras==3.0.0