eybro commited on
Commit
2fe3715
·
verified ·
1 Parent(s): c9fa560

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -5,11 +5,16 @@ import cv2
5
  from keras.models import load_model
6
  from keras.models import Model
7
  from datasets import load_dataset
 
8
 
9
  autoencoder = load_model("autoencoder_model.keras")
10
  encoded_images = np.load("X_encoded_compressed.npy")
11
  dataset = load_dataset('eybro/images')
12
 
 
 
 
 
13
  def find_nearest_neighbors(encoded_images, input_image, top_n=5):
14
  """
15
  Find the closest neighbors to the input image in the encoded image space.
 
5
  from keras.models import load_model
6
  from keras.models import Model
7
  from datasets import load_dataset
8
+ from sklearn.cluster import KMeans
9
 
10
  autoencoder = load_model("autoencoder_model.keras")
11
  encoded_images = np.load("X_encoded_compressed.npy")
12
  dataset = load_dataset('eybro/images')
13
 
14
+ num_clusters = 10 # Choose the number of clusters
15
+ kmeans = KMeans(n_clusters=num_clusters, random_state=42)
16
+ kmeans.fit(encoded_images)
17
+
18
  def find_nearest_neighbors(encoded_images, input_image, top_n=5):
19
  """
20
  Find the closest neighbors to the input image in the encoded image space.