Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'to_categorical' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)

I have just got below error from an import that use to work fine few hours ago going downward.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-33-4c52b67c20bf> in <module>()
      1 import keras
----> 2 from keras.utils import to_categorical

ImportError: cannot import name 'to_categorical' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Is Keras busy with Update to have this method deprecated?

enter image description here

like image 626
Jay eMineM Avatar asked May 26 '21 11:05

Jay eMineM


1 Answers

use this

from tensorflow.keras.utils import to_categorical

instead of

from keras.utils import to_categorical
like image 123
Mano S Avatar answered Oct 30 '22 03:10

Mano S