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)
In [3]:
arr = np.array([[1,2,3],[2,3,4]])
arr.swapaxes(0,1)
Out[3]:
In [4]:
arr2 = np.array([[2,6,7],[8,9,5]])
np.concatenate([arr,arr2],axis=1)
Out[4]:
In [5]:
# np.concatenate([[[1,2]],[[2,3]],[[3,3]]],axis=1)
print(arr2[:])
print(arr2[None])
print(arr2[:,None])
print(arr2[:,:,None])
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
In [45]:
weights.reshape((3,-1))
Out[45]:
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
In [74]:
s[s>=7] = 1. / np.sqrt(s[s>=7]+1.)
In [75]:
s
Out[75]:
In [79]:
s.std()
Out[79]: