keras中module ‘keras.utils‘ has no attribute ‘to

keras中module ‘keras.utils‘ has no attribute ‘to,第1张

项目场景:

在运行环境为:python 3.9.7,tensorflow 2.6.0,keras 2.6.0模型训练中报错


问题描述

当代码编辑如下时,运行中总会报出module 'keras.utils' has no attribute 'to_categorical'的错误

y_train = keras.utils.to_categorical(y_train, 10)
y_test = keras.utils.to_categorical(y_test, 10)


 

原因分析:

to_categorical的依赖包引用格式错误导致无法加载运行


解决方案:

import tensorflow as tf

y_train = tf.keras.utils.to_categorical(y_train, 10)
y_test = tf.keras.utils.to_categorical(y_test, 10)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/571196.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存