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


(360, 480, 3)

In [32]:
for i in range(3):
    img[:, :, i] -= mean_pix[i]/255.

print img.shape


(360, 480, 3)

In [33]:
preds = net.predict([img], oversample=False)

plt.plot(preds.flatten())

print np.argmax(preds.flatten())


278

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]:
<matplotlib.image.AxesImage at 0xa2895d0>

In [34]:
net.blobs.keys()


Out[34]:
['data',
 'conv1_1',
 'conv1_2',
 'pool1',
 'conv2_1',
 'conv2_2',
 'pool2',
 'conv3_1',
 'conv3_2',
 'conv3_3',
 'pool3',
 'conv4_1',
 'conv4_2',
 'conv4_3',
 'pool4',
 'conv5_1',
 'conv5_2',
 'conv5_3',
 'pool5',
 'fc6',
 'fc7',
 'fc8',
 'prob']

In [35]:
net.blobs['conv3_2'].data.shape


Out[35]:
(10, 256, 56, 56)

In [ ]:
res = net_conv.predict([img], oversample=False)

In [29]:
net_conv.blobs['conv3_2'].data.shape


Out[29]:
(10, 256, 56, 56)

In [ ]: