In [1]:
import caffe
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
net = caffe.Net('deploy.prototxt',caffe.TEST)

In [25]:
# net.layers[0].blobs>0

for i ,(name,layer) in enumerate(zip(net._layer_names,net.layers)):
    
#     display all layers
    print(name)
    for bottom_name in net.bottom_names[name]:
        
        print('layer_%s bottom name: '%name,bottom_name)
    if(len(net.bottom_names[name])>1):
        print('True')
#     parameters layers
#     if(len(layer.blobs)>0):
#         print(name)


data
conv1
('layer_conv1 bottom name: ', 'data')
relu1
('layer_relu1 bottom name: ', 'conv1')
norm1
('layer_norm1 bottom name: ', 'conv1')
pool1
('layer_pool1 bottom name: ', 'norm1')
conv2
('layer_conv2 bottom name: ', 'pool1')
relu2
('layer_relu2 bottom name: ', 'conv2')
norm2
('layer_norm2 bottom name: ', 'conv2')
pool2
('layer_pool2 bottom name: ', 'norm2')
conv3
('layer_conv3 bottom name: ', 'pool2')
relu3
('layer_relu3 bottom name: ', 'conv3')
conv4
('layer_conv4 bottom name: ', 'conv3')
relu4
('layer_relu4 bottom name: ', 'conv4')
conv5
('layer_conv5 bottom name: ', 'conv4')
relu5
('layer_relu5 bottom name: ', 'conv5')
pool5
('layer_pool5 bottom name: ', 'conv5')
fc6
('layer_fc6 bottom name: ', 'pool5')
relu6
('layer_relu6 bottom name: ', 'fc6')
drop6
('layer_drop6 bottom name: ', 'fc6')
fc7
('layer_fc7 bottom name: ', 'fc6')
relu7
('layer_relu7 bottom name: ', 'fc7')
drop7
('layer_drop7 bottom name: ', 'fc7')
fc8
('layer_fc8 bottom name: ', 'fc7')
prob
('layer_prob bottom name: ', 'fc8')

In [3]:
arr = np.array([[1,2,3],[2,3,4]])
arr.swapaxes(0,1)


Out[3]:
array([[1, 2],
       [2, 3],
       [3, 4]])

In [4]:
arr2 = np.array([[2,6,7],[8,9,5]])
np.concatenate([arr,arr2],axis=1)


Out[4]:
array([[1, 2, 3, 2, 6, 7],
       [2, 3, 4, 8, 9, 5]])

In [5]:
# np.concatenate([[[1,2]],[[2,3]],[[3,3]]],axis=1)
print(arr2[:])
print(arr2[None])
print(arr2[:,None])
print(arr2[:,:,None])


[[2 6 7]
 [8 9 5]]
[[[2 6 7]
  [8 9 5]]]
[[[2 6 7]]

 [[8 9 5]]]
[[[2]
  [6]
  [7]]

 [[8]
  [9]
  [5]]]

In [32]:
def transform(data,weights):
    D,W=[],[]
    OS=2
    for i in range(OS):
        D.append(data)
        W.append(weights)
    
    W, D = np.concatenate([w[:,None] for w in W], axis=1), np.concatenate([d[:,:,None] for d in D], axis=2)
    return W.reshape((-1,)+W.shape[2:]), D.reshape((D.shape[0], -1)+D.shape[3:])

In [41]:
#generate mock data by random
data = np.arange(1*2).reshape((1,2))
# np.random.shuffle(data)
weights = np.arange(1*5*2*6).reshape((1,5,2,6))
# np.random.shuffle(weights)

In [42]:
W,D = transform(data,weights)

In [43]:
print W.shape
print D.shape


(2, 5, 2, 6)
(1, 4)

In [45]:
weights.reshape((3,-1))


Out[45]:
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19],
       [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
        37, 38, 39],
       [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
        57, 58, 59]])

In [72]:
s = np.arange(10,dtype=np.float)
np.random.shuffle(s)
id = np.argsort(s)[-5:]
s = s[id]

In [73]:
print s
print id


[ 5.  6.  7.  8.  9.]
[1 9 7 0 8]

In [74]:
s[s>=7] = 1. / np.sqrt(s[s>=7]+1.)

In [75]:
s


Out[75]:
array([ 5.        ,  6.        ,  0.35355339,  0.33333333,  0.31622777])

In [79]:
s.std()


Out[79]:
2.5503395703071798