Я пытаюсь реализовать Dilated CNN, используя caffe и Lasagne. Когда я пытаюсь скопировать предварительно обученные параметры кофе (из lenet_iter_10000.caffemodel) в lasagne, я сталкиваюсь с этими ошибками, которые я не могу понять:
TypeError Traceback (most recent call last)
<ipython-input-10-40a671045a7c> in <module>()
9 layer.b.set_value(layers_caffe[name].blobs[1].data)
10 else:
---> 11 layer.W.set_value(layers_caffe[name].blobs[0].data[:,:,::-1,::-1])
12 layer.b.set_value(layers_caffe[name].blobs[1].data)
13
/usr/local/lib/python3.4/dist-packages/theano/compile/sharedvalue.py in set_value(self, new_value, borrow)
146 self.container.value = new_value
147 else:
--> 148 self.container.value = copy.deepcopy(new_value)
149
150 def zero(self, borrow=False):
/usr/local/lib/python3.4/dist-packages/theano/gof/link.py in __set__(self, value)
477 **kwargs)
478 else:
--> 479 self.storage[0] = self.type.filter(value, **kwargs)
480
481 except Exception as e:
/usr/local/lib/python3.4/dist-packages/theano/tensor/type.py in filter(self, data, strict, allow_downcast)
193 if b and data.shape[i] != 1:
194 raise TypeError("Non-unit value on shape on a broadcastable"
--> 195 " dimension.", data.shape, self.broadcastable)
196 i += 1
197 if (self.filter_checks_isfinite and
TypeError: ('Non-unit value on shape on a broadcastable dimension.', (20, 1, 5, 5), (True, False, False, False), 'Container name "None"')
Я создал лазанью сеть следующим образом:
net = {}
net['input'] = InputLayer((None, 1, 28, 28))
net['conv1'] = ConvLayer(net['input'], num_filters=20, filter_size=5, nonlinearity=linear)
net['pool1'] = PoolLayer(net['conv1'], pool_size=2, stride=2, mode='max', ignore_border=False)
net['conv2'] = ConvLayer(net['pool1'], num_filters=50, filter_size=5, nonlinearity=linear)
net['pool2'] = PoolLayer(net['conv2'], pool_size=2, stride=2, mode='max', ignore_border=False)
net['ip1'] = DenseLayer(net['pool2'], num_units=500, nonlinearity = rectify)
net['ip2'] = DenseLayer(net['ip1'], num_units=10, nonlinearity = None)
net['prob'] = NonlinearityLayer(net['ip2'], softmax)
и, чтобы скопировать параметры из кофе в лазанью, я написал это:
import numpy as np
layers_caffe = dict(zip(list(net_caffe._layer_names), net_caffe.layers))
print(layers_caffe)
for name, layer in net.items():
try:
if name=='ip1'or name=='ip2':
layer.W.set_value(np.transpose(layers_caffe[name].blobs[0].data))
layer.b.set_value(layers_caffe[name].blobs[1].data)
else:
layer.W.set_value(layers_caffe[name].blobs[0].data[:,:,::-1,::-1])
layer.b.set_value(layers_caffe[name].blobs[1].data)
except AttributeError:
continue