ImanAmran commited on
Commit
997d4ca
·
1 Parent(s): 13fd080

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -1,9 +1,19 @@
 
 
1
  from tensorflow.keras.models import load_model
2
 
3
- # Replace 'final_siamese_network.h5' with the path to your saved model
4
- loaded_siamese_network = load_model('siamese_network.h5')
 
 
5
 
6
- loaded_siamese_network.summary()
 
 
 
7
 
8
- print("Input shape:", loaded_siamese_network.input_shape)
9
- print("Output shape:", loaded_siamese_network.output_shape)
 
 
 
 
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()