In [2]:
import caffe
import numpy as np

net = caffe.Net('conv.prototxt', caffe.TEST)

# caffe.set_mode_cpu()
# print(net.inputs)

# net.blobs has activations
# net.blobs['data']
# net.blobs['conv']

# print the info of the network

info = [(k, v.data.shape) for k, v in net.blobs.items()]
# caffe.set_mode_cpu()

# output of each layers include input
# for i in range(len(info)):
# print('blobs_name', info[i][0])
# print('blobs_datashape', info[i][1])


# get parameters of network

# net.params['conv'][0]
# net.params['conv'][1]
info_params = [(k, v[0].data.shape, v[1].data.shape)
               for k, v in net.params.items()]

# for i in range(len(info_params)):
# print('params_name', info_params[i][0])
# print('params_weigthsshape', info_params[i][1])
# print('params_biasshape', info_params[i][1])


# to see what the weights and bias like
# take params['conv'][0] and [1] for example


# print('params_name', ' conv')

# print('params_weigths', net.params['conv'][0].data)
# print('params_bias', net.params['conv'][1].data)

# maybe can get it by layer
# for _ in range(len(net._layer_names)):
# print(net._layer_names[_])

# the input layer and conv layer are both in it

# for _ in range(len(info_layers)):
# print(info_layers[_][0])
# print(info_layers[_][1])

# error out of range due to layers[0] is input layers that it has not parameters
# print(net.layers[0].blobs[0])

# weights and bias
# print((net.layers[1].blobs[0].data))
# print(net.layers[1].blobs[1].data)

# more details about layers

# print(dir(net.layers[1].blobs[0]))

# check ... usage =-=
array = np.array([1., 2.1, 3.2])
array[...] = np.random.normal(0, 1, array.shape)
# print(1 * array)

# net.blobs['conv'].reshape((net.blobs['conv'].data.shape[0],-1))

# print(net.blobs['conv'].data)

In [4]:
# output tuple
# OrderedDict([('input', []), ('conv', ['data'])])
# bottom_names and top_names are both 2-D like array
print(net.bottom_names)


OrderedDict([('input', []), ('conv', ['data'])])

In [5]:
print(net.top_names)


OrderedDict([('input', ['data']), ('conv', ['conv'])])

In [23]:
# weights is the same as input
net.blobs['conv'].shape[1]==net.layers[1].blobs[0].shape[0]


Out[23]:
True

In [32]:
dic = {'1':np.array([[1,2,3],[2,3,5]]),'2':np.array([2,4,6])}

a = np.array([[1,2,3],[4,2,2],[4,3,5]])
a.shape


Out[32]:
(3, 3)

In [37]:
1*np.array([[1.2,2.1],[2.1,3.1]])


Out[37]:
array([[ 1.2,  2.1],
       [ 2.1,  3.1]])

In [43]:
np.concatenate([[[1,2],[4,6]],[[1,2]]],axis=0)


Out[43]:
array([[1, 2],
       [4, 6],
       [1, 2]])

In [45]:
d = []
d.append(net.layers[1].blobs[0].data).shape


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-45-409e1cdb9c22> in <module>()
      1 d = []
----> 2 d.append(net.layers[1].blobs[0].data).shape

AttributeError: 'NoneType' object has no attribute 'shape'