Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let keras do pre/post processing in test_inference.py #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions test_inference.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""Test ImageNet pretrained DenseNet"""

import cv2
import numpy as np
from keras.optimizers import SGD
import keras.backend as K

# We only test DenseNet-121 in this script for demo purpose
from densenet121 import DenseNet

im = cv2.resize(cv2.imread('resources/cat.jpg'), (224, 224)).astype(np.float32)
#im = cv2.resize(cv2.imread('shark.jpg'), (224, 224)).astype(np.float32)
from keras.preprocessing import image
from keras.applications.imagenet_utils import decode_predictions

im = image.load_img('resources/cat.jpg', target_size=(224, 224))
im = image.img_to_array(im)

# Subtract mean pixel and multiple by scaling constant
# Reference: https://github.com/shicai/DenseNet-Caffe
Expand Down Expand Up @@ -44,4 +46,5 @@
for line in list_:
classes.append(line.rstrip('\n'))

print 'Prediction: '+str(classes[np.argmax(out)])
print('Prediction: '+str(classes[np.argmax(out)]))
print('Predicted:', decode_predictions(out))