**
之所以会报错,是因为keras库老版本中的参数不是accuracy,而是acc,将参数accuracy替换为acc,
**
please try
# plot accuracy evolution vs epochs
fig = plt.figure( )
ax = fig.add_subplot( 111 )
ax.plot( hist.history[ 'accuracy' ], linewidth = 3. )
ax.plot( hist.history[ 'val_accuracy' ], linewidth = 3. )
plt.title( ' Accuracy' )
plt.ylabel( 'Accuracy' )
plt.xlabel( 'Epoch' )
plt.legend( [ 'Train', 'Validation' ], loc = 'upper left' )
plt.savefig( join( self.resultDir, self.modelFileName + '_accuracy_function.png' ) )
plt.show( )
instead of
# plot accuracy evolution vs epochs
fig = plt.figure( )
ax = fig.add_subplot( 111 )
ax.plot( hist.history[ 'acc' ], linewidth = 3. )
ax.plot( hist.history[ 'val_acc' ], linewidth = 3. )
plt.title( ' Accuracy' )
plt.ylabel( 'Accuracy' )
plt.xlabel( 'Epoch' )
plt.legend( [ 'Train', 'Validation' ], loc = 'upper left' )
plt.savefig( join( self.resultDir, self.modelFileName + '_accuracy_function.png' ) )
plt.show( )
本文档介绍了在使用Keras训练模型时遇到的精度指标显示错误,问题在于旧版本Keras中精度指标的键是'acc'而非'accuracy'。解决方案是将代码中的'accuracy'替换为'acc'来正确绘制训练和验证的精度演化图。更新后的代码示例已给出。
4204

被折叠的 条评论
为什么被折叠?



