Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,28 @@ from scipy.spatial.distance import cosine
|
|
| 5 |
import cv2
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# K-mean Clustering
|
| 11 |
from sklearn.cluster import KMeans
|
|
@@ -17,7 +38,9 @@ n_clusters = 5 # You can adjust this based on your data
|
|
| 17 |
kmeans = KMeans(n_clusters=n_clusters)
|
| 18 |
|
| 19 |
# Load the embedding model
|
| 20 |
-
embedding_model = tf.keras.models.load_model('base_128.h5')
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Database to store embeddings and user IDs
|
| 23 |
user_embeddings = []
|
|
|
|
| 5 |
import cv2
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
from tensorflow.keras.applications import resnet
|
| 9 |
+
from tensorflow.keras import layers, Model
|
| 10 |
+
|
| 11 |
+
def create_embedding_model():
|
| 12 |
+
base_cnn = resnet.ResNet50(weights="imagenet", input_shape=(200, 200, 3), include_top=False)
|
| 13 |
+
|
| 14 |
+
flatten = layers.Flatten()(base_cnn.output)
|
| 15 |
+
dense1 = layers.Dense(512, activation="relu")(flatten)
|
| 16 |
+
dense1 = layers.BatchNormalization()(dense1)
|
| 17 |
+
dense2 = layers.Dense(256, activation="relu")(dense1)
|
| 18 |
+
dense2 = layers.BatchNormalization()(dense2)
|
| 19 |
+
output = layers.Dense(256)(dense2)
|
| 20 |
+
|
| 21 |
+
embedding_model = Model(base_cnn.input, output, name="Embedding")
|
| 22 |
+
|
| 23 |
+
trainable = False
|
| 24 |
+
for layer in base_cnn.layers:
|
| 25 |
+
if layer.name == "conv5_block1_out":
|
| 26 |
+
trainable = True
|
| 27 |
+
layer.trainable = trainable
|
| 28 |
+
|
| 29 |
+
return embedding_model
|
| 30 |
|
| 31 |
# K-mean Clustering
|
| 32 |
from sklearn.cluster import KMeans
|
|
|
|
| 38 |
kmeans = KMeans(n_clusters=n_clusters)
|
| 39 |
|
| 40 |
# Load the embedding model
|
| 41 |
+
# embedding_model = tf.keras.models.load_model('base_128.h5')
|
| 42 |
+
embedding_model = create_embedding_model()
|
| 43 |
+
embedding_model.load_weights('base_128.h5')
|
| 44 |
|
| 45 |
# Database to store embeddings and user IDs
|
| 46 |
user_embeddings = []
|