网上查了一些方法对我没用。猜测是Keras版本的问题。
然后我直接改成调用tensorflow中的keras模块,问题解决!
具体如下:
1.输入:
from keras.utils import to_categorical
报错:
2.修改后:
from tensorflow.keras.utils import to_categorical
运行成功!
其他解决方法:
cannot import name ‘to_categorical‘ from ‘keras.utils‘_FFFFfenghen的博客-CSDN博客
cannot import name ‘to_categorical‘ from ‘keras.utils‘_u011250160的博客-CSDN博客