我希望您使用Keras创建和训练一个卷积神经网络模型,用于对纸币进行分类。使用简单的教程可以很好地创建模型,但使用我从这篇论文中采用的结构时出现了问题。在调用
如果您使用tensorflow后端,则可能需要注意。
该模型在
据我所理解,Keras 的过程如下:
非常感谢您提供的任何帮助! :)
fit_generator()
后,Keras输出:RuntimeError('You must compile your model before using it.')
。如果您使用tensorflow后端,则可能需要注意。
该模型在
model.py
中定义:from keras.layers import ...
model = Sequential()
model.add(some_layer)
... #according to the paper
model.add(some_layer)
model.add(Dense(#output_classes, activation='softmax') #last layer
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
从start_train.py
开始使用model
:
from model import model as m
#some ImageGenerator stuff as input
m.fit_generator( #training on train_data
train_pics,
steps_per_epoch=#steps,
epochs=#epochs,
validation_data=test_pics,
据我所理解,Keras 的过程如下:
- 定义模型
- 编译模型
- (如果需要,在编译后可以使用 evaluate() 和 summary() 进行评估)
- 拟合模型
- 评估模型。
非常感谢您提供的任何帮助! :)
start_train.py
脚本中运行model.compile()
,它是否无法正常工作? - sdcbr