|
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()) |
|
|
|
|
|
image = cv2.imread("/content/pisang-busuk-sebagian_20171004_085005.jpg") |
|
output = imutils.resize(image, width=400) |
|
|
|
|
|
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) |