修正from keras.utils import np_utils
原程式碼:from keras.utils import np_utils
y_train_onehot=np_utils.to_categorical(y_train_label)
y_test_onehot=np_utils.to_categorical(y_test_label)
出現錯誤:
ImportError Traceback (most recent call last) Cell In[42], line 1 ----> 1 from keras.utils import np_utils 2 y_train_onehot=np_utils.to_categorical(y_train_label) 3 y_test_onehot=np_utils.to_categorical(y_test_label) ImportError: cannot import name 'np_utils' from 'keras.utils' (C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\__init__.py)
修正成這樣就好了
from tensorflow.keras.utils import to_categorical
y_train_onehot = to_categorical(y_train_label)
y_test_onehot = to_categorical(y_test_label)
评论
发表评论