-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutfitPredictor.py
More file actions
84 lines (61 loc) · 1.99 KB
/
OutfitPredictor.py
File metadata and controls
84 lines (61 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#Script to predict image
import os
import numpy as np
import glob
from os.path import join as pJoin
import random
from keras.applications import vgg19
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import ImageDataGenerator
from keras.applications.imagenet_utils import decode_predictions
import matplotlib.pyplot as plt
import ssl
import h5py
#Create new model
from keras import models
from keras import layers
from keras import optimizers
from keras.models import load_model
def predictionCategoryLookup(pred):
pred = int(pred)
return categories[pred+1].rstrip()
def import_image(imgpath):
# load an image in PIL format
original = load_img(imgpath, target_size=(224, 224))
# convert the PIL image to a numpy array
# IN PIL - image is in (width, height, channel)
# In Numpy - image is in (height, width, channel)
numpy_image = img_to_array(original)
return numpy_image
def predictClasses(img_Path):
#IN DEV: Find probability of article of clothing
# for file in test_labels[0]:
img = import_image(img_Path)
img = np.expand_dims(img, axis=0)
pred = model.predict_proba(img)
probs = []
for i in pred[0]:
probs.append(i)
probs = np.array(probs)
bestChoice = np.argmax(probs)
probsIndices = probs.argsort()
top3indices=probsIndices[-8:]
img = import_image(img_Path)
plt.imshow(np.uint8(img))
plt.show()
#Print class number, article of clthing + category type, and the probability
for i in top3indices:
print probs[i], predictionCategoryLookup(i)
return bestChoice, predictionCategoryLookup(bestChoice), max(probs)
file = ('categories.txt')
f=open(file, "r")
categories=f.readlines()
# Create the model
model = models.Sequential()
vgg_model = vgg19.VGG19(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
# Add the vgg convolutional base model
model.add(vgg_model)
model = load_model('Clothing_Classifier_Model.h5')
response = predictClasses('images/elliot.jpg')
print response