-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_imagenet.py
34 lines (27 loc) · 991 Bytes
/
test_imagenet.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
from keras.preprocessing import image as image_utils
from imagenet_utils import decode_predictions
from imagenet_utils import preprocess_input
from vgg16 import VGG16
import numpy as np
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path gambar")
args = vars(ap.parse_args())
orig = cv2.imread(args["image"])
print("[INFO] loading and Prosese image...")
image = image_utils.load_img(args["image"], target_size=(224, 224))
image = image_utils.img_to_array(image)
image = np.expand_dims(image, axis=0)
image = preprocess_input(image)
print("[INFO] loading network...")
model = VGG16(weights="imagenet")
print("[INFO] klasifikasi image...")
preds = model.predict(image)
(inID, label) = decode_predictions(preds)[0]
print("ImageNet ID: {}, Label: {}".format(inID, label))
cv2.putText(orig, "Label: {}".format(label), (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imshow("Klasifikasi", orig)
cv2.waitKey(0)