[英]How to solve "model has not yet been built" error in Keras?
我在使用 CNN 時遇到了這個錯誤:
This model has not yet been built. Build the model first by calling `build()` or by calling the model on a batch of data.
我的代碼如下:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.callbacks import TensorBoard
model=Sequential()
model.add(Conv2D(32,5,input_shape=(1,28,28),activation='relu',data_format='channels_last'))
model.add(MaxPooling2D(pool_size=(2,2),strides=2))
model.add(Flatten())
model.add(Conv2D(64,5,input_shape=(1,28,28),activation='relu',data_format='channels_last'))
model.add(MaxPooling2D(pool_size=2,strides=2))
model.add(Flatten())
model.add(Dense(units=32,activation='relu'))
model.add(Dropout(0.4))
model.add(Dense(units=1,activation='softmax'))
model.summary()
根據錯誤,運行:
input_shape=(1,28,28)
model.build(input_shape)
model.summary()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.