ImanAmran commited on
Commit
5acf0e3
·
1 Parent(s): c8414f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -1,10 +1,19 @@
1
  import tensorflow as tf
 
2
  from tensorflow.keras.models import load_model
3
- import numpy as np
4
- from PIL import Image
5
 
6
- # Define the target shape as previously used
7
- target_shape = (160, 160)
 
 
8
 
9
- # Load the FaceNet model with custom weights
10
- facenet_model = load_model('facenet_keras.h5', compile=False)
 
 
 
 
 
 
 
 
 
1
  import tensorflow as tf
2
+ from tensorflow.keras.layers import Layer
3
  from tensorflow.keras.models import load_model
 
 
4
 
5
+ # Define the custom layer
6
+ class DistanceLayer(Layer):
7
+ def __init__(self, **kwargs):
8
+ super().__init__(**kwargs)
9
 
10
+ def call(self, anchor, positive, negative):
11
+ ap_distance = tf.reduce_sum(tf.square(anchor - positive), -1)
12
+ an_distance = tf.reduce_sum(tf.square(anchor - negative), -1)
13
+ return (ap_distance, an_distance)
14
+
15
+ # Load the model with the custom layer
16
+ siamese_network = load_model('siamese_network.h5', custom_objects={'DistanceLayer': DistanceLayer})
17
+
18
+ # Now, you can use siamese_network for predictions, evaluation, etc.
19
+ siamese_network.summary()