我找不到太多在千层面中使用空间网络的例子,所以我可能在定义我的网络时犯了一个错误。请查看我的网络定义,如果问题出在我的网络配置或有其他问题,请告诉我。
``` 网络 = 神经网络(
layers=[('loc_input', InputLayer),
('loc_conv2d1', Conv2DLayer),
('loc_maxpool1', MaxPool2DLayer),
('loc_conv2d2', Conv2DLayer),
('loc_maxpool2', MaxPool2DLayer),
('loc_dense', DenseLayer),
('loc_output', DenseLayer),
('STN1', TransformerLayer),
('conv2d1', Conv2DLayer),
('maxpool1', MaxPool2DLayer),
('conv2d2', Conv2DLayer),
('maxpool2', MaxPool2DLayer),
('dense', DenseLayer),
('dropout1', DropoutLayer),
('dense', DenseLayer),
('output', DenseLayer),
],
loc_input_shape=(None, 1, X_train.shape[2],X_train.shape[3]),
# layer conv2d1
loc_conv2d1_num_filters=32,
loc_conv2d1_filter_size=(5, 5),
loc_conv2d1_stride=2,
loc_conv2d1_W=lasagne.init.HeUniform(),
# layer maxpool1
loc_maxpool1_pool_size=(2, 2),
# layer conv2d2
loc_conv2d2_num_filters=64,
loc_conv2d2_filter_size=(5, 5),
loc_conv2d2_stride=2,
loc_conv2d2_W=lasagne.init.HeUniform(),
# layer maxpool2
loc_maxpool2_pool_size=(2, 2),
loc_dense_num_units=64,
# dense
loc_output_num_units=6,
#Spatial Transformer Network
STN1_incoming = 'loc_input',
STN1_localization_network = 'loc_output',
STN1_downsample_factor = 1,
# layer conv2d1
conv2d1_incoming = 'STN1',
conv2d1_num_filters=32,
conv2d1_filter_size=(3, 3),
conv2d1_stride=2,
conv2d1_nonlinearity=lasagne.nonlinearities.rectify,
conv2d1_W=lasagne.init.GlorotUniform(),
# layer maxpool1
maxpool1_pool_size=(2, 2),
# layer conv2d2
conv2d2_num_filters=64,
conv2d2_filter_size=(3, 3),
conv2d2_stride=2,
conv2d2_nonlinearity=lasagne.nonlinearities.rectify,
# layer maxpool2
maxpool2_pool_size=(2, 2),
# dropout1
dropout1_p=0.5,
# dense
dense_num_units=256,
dense_nonlinearity=lasagne.nonlinearities.rectify,
# output
output_nonlinearity= softmax,
output_num_units=numClasses,
# optimization method params
update=nesterov_momentum,
update_learning_rate=0.01,
update_momentum=0.9,
max_epochs=20,
verbose=1,
)
```
当我启动网络时,我收到以下错误:
```
AttributeError Traceback (most recent call last)
<ipython-input-84-29eabf8b9697> in <module>()
----> 1 net.initialize()
D:\Python Directory\winPython 2.7\python-2.7.10.amd64\lib\site-packages\nolearn\lasagne\base.pyc in initialize(self)
360 out = getattr(self, '_output_layer', None)
361 if out is None:
--> 362 out = self._output_layer = self.initialize_layers()
363 self._check_for_unused_kwargs()
364
D:\Python Directory\winPython 2.7\python-2.7.10.amd64\lib\site-packages\nolearn\lasagne\base.pyc in initialize_layers(self, layers)
452 try:
453 layer_wrapper = layer_kw.pop('layer_wrapper', None)
--> 454 layer = layer_factory(**layer_kw)
455 except TypeError as e:
456 msg = ("Failed to instantiate {} with args {}.\n"
D:\Python Directory\winPython 2.7\python-2.7.10.amd64\lib\site-packages\lasagne\layers\special.pyc in __init__(self, incoming, localization_network, downsample_factor, **kwargs)
408 **kwargs):
409 super(TransformerLayer, self).__init__(
--> 410 [incoming, localization_network], **kwargs)
411 self.downsample_factor = as_tuple(downsample_factor, 2)
412
D:\Python Directory\winPython 2.7\python-2.7.10.amd64\lib\site-packages\lasagne\layers\base.pyc in __init__(self, incomings, name)
246 self.input_shapes = [incoming if isinstance(incoming, tuple)
247 else incoming.output_shape
--> 248 for incoming in incomings]
249 self.input_layers = [None if isinstance(incoming, tuple)
250 else incoming
AttributeError: 'str' object has no attribute 'output_shape'
```