keras-team / keras-cv

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

import keras_cv fails #442

Closed johnypark closed 2 years ago

johnypark commented 2 years ago

First, thank you so much to all the contributors for their tremendous effort in building keras-cv.

Obviously, I would like to try it out, but in colab I could not load keras-cv:

https://colab.research.google.com/drive/1k-IrSJF-DlP_o27ohr7GvYsXliGRifTF?usp=sharing

---------------------------------------------------------------------------

ModuleNotFoundError                       Traceback (most recent call last)

[<ipython-input-6-1d020d0fde65>](https://localhost:8080/#) in <module>()
      1 import tensorflow as tf
----> 2 import keras_cv

1 frames

[/usr/local/lib/python3.7/dist-packages/keras_cv/layers/__init__.py](https://localhost:8080/#) in <module>()
     13 # limitations under the License.
     14 
---> 15 from tensorflow.keras.__internal__.layers import BaseImageAugmentationLayer
     16 from tensorflow.keras.layers import CenterCrop
     17 from tensorflow.keras.layers import RandomBrightness

ModuleNotFoundError: No module named 'tensorflow.keras.__internal__.layers'

---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------

Above is the error message I am getting. What am I missing? Any suggestions would be appreciated.

Thank you, John

LukeWood commented 2 years ago

Hey John! You’ll need to install it in Colab.

can you try running:

!pip install keras-cv

in a cell? Please note Colab may not have the newest version of TensorFlow yet, so we may need to wait on that.

I’ll try to get KerasCV included in Colab as well. Thanks for the feedback!

LukeWood commented 2 years ago

Just looked again John! You need to upgrade to TensorFlow 2.9

can you run

pip install —upgrade tensorflow

?

adhadse commented 2 years ago

Run this cell:

%%bash
git clone https://github.com/keras-team/keras-cv.git
mv keras-cv/keras_cv /content/keras_cv

pip uninstall tensorflow -y
pip install tf-nightly==2.10.0.dev20220427

pip uninstall keras -y
pip install keras-nightly==2.10.0.dev2022042807

import keras_cv

The library is currently using a nightly version of TensorFlow and Keras for development. This is what we are using, give it a shot.

johnypark commented 2 years ago

Hi @LukeWood @adhadse Thank you for your prompt responses!

Upgrading TensorFlow to 2.9. worked.

So is there a big difference between the nightly version and the 2.9 version of keras-cv?

I am interested in using the RandAugment layer, would you recommend using the nightly version?

Thank you, John

bhack commented 2 years ago

More in general with https://github.com/keras-team/keras-cv/pull/417 we have removed the wheel/install dependency.

So now we have only rely to a runtime check: https://github.com/keras-team/keras-cv/blob/master/keras_cv/version_check.py

But If tensorflow is not installed and we install only keras_cv in a fresh venv/container:

import keras_cv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/keras_cv/__init__.py", line 15, in <module>
    from keras_cv import layers
  File "/usr/local/lib/python3.10/site-packages/keras_cv/layers/__init__.py", line 15, in <module>
    from tensorflow.keras.__internal__.layers import BaseImageAugmentationLayer
ModuleNotFoundError: No module named 'tensorflow'
LukeWood commented 2 years ago

Hi @LukeWood @adhadse Thank you for your prompt responses!

Upgrading TensorFlow to 2.9. worked.

So is there a big difference between the nightly version and the 2.9 version of keras-cv?

I am interested in using the RandAugment layer, would you recommend using the nightly version?

Thank you, John

Hey John, I'd recommend TensorFlow 2.9. Nightly is released every night, 2.9 is a vetted, thoroughly tested release.

LukeWood commented 2 years ago

p.s. @johnypark let me know what you use our RandAugment for! Really interested in seeing it!

johnypark commented 2 years ago

@LukeWood Thank you!

I would love to elaborate on what I am working on. We are doing a fine-grained classification task for herbarium specimen images (plant images), to help botanists with more efficient biodiversity discovery. Since herbaria around the world have about 30M high-resolution images of very well curated 400K plant labels, we think it would be worth the intention from the vision community as well. We also host an annual competition through Kaggle (https://www.kaggle.com/competitions/herbarium-2022-fgvc9)!

bhack commented 2 years ago

@LukeWood @qlzh727 I will reconsider this or please open a related ticket as this kind of behavior is really user unfriendly. See again my comment at https://github.com/keras-team/keras-cv/issues/442#issuecomment-1131831501

LukeWood commented 2 years ago

@LukeWood @qlzh727 I will reconsider this or please open a related ticket as this kind of behavior is really user unfriendly. See again my comment at #442 (comment)

Perhaps we should specify a >= relationship with 2.9.0. Can we do this in setup.py dependencies? Or will this require us to use requirements.txt

bhack commented 2 years ago

Yes you could do this in setup.py or requirements.txt as you like: https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/

The problem is more about CPU/GPU TF. If we don't want to publish two Keras-cv wheels the alternatives are a bit ugly: https://github.com/tensorforce/tensorforce/issues/31

LukeWood commented 2 years ago

I see, maybe we can opt the root init.py out of linting so we can run the version check before we import layers.

bhack commented 2 years ago

Keras totally ignore that we have two distinct upstream wheels (CPU/GPU) and depend on GPU:

https://github.com/keras-team/keras/blob/master/requirements.txt#L6

LukeWood commented 2 years ago

Keras totally ignore that we have two distinct upstream wheels (CPU/GPU) and depend on GPU:

https://github.com/keras-team/keras/blob/master/requirements.txt#L6

From your perspective is this problematic or ok? AFAIK tensorflow works on both GPU and CPU on unix based OSes.

bhack commented 2 years ago

From your perspective is this problematic or ok? AFAIK tensorflow works on both GPU and CPU on unix based OSes.

Honestly if you want my opinion it is mainly a disk space topic on your environment:

CPU+GPU: tensorflow-2.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (511.7 MB)

CPU: tensorflow_cpu-2.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (207.5 MB)

So compressed is already more then 2.5x.

qlzh727 commented 2 years ago

Note that keras (as part of the tf API) doesn't list any dependency by itself. It always get its needed package from tensorflow. The requirements.txt in keras repo is purely for test purpose (local env setup). End user will always access keras package via pip install tensorflow package.

As of Keras CV, since it relies on tf/keras, we should config proper version dependency for it, so that CV nightly will install tf/keras-nightly, same for formal release version.

bhack commented 2 years ago

@qlzh727 Yes I know this but I've mentioned it cause we have already a parallel CI/dev_env ticket at https://github.com/keras-team/keras-cv/issues/440

qlzh727 commented 2 years ago

Ack. Will comment on #440.

David-OConnor commented 1 year ago

Getting this with the latest CAO Oct 2023.