本文是关于运行from keras.utils import to_categorical出错如何解决
to_categorical报错
把keras库安装好后,在深度学习标签准备模块那里通常会用到keras.utils中的to_categorical函数,通常我们直接用引入函数:
from keras.utils import to_categorical
但是这样运行后就报错了,报错显示:
ImportError: cannot import name 'to_categorical'
解决办法
keras此时是在tensorflow的环境中
所以从tensorflow中引入就可以了,嘻嘻:
from tensorflow.keras.utils import to_categorical
在尝试使用`from keras.utils import to_categorical`时遇到ImportError,问题在于keras实际位于tensorflow环境中。解决方法是直接从tensorflow.keras.utils导入to_categorical,即`from tensorflow.keras.utils import to_categorical`。
1060

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



