%matplotlib inline
import os
import numpy as np
import matplotlib.pyplot as plt
import caffe
import random
MODEL_FILE = '/home/ubuntu/caffe/examples/cifar10/cifar10_quick.prototxt'
PRETRAINED = '/home/ubuntu/caffe/examples/cifar10/cifar10_quick_iter_4000.caffemodel'
x = caffe.io.load_image('/home/ubuntu/caffe/examples/images/' + str(random.randint(1,18)) + '.png')
plt.imshow(x)
plt.axis('off')
plt.show()
caffe.set_mode_gpu()
net = caffe.Classifier(MODEL_FILE, PRETRAINED,
mean=np.load('/home/ubuntu/caffe/caffe/examples/cifar10/cifar10_mean.npy').mean(1).mean(1),
raw_scale=255,
image_dims=(32, 32))
prediction = net.predict([x])
classes = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
plt.plot(prediction[0])
plt.xticks(range(0,10), classes, rotation=45)
print classes[prediction[0].argmax()]