File size: 1,105 Bytes
37927bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import imutils
import pickle
from tensorflow.keras.models import load_model
def buka(title, image):
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  plt.imshow(image)
  plt.title(title)
  plt.grid(False)
  plt.axis("off")
  plt.show()
  
print("loading model....")
model = load_model('/content/bananafreshness/pisang.model')
mlb = pickle.loads(open('/content/bananafreshness/pisang.pickle', "rb").read())

# load the image
image = cv2.imread("/content/pisang-busuk-sebagian_20171004_085005.jpg")
output = imutils.resize(image, width=400)
 
# pre-process the image for classification
image = cv2.resize(image, (94, 94))
image = image.astype("float") / 255.0
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
proba = model.predict(image)[0]
idxs = np.argsort(proba)[::-1][:2]



for (i, j) in enumerate(idxs):
	label = "{}: {:.2f}%".format(mlb.classes_[j], proba[j] * 100)
	cv2.putText(output, label, (10, (i * 30) + 25), 
		cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
 

for (label, p) in zip(mlb.classes_, proba):
	print("{}: {:.2f}%".format(label, p * 100))
 

buka("Output", output)