Spaces:
Runtime error
Runtime error
added streamlit api
Browse files
app.py
CHANGED
|
@@ -6,9 +6,16 @@ Automatically generated by Colaboratory.
|
|
| 6 |
Original file is located at
|
| 7 |
https://colab.research.google.com/drive/1H-R9L74rpYOoQJOnTLLbUpcNpd9Tty_D
|
| 8 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
import tensorflow as tf
|
| 13 |
from sklearn.datasets import load_sample_image
|
| 14 |
import os
|
|
@@ -42,21 +49,26 @@ for dir in os.listdir(directory):
|
|
| 42 |
new_dir = '/content/lfw/'+dir
|
| 43 |
if os.path.isdir(new_dir):
|
| 44 |
for files in os.listdir(new_dir):
|
| 45 |
-
feature_dict[
|
| 46 |
if i >= 100:
|
| 47 |
break
|
| 48 |
|
| 49 |
-
for file, features in feature_dict.items():
|
| 50 |
-
|
| 51 |
|
| 52 |
feature_map = np.array(list(feature_dict.values()))
|
| 53 |
|
| 54 |
NearNeigh = NearestNeighbors(n_neighbors=10,algorithm='auto').fit(feature_map)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
Original file is located at
|
| 7 |
https://colab.research.google.com/drive/1H-R9L74rpYOoQJOnTLLbUpcNpd9Tty_D
|
| 8 |
"""
|
| 9 |
+
import streamlit as st
|
| 10 |
+
st.markdown("This is a image classification program, please enter the image that you would like to process.")
|
| 11 |
+
st.markdown("Please keep in mind that the dataset is very small (around 100-2000 imgs only")
|
| 12 |
+
path = ['Coretta_Scott_King','Saddam_Hussein','Augustin_Calleri','Peter_Hunt']
|
| 13 |
|
| 14 |
+
select_path = st.selectbox('Which of the three photos would you like to process', options = path)
|
| 15 |
+
st.write("You've select", select_path)
|
| 16 |
+
|
| 17 |
+
# !wget http://vis-www.cs.umass.edu/lfw/lfw.tgz
|
| 18 |
+
# !tar -xvf /content/lfw.tgz
|
| 19 |
import tensorflow as tf
|
| 20 |
from sklearn.datasets import load_sample_image
|
| 21 |
import os
|
|
|
|
| 49 |
new_dir = '/content/lfw/'+dir
|
| 50 |
if os.path.isdir(new_dir):
|
| 51 |
for files in os.listdir(new_dir):
|
| 52 |
+
feature_dict[dir] = preprocess_image(new_dir+'/'+files, target_size).flatten()
|
| 53 |
if i >= 100:
|
| 54 |
break
|
| 55 |
|
| 56 |
+
# for file, features in feature_dict.items():
|
| 57 |
+
# print(file, features)
|
| 58 |
|
| 59 |
feature_map = np.array(list(feature_dict.values()))
|
| 60 |
|
| 61 |
NearNeigh = NearestNeighbors(n_neighbors=10,algorithm='auto').fit(feature_map)
|
| 62 |
+
img = feature_dict[select_path].reshape(1,-1)
|
| 63 |
+
distance,indices = NearNeigh.kneighbors(img)
|
| 64 |
+
st.write('Similar images for', select_path)
|
| 65 |
+
for i,index in enumerate(indices[0]):
|
| 66 |
+
similar_img_path = list(feature.keys())[index]
|
| 67 |
+
print(i+1,similar_img_path)
|
| 68 |
+
# for image_path in feature_dict:
|
| 69 |
+
# img = feature_dict[image_path].reshape(1,-1)
|
| 70 |
+
# distance,indices = NearNeigh.kneighbors(img)
|
| 71 |
+
# print('Similar images for', image_path)
|
| 72 |
+
# for i, index in enumerate(indices[0]):
|
| 73 |
+
# similar_img_path = list(feature_dict.keys())[index]
|
| 74 |
+
# print(i+1,similar_img_path)
|