Upload 4 files
Browse files- 16871.jpg +0 -0
- app.py +53 -0
- featurevector.pkl +3 -0
- filename.pkl +3 -0
16871.jpg
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pickle as pkl
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input
|
| 5 |
+
from tensorflow.keras.preprocessing import image
|
| 6 |
+
from tensorflow.keras.layers import GlobalMaxPool2D
|
| 7 |
+
|
| 8 |
+
from sklearn.neighbors import NearestNeighbors
|
| 9 |
+
import os
|
| 10 |
+
from numpy.linalg import norm
|
| 11 |
+
import streamlit as st
|
| 12 |
+
|
| 13 |
+
st.header('Fashion Recommendation System')
|
| 14 |
+
|
| 15 |
+
Image_features = pkl.load(open('featurevector.pkl','rb'))
|
| 16 |
+
filenames = pkl.load(open('filename.pkl','rb'))
|
| 17 |
+
|
| 18 |
+
def extract_features_from_images(image_path, model):
|
| 19 |
+
img = image.load_img(image_path, target_size=(224,224))
|
| 20 |
+
img_array = image.img_to_array(img)
|
| 21 |
+
img_expand_dim = np.expand_dims(img_array, axis=0)
|
| 22 |
+
img_preprocess = preprocess_input(img_expand_dim)
|
| 23 |
+
result = model.predict(img_preprocess).flatten()
|
| 24 |
+
norm_result = result/norm(result)
|
| 25 |
+
return norm_result
|
| 26 |
+
model = ResNet50(weights='imagenet', include_top=False, input_shape=(224,224,3))
|
| 27 |
+
model.trainable = False
|
| 28 |
+
|
| 29 |
+
model = tf.keras.models.Sequential([model,
|
| 30 |
+
GlobalMaxPool2D()
|
| 31 |
+
])
|
| 32 |
+
neighbors = NearestNeighbors(n_neighbors=6, algorithm='brute', metric='euclidean')
|
| 33 |
+
neighbors.fit(Image_features)
|
| 34 |
+
upload_file = st.file_uploader("Upload Image")
|
| 35 |
+
if upload_file is not None:
|
| 36 |
+
with open(os.path.join('upload', upload_file.name), 'wb') as f:
|
| 37 |
+
f.write(upload_file.getbuffer())
|
| 38 |
+
st.subheader('Uploaded Image')
|
| 39 |
+
st.image(upload_file)
|
| 40 |
+
input_img_features = extract_features_from_images(upload_file, model)
|
| 41 |
+
distance,indices = neighbors.kneighbors([input_img_features])
|
| 42 |
+
st.subheader('Recommended Images')
|
| 43 |
+
col1,col2,col3,col4,col5 = st.columns(5)
|
| 44 |
+
with col1:
|
| 45 |
+
st.image(filenames[indices[0][1]])
|
| 46 |
+
with col2:
|
| 47 |
+
st.image(filenames[indices[0][2]])
|
| 48 |
+
with col3:
|
| 49 |
+
st.image(filenames[indices[0][3]])
|
| 50 |
+
with col4:
|
| 51 |
+
st.image(filenames[indices[0][4]])
|
| 52 |
+
with col5:
|
| 53 |
+
st.image(filenames[indices[0][5]])
|
featurevector.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8d5239fd5cca883d40bc82819004399c31b9b0b2e4e1714c66c61e168f0d8450
|
| 3 |
+
size 78
|
filename.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12d6e1c567a7ec1b42da9bb876224e39dc678636f5cac04866f4d8fdf797e3a1
|
| 3 |
+
size 73
|