我想转换这个宽面条代码:
et = {}
net['input'] = lasagne.layers.InputLayer((100, 1, 24, 113))
net['conv1/5x1'] = lasagne.layers.Conv2DLayer(net['input'], 64, (5, 1))
net['shuff'] = lasagne.layers.DimshuffleLayer(net['conv1/5x1'], (0, 2, 1, 3))
net['lstm1'] = lasagne.layers.LSTMLayer(net['shuff'], 128)
在Keras代码中。现在我想到了这个:
^{pr2}$但是我得到了一个错误:Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4
解决方案
解释
我把千层面和Keras的文件放在这里,这样你就可以交叉引用了:
Lasagne
Keras
基本上API是相同的,但是Lasagne可能会为您重新塑造(我需要稍后检查源代码)。所以你得到了这个错误:
^{pr2}$,因为
Conv2D
后面的张量形状是ndim=4
的(?, 64, 20, 113)
因此,解决方案是将其重塑为
(?, 20, 7232)
。在编辑
确认了千层面source code,它为您提供了窍门:
^{3}$所以正确的张量形状作为LSTM的输入是
(?, 20, 64 * 113)
=(?, 20, 7232)
注意
Permute
在Keras中是多余的,因为您无论如何都要重塑形状。我之所以把它放在这里的原因是有一个“完整的翻译”从宽面条到Keras,它做了DimshuffleLaye
在宽面条中的作用。在然而,宽面条需要
DimshuffleLaye
,因为我在编辑中提到的原因,宽面条LSTM创建的新维度来自于“最后两个”维度的乘法。在相关问题 更多 >
编程相关推荐