Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|