UserWarning: RuntimeError: 文中的错误应该怎么解决求答案

UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
  cnn_model.fit_generator(training_set,epochs=20)


RuntimeError: You must compile your model before training/testing. Use `model.compile(optimizer, loss)`.



#建立CNN模型
from tensorflow.keras import Sequential
from keras.layers import Conv2D,MaxPool2D,Flatten,Dense

cnn_model = Sequential()
#添加卷积层
cnn_model.add(Conv2D(32,(3,3),input_shape=(50,50,3),activation='relu'))
#添加池化层
cnn_model.add(MaxPool2D(pool_size=(2,2)))
#添加卷积层
cnn_model.add(Conv2D(32,(3,3),activation='relu'))
#添加池化层
cnn_model.add(MaxPool2D(pool_size=(2,2)))
#flatten展开
cnn_model.add(Flatten())
#FC层
cnn_model.add(Dense(units=128,activation='relu'))
#预测输出层
cnn_model.add(Dense(units=1,activation='sigmoid'))
cnn_model.summary()
#模型配置
#cnn_model.compile(optimizer='adam',loss='binary_crossentropy',metrcs=['accuracy'])
#模型训练
cnn_model.fit_generator(training_set,epochs=20)

你可能感兴趣的:(tensorflow,深度学习,人工智能,keras)