Mi cuaderno estaba funcionando hasta hoy. Al inicio de mi notebook colab instalo tf-nightly, pero ahora me esta dando este error
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-1-589c442233c5> in <module>() 7 import tensorflow as tf 8 from tensorflow.keras import datasets, layers, models ----> 9 from keras.preprocessing import image 10 from keras_preprocessing.image import ImageDataGenerator #check underscore or not 11 from tensorflow.keras.preprocessing import image_dataset_from_directory 2 frames /usr/local/lib/python3.7/dist-packages/keras/backend.py in <module>() 35 from tensorflow.python.distribute import distribute_coordinator as dc 36 from tensorflow.python.distribute import distribute_coordinator_context as dc_context ---> 37 from tensorflow.python.eager.context import get_config 38 from tensorflow.python.framework import config 39 from keras import backend_config ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' (/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/eager/context.py)Este es mi código:
!pip install tf-nightly import tensorflow as tf from tensorflow.keras import datasets, layers, models from keras.preprocessing import image from keras_preprocessing.image import ImageDataGenerator from tensorflow.keras.preprocessing import image_dataset_from_directory from keras.callbacks import Callback, ModelCheckpoint, ReduceLROnPlateau, EarlyStoppingHe intentado instalar tensorflow==2.1.0 y tampoco ha funcionado. Si comento esa importación, aparece otro error en la siguiente línea y no he podido encontrar mucho en línea sobre esto. ¡Cualquier ayuda sería apreciada!
En lugar de
import kerastratar
from tensorflow import keras¡Esto funcionó para mí!
Estos comandos solucionaron el problema:
pip install --upgrade tensorflow pip install --upgrade tensorflow-gpuTenía Tensorflow===2.2.0 y cuando lo actualicé a Tensorflow==2.4.0 ocurrió este problema.
Creo que hay un conflicto entre keras.models.load_model y la versión base de tensorflow que estás usando.
Intenta correr -
import tensorflow as tf tf.keras.models.load_model(model_path)Funcionó para mí.
Este extraño problema se corresponde con las importaciones de tensorflow. Si cambia from keras.preprocessing import image from tensorflow.keras.preprocessing import image , funcionará.
Prueba la versión de Keras 2.3.1
pip install keras==2.3.1
entonces también instala eso
pip install git+https://www.github.com/keras-team/keras-contrib.git
he actualizado
from keras.preprocessing.image import ImageDataGenerator from keras.preprocessing.image import img_to_array, load_img from keras import layers, models, optimizers from keras import backend as Kpara
from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.keras.preprocessing.image import img_to_array, load_img from tensorflow.keras import layers, models, optimizers from tensorflow.keras import backend as Ky funciona :)
pip install --upgrade tensorflow pip install --upgrade tensorflow-gpuFunciona, pero interferirá con la configuración de soporte de GPU Tensorflow/NVIDIA CUDA Toolkit/NVIDIA cuDNN. Mejor solución: desinstale Keras 2.6.0, instale Keras 2.4.3
¡El error está solucionado y la GPU se está ejecutando!
En mi caso con Google colab, bajé tensorflow a 2.2 y reemplacé todo import keras.xxxx para import tensorflow.keras.xxxx . Eso lo arregló.
en lugar de from keras.preprocessing import image haga esto: from tensorflow.keras.preprocessing import image
Acabo de resolver este problema por mí mismo.
# Instead of this: from keras.preprocessing import image # Do this: from tensorflow.keras.preprocessing import imageEn mi caso cambié la importación de lo siguiente:
from keras.preprocessing.image import ImageDataGeneratorA esto:
from tensorflow.keras.preprocessing.image import ImageDataGeneratorPara mí, solo funciona actualizando tensorflow. Nota: si está utilizando tensorflow especial como versión gpu, debe actualizar este porque es un módulo separado.
pip install --upgrade tensorflow