asaderu commited on
Commit
37927bd
1 Parent(s): c1a884c

Create test.py

Browse files
Files changed (1) hide show
  1. test.py +40 -0
test.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import imutils
2
+ import pickle
3
+ from tensorflow.keras.models import load_model
4
+ def buka(title, image):
5
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
6
+ plt.imshow(image)
7
+ plt.title(title)
8
+ plt.grid(False)
9
+ plt.axis("off")
10
+ plt.show()
11
+
12
+ print("loading model....")
13
+ model = load_model('/content/bananafreshness/pisang.model')
14
+ mlb = pickle.loads(open('/content/bananafreshness/pisang.pickle', "rb").read())
15
+
16
+ # load the image
17
+ image = cv2.imread("/content/pisang-busuk-sebagian_20171004_085005.jpg")
18
+ output = imutils.resize(image, width=400)
19
+
20
+ # pre-process the image for classification
21
+ image = cv2.resize(image, (94, 94))
22
+ image = image.astype("float") / 255.0
23
+ image = img_to_array(image)
24
+ image = np.expand_dims(image, axis=0)
25
+ proba = model.predict(image)[0]
26
+ idxs = np.argsort(proba)[::-1][:2]
27
+
28
+
29
+
30
+ for (i, j) in enumerate(idxs):
31
+ label = "{}: {:.2f}%".format(mlb.classes_[j], proba[j] * 100)
32
+ cv2.putText(output, label, (10, (i * 30) + 25),
33
+ cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
34
+
35
+
36
+ for (label, p) in zip(mlb.classes_, proba):
37
+ print("{}: {:.2f}%".format(label, p * 100))
38
+
39
+
40
+ buka("Output", output)