Spaces:
Runtime error
Runtime error
app.py
CHANGED
|
@@ -44,7 +44,7 @@ class Contrastive_Loss_2(tf.keras.losses.Loss):
|
|
| 44 |
tf.debugging.check_numerics(total_loss.numpy(), 'Total contains NaN values.')
|
| 45 |
return total_loss
|
| 46 |
|
| 47 |
-
model = tf.keras.models.load_model( filepath='contrastive_model.h5', custom_objects={'Contrastive_Loss_2': Contrastive_Loss_2})
|
| 48 |
|
| 49 |
with open("scene_labels.json") as labels_file:
|
| 50 |
labels = json.load(labels_file)
|
|
@@ -52,7 +52,8 @@ with open("scene_labels.json") as labels_file:
|
|
| 52 |
def classify_image(img):
|
| 53 |
img = tf.convert_to_tensor(img, dtype=tf.float32)
|
| 54 |
img = tf.expand_dims(img, axis=0)
|
| 55 |
-
probs = model.predict(img).flatten()
|
|
|
|
| 56 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 57 |
|
| 58 |
image = gr.inputs.Image(shape=(256, 256))
|
|
|
|
| 44 |
tf.debugging.check_numerics(total_loss.numpy(), 'Total contains NaN values.')
|
| 45 |
return total_loss
|
| 46 |
|
| 47 |
+
model = tf.keras.models.load_model( filepath='contrastive_model.h5', custom_objects={'Contrastive_Loss_2': Contrastive_Loss_2}, compile=False)
|
| 48 |
|
| 49 |
with open("scene_labels.json") as labels_file:
|
| 50 |
labels = json.load(labels_file)
|
|
|
|
| 52 |
def classify_image(img):
|
| 53 |
img = tf.convert_to_tensor(img, dtype=tf.float32)
|
| 54 |
img = tf.expand_dims(img, axis=0)
|
| 55 |
+
# probs = model.predict(img).flatten()
|
| 56 |
+
probs = (model(img)).flatten()
|
| 57 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 58 |
|
| 59 |
image = gr.inputs.Image(shape=(256, 256))
|