Я новичок в изучении глубокого подкрепления и имею проблему с использованием Theano a Lasagne для воспроизведения модели, описанной здесь: https://openreview.net/pdf?id=SklPFVXUsN стр. 5, поскольку она близка к моему собственному контексту.
Здеськод, который я использую для создания слоев модели:
def build_crafted_network(self, l_carte, h_carte, l_minimap, h_minimap, l_tinymap, h_tinymap, nb_properties,
output_dim, batch_size):
self.l_in_carte = lasagne.layers.InputLayer(
shape=(batch_size, l_carte, h_carte)
)
self.l_in_minimap = lasagne.layers.InputLayer(
shape=(batch_size, l_minimap, h_minimap)
)
self.l_in_tinymap = lasagne.layers.InputLayer(
shape=(batch_size, l_tinymap, h_tinymap)
)
self.l_in_properties = lasagne.layers.InputLayer(
shape=(batch_size, 1, nb_properties)
)
l_embedding_carte = lasagne.layers.EmbeddingLayer(
self.l_in_carte,
input_size=l_carte*h_carte,
output_size=32
)
l_embedding_minimap = lasagne.layers.EmbeddingLayer(
self.l_in_minimap,
input_size=l_minimap*h_minimap,
output_size=32
)
l_embedding_tinymap = lasagne.layers.EmbeddingLayer(
self.l_in_tinymap,
input_size=l_tinymap*h_tinymap,
output_size=32
)
l_embedding_properties = lasagne.layers.EmbeddingLayer(
self.l_in_properties,
input_size=nb_properties,
output_size=64
)
l_dimshuffle_carte = lasagne.layers.DimshuffleLayer(
l_embedding_carte,
(0,3,1,2)
)
l_dimshuffle_minimap= lasagne.layers.DimshuffleLayer(
l_embedding_minimap,
(0,3,1,2)
)
l_dimshuffle_tinymap = lasagne.layers.DimshuffleLayer(
l_embedding_tinymap,
(0,3,1,2)
)
l_conv_carte = lasagne.layers.Conv2DLayer(
l_dimshuffle_carte,
num_filters=32,
filter_size=(3, 3),
nonlinearity=lasagne.nonlinearities.rectify
)
l_conv_minimap = lasagne.layers.Conv2DLayer(
l_dimshuffle_minimap,
num_filters=32,
filter_size=(3, 3),
nonlinearity=lasagne.nonlinearities.rectify
)
l_conv_tinymap = lasagne.layers.Conv2DLayer(
l_dimshuffle_tinymap,
num_filters=32,
filter_size=(3, 3),
nonlinearity=lasagne.nonlinearities.rectify,
pad=1
)
l_conv2_carte = lasagne.layers.Conv2DLayer(
l_conv_carte,
num_filters=64,
filter_size=(3, 3),
nonlinearity=lasagne.nonlinearities.rectify
)
l_conv2_minimap = lasagne.layers.Conv2DLayer(
l_conv_minimap,
num_filters=64,
filter_size=(3, 3),
nonlinearity=lasagne.nonlinearities.rectify
)
l_conv2_tinymap = lasagne.layers.Conv2DLayer(
l_conv_tinymap,
num_filters=64,
filter_size=(3, 3),
nonlinearity=lasagne.nonlinearities.rectify,
pad=1
)
l_fc_properties = lasagne.layers.DenseLayer(
l_embedding_properties,
num_units=256,
nonlinearity=None,
W=lasagne.init.Constant(0.0),
b=None
)
l_flatten_carte = lasagne.layers.FlattenLayer(
l_conv2_carte, 2
)
l_flatten_minimap = lasagne.layers.FlattenLayer(
l_conv2_minimap, 2
)
l_flatten_tinymap = lasagne.layers.FlattenLayer(
l_conv2_tinymap, 2
)
l_merge_layer = lasagne.layers.ConcatLayer(
(l_flatten_carte, l_flatten_minimap, l_flatten_tinymap, l_fc_properties),
axis=1
)
l_hidden_layer = lasagne.layers.DenseLayer(
l_merge_layer,
num_units=256,
nonlinearity=None,
W=lasagne.init.Constant(0.0),
b=lasagne.init.Constant(.1)
)
l_out = lasagne.layers.DenseLayer(
l_hidden_layer,
num_units=output_dim,
nonlinearity=T.nnet.softmax,
W=lasagne.init.Normal(.01),
b=lasagne.init.Constant(.1)
)
return l_out
Сборка build_network завершается без ошибок, но затем происходит сбой при
states_carte = T.tensor4('states_carte', dtype='int8')
states_minimap = T.tensor4('states_minimap', dtype='int8')
states_tinymap = T.tensor4('states_tinymap', dtype='int8')
states_properties = T.tensor4('states_properties', dtype='int16')
states_dict = {self.l_in_carte:states_carte, self.l_in_minimap:states_minimap, self.l_in_tinymap:states_tinymap, self.l_in_properties:states_properties}
q_vals = lasagne.layers.get_output(self.l_out, inputs = states_dict)
со следующей ошибкой:
Traceback (most recent call last):
File "stester.py", line 99, in <module>
np.random.RandomState(123456))
File "/home/barre/Private/DeepDofus/deep_q_learn.py", line 121, in __init__
q_vals = lasagne.layers.get_output(self.l_out, inputs = states_dict)
File "/home/barre/anaconda3/envs/deepdofus/lib/python3.7/site-packages/lasagne/layers/helper.py", line 197, in get_output
all_outputs[layer] = layer.get_output_for(layer_inputs, **kwargs)
File "/home/barre/anaconda3/envs/deepdofus/lib/python3.7/site-packages/lasagne/layers/shape.py", line 284, in get_output_for
return input.dimshuffle(self.pattern)
File "/home/barre/anaconda3/envs/deepdofus/lib/python3.7/site-packages/theano/tensor/var.py", line 358, in dimshuffle
pattern)
File "/home/barre/anaconda3/envs/deepdofus/lib/python3.7/site-packages/theano/tensor/elemwise.py", line 197, in __init__
(input_broadcastable, new_order))
ValueError: ('You cannot drop a non-broadcastable dimension.', ([False, False, False, False, False], (0, 3, 1, 2)))
Кажется, что слой dimshuffle не работает должным образом, но я не понимаю, почему, поскольку двумерный сверточный слой требует такой ввод, как (batch_size, num_input_channels, input_rows, input_columns)
Я использую этиверсии: theano 1.0.4 + 21.g8f510a1f0 pypi_0 pypi lasagne 0.2.dev1 pypi_0 pypi python 3.7.4 h265db76_1
Полный код доступен по адресу https://pastebin.com/7z1uwvs8