In [1]:
import sys
sys.path.append('/home/ipl/installs/caffe-dev/python/')
In [2]:
import caffe
import numpy as np
from matplotlib import pylab as plt
%matplotlib inline
In [30]:
net = caffe.Classifier('/home/ipl/installs/caffe-dev/models/VGG_16/deploy.prototxt',
'/home/ipl/installs/caffe-dev/models/VGG_16/VGG_ILSVRC_16_layers.caffemodel',
gpu=True, channel_swap=(2, 1, 0), raw_scale=255)
net_conv = caffe.Classifier('/home/ipl/installs/caffe-dev/models/VGG_16/deploy_conv_nopool.prototxt',
'/home/ipl/installs/caffe-dev/models/VGG_16/VGG_ILSVRC_16_layers.caffemodel',
gpu=True, channel_swap=(2, 1, 0), raw_scale=255)
mean_pix = [103.939, 116.779, 123.68];
In [31]:
img = caffe.io.load_image('/home/ipl/installs/caffe-dev/examples/images/cat.jpg')
plt.imshow(img)
print img.shape
In [32]:
for i in range(3):
img[:, :, i] -= mean_pix[i]/255.
print img.shape
In [33]:
preds = net.predict([img], oversample=False)
plt.plot(preds.flatten())
print np.argmax(preds.flatten())
In [15]:
img = net.deprocess('data', net.blobs['data'].data[0])
for i in range(3):
img[:, :, i] += mean_pix[i]/255.
plt.imshow(img)
Out[15]:
In [34]:
net.blobs.keys()
Out[34]:
In [35]:
net.blobs['conv3_2'].data.shape
Out[35]:
In [ ]:
res = net_conv.predict([img], oversample=False)
In [29]:
net_conv.blobs['conv3_2'].data.shape
Out[29]:
In [ ]: