-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
46 lines (40 loc) · 1.14 KB
/
run.py
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
print("Importing Modules")
import sys
import tensorflow as tf
import cv2
import numpy as np
IMG_S1, IMG_S2 = (140,140)
CATEGORIES = ['Loose Silky-bent',
'Common Chickweed',
'Black-grass',
'Charlock',
'Small-flowered Cranesbill',
'Sugar beet',
'Maize',
'Fat Hen',
'Cleavers',
'Common wheat',
'Scentless Mayweed',
'Shepherds Purse']
print("Importing Model")
model = tf.keras.models.load_model("saved_model")
print("Creating test set")
X = []
index = []
for i in range(1,len(sys.argv)):
imgdir = sys.argv[i]
image = cv2.imread(imgdir, cv2.IMREAD_ANYCOLOR)
if image is None:
print("Image not found, dir:",imgdir)
else:
image = cv2.resize(image , (IMG_S1, IMG_S2))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
X.append(image)
index.append(i)
X = np.array(X)/255.
result = model.predict_classes(X)
print("-------------------------")
for i in range(len(index)):
print(index[i]," : ",CATEGORIES[result[i]])
print("------------------------------")
print("End")