-
-
Save pavelgonchar/4ebdb19b575eb3b102ad0840563b14c3 to your computer and use it in GitHub Desktop.
VGG16Places365 test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import numpy as np | |
from PIL import Image | |
from cv2 import resize | |
from vgg16_places365 import VGG16Places365, preprocess_input | |
LABELS_URL = 'https://raw.githubusercontent.com/csailvision/places365/master/categories_places365.txt' | |
LABELS = np.array(urllib2.urlopen(LABELS_URL).read().splitlines()) | |
TEST_IMAGE_URL = 'https://s3-us-west-2.amazonaws.com/kaggleglm/inside_airplane.jpg' | |
image = Image.open(urllib2.urlopen(TEST_IMAGE_URL)) | |
image = np.array(image, dtype=np.uint8) | |
image = resize(image, (224, 224)) | |
image = preprocess_input(image.astype(np.float32)) | |
image = np.expand_dims(image, 0) | |
model = VGG16Places365() | |
output = model.predict(image) | |
output = np.squeeze(output) | |
top5 = output.argsort()[-5:][::-1] | |
print("Labels:", LABELS[top5]) | |
print("Probs:", output[top5]) |
Author
pavelgonchar
commented
May 31, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment