项目场景:
在运行环境为: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)
文章出处登录后可见!
已经登录?立即刷新