Skip to content

Instantly share code, notes, and snippets.

@pavelgonchar
Last active May 31, 2018 16:05
Show Gist options
  • Save pavelgonchar/4ebdb19b575eb3b102ad0840563b14c3 to your computer and use it in GitHub Desktop.
Save pavelgonchar/4ebdb19b575eb3b102ad0840563b14c3 to your computer and use it in GitHub Desktop.
VGG16Places365 test
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])
@pavelgonchar
Copy link
Author

inside_airplane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment