keras-team / keras-cv

Industry-strength Computer Vision workflows with Keras
Other
1.01k stars 331 forks source link

KerasCV on Google Colab #2376

Closed innat closed 6 months ago

innat commented 8 months ago

Tried to install keras-cv in colab with latest packages but got the following issue. However, this might be issue with colab and not keras-cv - not sure!!

!pip install --upgrade keras-cv-nightly tf-nightly keras-nightly

import tensorflow as tf
tf.__version__
2.17.0-dev20240310

import keras
keras.__version__
3.1.0.dev2024031103

import keras_cv
keras_cv.__version__
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-5-e37ee6d8d2a2>](https://localhost:8080/#) in <cell line: 1>()
----> 1 import keras_cv
      2 keras_cv.__version__

10 frames
[/usr/local/lib/python3.10/dist-packages/keras/api/_v2/keras/__internal__/backend/__init__.py](https://localhost:8080/#) in <module>
      1 """AUTOGENERATED. DO NOT EDIT."""
      2 
----> 3 from keras.src.backend import _initialize_variables as initialize_variables
      4 from keras.src.backend import track_variable

ImportError: cannot import name '_initialize_variables' from 'keras.src.backend' (/usr/local/lib/python3.10/dist-packages/keras/src/backend/__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.
---------------------------------------------------------------------------
sachinprasadhs commented 8 months ago

I was able to install all these packages in individual cell in colab, here is the Gist https://colab.sandbox.google.com/gist/sachinprasadhs/2c9a60d3e51bc986c37999c222675e87/2376.ipynb

innat commented 8 months ago

Not exactly. Inspect the first post, the packages did install but import error for keras-cv.

RichiDot commented 8 months ago

I have encountered the same issue. Although the Keras packages appear to be installed, I'm facing difficulties importing the modules. For instance, I encountered this error:

ModuleNotFoundError                       
Traceback (most recent call last)
[<ipython-input-2-1a02c2e511a0>](https://localhost:8080/#) in <cell line: 10>()
      8 import tensorflow as tf
      9 import tensorflow.experimental.numpy as tnp
---> 10 from keras_cv.models.stable_diffusion.clip_tokenizer import SimpleTokenizer
     11 from keras_cv.models.stable_diffusion.diffusion_model import DiffusionModel
     12 from keras_cv.models.stable_diffusion.image_encoder import ImageEncoder

ModuleNotFoundError: No module named 'keras_cv.models.stable_diffusion.clip_tokenizer
smitlg commented 8 months ago

I am trying to fix it in #2394. This isn't an issue on colab side.

smitlg commented 8 months ago

I was able to install all these packages in individual cell in colab, here is the Gist https://colab.sandbox.google.com/gist/sachinprasadhs/2c9a60d3e51bc986c37999c222675e87/2376.ipynb

Installation should work fine. import keras_cv will fail.

divyashreepathihalli commented 8 months ago

Your colab already has a keras version installed, and when you reinstall a different version - you might get this error. Please restart session and then do import keras - that should work.

smitlg commented 8 months ago

The failure comes from import keras_cv and keras_nlp is not installed.

scienceLabwork commented 5 months ago

I have encountered the same issue. Although the Keras packages appear to be installed, I'm facing difficulties importing the modules. For instance, I encountered this error:

ModuleNotFoundError                       
Traceback (most recent call last)
[<ipython-input-2-1a02c2e511a0>](https://localhost:8080/#) in <cell line: 10>()
      8 import tensorflow as tf
      9 import tensorflow.experimental.numpy as tnp
---> 10 from keras_cv.models.stable_diffusion.clip_tokenizer import SimpleTokenizer
     11 from keras_cv.models.stable_diffusion.diffusion_model import DiffusionModel
     12 from keras_cv.models.stable_diffusion.image_encoder import ImageEncoder

ModuleNotFoundError: No module named 'keras_cv.models.stable_diffusion.clip_tokenizer

Try using src in between keras_cv and models while importing

from keras_cv.src.models.stable_diffusion.clip_tokenizer import SimpleTokenizer
from keras_cv.src.models.stable_diffusion.diffusion_model import DiffusionModel
from keras_cv.src.models.stable_diffusion.image_encoder import ImageEncoder