In [ ]:
batch_size = 1
In [ ]:
%matplotlib inline
import matplotlib.pylab as plt
In [ ]:
import vgg19_model
reload(vgg19_model)
VGG19 = vgg19_model.VGG19
import numpy as np
import theano
layer_weights = vgg19_model.layer_weights
bias_weights = vgg19_model.bias_weights
VGG19_conv2d_layer = vgg19_model.VGG19_conv2d_layer
batch_size = 1
input_image = np.ones(((batch_size,3, 224, 224)))
image = theano.tensor.tensor4('image')
In [ ]:
In [ ]:
import cv2
img = cv2.resize(cv2.imread('../bald_eagle.jpg'), (224, 224)).astype(np.float32)
# im[:,:,0] -= 103.939
# im[:,:,1] -= 116.779
# im[:,:,2] -= 123.68
mean_pixel = [103.939, 116.779, 123.68]
img = img.astype(np.float32, copy=False)
for c in range(3):
img[:, :, c] = img[:, :, c] - mean_pixel[c]
img = img.transpose((2,0,1))
img = np.expand_dims(img, axis=0)
im = img
In [ ]:
im.shape
In [ ]:
im2 = im.reshape(1,224,224,3)
print im2.shape
new_input_image = np.transpose(im2,(0,3,1,2))
In [ ]:
vgg19 = VGG19(input_image_shape=(1,224,224,3))
try_out = theano.function(inputs=[vgg19.input],outputs=vgg19.dense_12.output)
In [ ]:
softmax_output = try_out(im)
In [ ]:
print softmax_output.shape
print softmax_output.sum()
In [ ]:
softmax_output[0].sum()
In [ ]:
print np.argmax(softmax_output[0])
print labels[22]
In [ ]:
import pickle
import pandas as pd
file = open('../labels/imagenet.bet.pickle','rb')
labels = pickle.load(file)
df_labels = pd.DataFrame(zip(labels[labels.keys()[1]],labels[labels.keys()[3]]))
df_labels.columns = ['Text Label','Numeric Label']
In [ ]:
labels.keys()
In [ ]:
# def print_top_5(out):
top_five = np.argsort(softmax_output[0])
labels_file = '../labels/synset_words.txt'
labels = np.loadtxt(labels_file, str, delimiter='\t')
for i,label in enumerate(labels[top_five]):
print str(i), ' output label: ', label.strip().split(' ')[1]
In [ ]:
In [ ]:
labels
In [ ]:
softmax_output[0]
In [ ]:
labels[top_five]
In [ ]:
labels
In [ ]:
for i in vgg19.__dict__.keys():
print i,vgg19.__dict__[i].get_values()
In [ ]:
vgg19.convolution2d_50_pool.o
In [ ]: