-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPredictMulticlass.py
More file actions
41 lines (35 loc) · 955 Bytes
/
PredictMulticlass.py
File metadata and controls
41 lines (35 loc) · 955 Bytes
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
#Usage: python predict-multiclass.py
#https://github.com/tatsuyah/CNN-Image-Classifier
import os
import sys
import numpy as np
from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
from keras.models import Sequential, load_model
img_width, img_height = 150, 150
model_path = './models/model.h5'
model_weights_path = './models/weights.h5'
model = load_model(model_path)
model.load_weights(model_weights_path)
def predict(file):
x = load_img(file, target_size=(img_width,img_height))
x = img_to_array(x)
x = np.expand_dims(x, axis=0)
array = model.predict(x)
result = array[0]
answer = np.argmax(result)
label = ""
if answer == 0:
label = "Label: Daisy"
elif answer == 1:
label = "Label: Rose"
elif answer == 2:
label = "Label: Sunflower"
file = open("Result.txt", "w")
file.write(label)
daisy_t = 0
daisy_f = 0
rose_t = 0
rose_f = 0
sunflower_t = 0
sunflower_f = 0
predict(sys.argv[1])