Skip to content

Commit 287a0bc

Browse files
committed
Fixed vgg
1 parent cc1b307 commit 287a0bc

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from tensorflow.keras.applications.vgg16 import VGG16
2-
import cv2
1+
from tensorflow.keras.preprocessing import image
2+
from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions
33
import numpy as np
44

5-
if __name__ == "__main__":
6-
model = VGG16()
7-
model.summary()
8-
im = cv2.resize(cv2.imread('elephant.jpg'),
9-
(224, 224)).astype(np.float32)
10-
im[:, :, 0] -= 103.939
11-
im[:, :, 1] -= 116.779
12-
im[:, :, 2] -= 123.68
13-
out = model.predict(im)
14-
print(np.argmax(out))
5+
img_path = 'elephant.jpg'
6+
model = VGG16()
7+
img = image.load_img(img_path, target_size=(224, 224))
8+
x = image.img_to_array(img)
9+
x = np.expand_dims(x, axis=0)
10+
x = preprocess_input(x)
11+
model.summary()
12+
preds = model.predict(x)
13+
14+
print('Predicted:', decode_predictions(preds, top=3)[0])

0 commit comments

Comments
 (0)