How to fix “KeyError: ‘acc‘“

本文档介绍了在使用Keras训练模型时遇到的精度指标显示错误,问题在于旧版本Keras中精度指标的键是'acc'而非'accuracy'。解决方案是将代码中的'accuracy'替换为'acc'来正确绘制训练和验证的精度演化图。更新后的代码示例已给出。
摘要由CSDN通过智能技术生成

**

之所以会报错,是因为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( )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CZU_zzjj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值