LSTMレイヤーを間に挟んでノイズ除去オートエンコーダーを実装しようとしています。アーキテクチャは次のとおりです。
FC layer -> FC layer -> LSTM cell -> FC layer -> FC layer.
このアーキテクチャを実装するために入力ディメンションをどのようにすべきか理解できませんか?
次のコードを試しました
batch_size = 1
model = Sequential()
model.add(Dense(5, input_shape=(1,)))
model.add(Dense(10))
model.add(LSTM(32))
model.add(Dropout(0.3))
model.add(Dense(5))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY, nb_epoch=100, batch_size=batch_size, verbose=2)
私のtrainXは[650,20,1]ベクトルです。特徴が1つしかない時系列データです。
次のエラーが発生します
ValueError Traceback (most recent call last)
<ipython-input-20-1248a33f6518> in <module>()
3 model.add(Dense(5, input_shape=(1,)))
4 model.add(Dense(10))
----> 5 model.add(LSTM(32))
6 model.add(Dropout(0.3))
7 model.add(Dense(5))
/usr/local/lib/python2.7/dist-packages/keras/models.pyc in add(self, layer)
330 output_shapes=[self.outputs[0]._keras_shape])
331 else:
--> 332 output_tensor = layer(self.outputs[0])
333 if isinstance(output_tensor, list):
334 raise TypeError('All layers in a Sequential model '
/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in __call__(self, x, mask)
527 # Raise exceptions in case the input is not compatible
528 # with the input_spec specified in the layer constructor.
--> 529 self.assert_input_compatibility(x)
530
531 # Collect input shapes to build layer.
/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in assert_input_compatibility(self, input)
467 self.name + ': expected ndim=' +
468 str(spec.ndim) + ', found ndim=' +
--> 469 str(K.ndim(x)))
470 if spec.dtype is not None:
471 if K.dtype(x) != spec.dtype:
ValueError: Input 0 is incompatible with layer lstm_10: expected ndim=3, found ndim=2
密なレイヤーはシーケンスを入力として受け取ることができ、すべてのベクトル(最後の次元)に同じ密なレイヤーを適用します。例:
シーケンスを表す2Dテンソル入力(timesteps, dim_features)
があります。new_dim出力を使用して密なレイヤーを適用すると、レイヤーの後にあるテンソルは新しいシーケンスになります。(timesteps, new_dim)
(n_lines, n_words, embedding_dim)
ドキュメントになり得る3Dテンソルがあり、n_lines
行、n_words
行embedding_dim
ごとの単語、および各単語の寸法がある場合、new_dim出力を使用して高密度レイヤーを適用すると、形状のある新しいドキュメントテンソル(3D)が得られます。(n_lines, n_words, new_dim)
あなたはできますここを参照してくださいあなたが餌と高密度()層を得ることができるという寸法入力と出力を。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加