[英]This model has not yet been built error on model.summary()
[英]model.summary error for RNN. This model has not yet been built
我正在使用以下代碼:
model = Sequential()
model.add(Conv2D(filters=96, kernel_size=(11,11), strides=(11, 3),input_shape=(input_length,input_features,1), activation='relu'))
model.add(Dense(5, activation="softmax"))
model.compile(loss='categorical_crossentropy', metrics=["accuracy"], optimizer=optimizer(lr))
model.summary()
del model
model = Sequential()
model.add(Bidirectional(LSTM(128, return_sequences=True, input_shape=(input_length,input_features))))
model.add(Dense(5, activation="softmax"))
model.compile(loss='categorical_crossentropy', metrics=["accuracy"], optimizer=optimizer(lr))
model.summary()
exit()
並獲得以下 output:
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 55, 55, 96) 11712
_________________________________________________________________
dense (Dense) (None, 55, 55, 5) 485
=================================================================
Total params: 12,197
Trainable params: 12,197
Non-trainable params: 0
_________________________________________________________________
Traceback (most recent call last):
File "Convert2hdf5.py", line 28, in <module>
model.summary()
File "/home/erez/projects/Journal/VE/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2376, in summary
raise ValueError('This model has not yet been built. '
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling `fit()` with some data, or specify an `input_shape` argument in the first layer(s) for automatic build.
為什么Conv2D
層使用input_shape
指定輸入就足夠了,而對於 LSTM 還不夠? 我在這里做錯了嗎?
你已經用一個Bidirectional
層包裹了你的LSTM
層。 因此,您應該將input_shape
參數傳遞給Bidirectional
而不是LSTM
層。 根據以下內容進行更改:
model.add(Bidirectional(LSTM(128, return_sequences=True), input_shape=(nput_length, input_features)))
model 然后編譯沒有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.