keras-team / keras-cv

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

incompatibility issue between keras_cv and TensorFlow and keras in windows 10 #2354

Open said-ml opened 8 months ago

said-ml commented 8 months ago

i install keras_cv, keras and tensorflow , with all options that specified in guidline of kerasCV installation , when i run:


import os
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'

import keras_cv
import keras
from keras.losses import KLDivergence
from keras.utils import plot_model
from keras import backend

from configurations import classes
from configurations import preset_with_weights
from keras.models import Model

preset = "efficientnetv2_b2_imagenet"

def model(preset:str, classes:list[str])->Model:
    if preset_with_weights not in preset_with_weights:
       raise ValueError(f'{preset} we want a pretrained model')

       # Build Classifier
    model = keras_cv.models.ImageClassifier.from_preset(preset=preset,
                                                        num_classes=len(classes)
                                                        )

    # Compile the model
    model.compile(optimizer=keras.optimizers.Adam(learning_rate=1e-4),
              loss=  KLDivergence)

    return model

model=model(preset, classes)
# Model Sumamry
model.summary()

``` python

i get errors: 
Traceback (most recent call last):
  File "C:\Users\LG\PycharmProjects\HarmfulBrainActivityClassification\models\pretrained_models.py", line 4, in <module>
    import keras_cv
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\__init__.py", line 8, in <module>
    from keras_cv import bounding_box
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\bounding_box\__init__.py", line 8, in <module>
    from keras_cv.src.bounding_box.converters import convert_format
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\src\__init__.py", line 30, in <module>
    from keras_cv.src import bounding_box
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\src\bounding_box\__init__.py", line 15, in <module>
    from keras_cv.src.bounding_box.converters import _decode_deltas_to_boxes
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\src\bounding_box\converters.py", line 19, in <module>
    from keras_cv.src.api_export import keras_cv_export
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\src\api_export.py", line 17, in <module>
    from keras_cv.src.backend import keras
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\src\backend\__init__.py", line 29, in <module>
    from keras_cv.src.backend import keras  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras_cv\src\backend\keras.py", line 36, in <module>
    from tensorflow.keras import *  # noqa: F403, F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\api\_v2\keras\__init__.py", line 3, in <module>
    from keras.api._v2.keras import __internal__
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\__init__.py", line 3, in <module>
    from keras import __internal__
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\__internal__\__init__.py", line 6, in <module>
    from keras.__internal__ import models
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\__internal__\models\__init__.py", line 3, in <module>
    from keras.src.models.cloning import clone_and_build_model
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\__init__.py", line 21, in <module>
    from keras.src import applications
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\applications\__init__.py", line 18, in <module>
    from keras.src.applications.convnext import ConvNeXtBase
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\applications\convnext.py", line 33, in <module>
    from keras.src.engine import sequential
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\sequential.py", line 24, in <module>
    from keras.src.engine import functional
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\functional.py", line 33, in <module>
    from keras.src.engine import training as training_lib
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\engine\training.py", line 48, in <module>
    from keras.src.saving import saving_api
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\saving\saving_api.py", line 25, in <module>
    from keras.src.saving.legacy import save as legacy_sm_saving_lib
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\saving\legacy\save.py", line 27, in <module>
    from keras.src.saving.legacy.saved_model import load_context
  File "C:\Users\LG\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\saving\legacy\saved_model\load_context.py", line 68, in <module>
    tf.__internal__.register_load_context_function(in_load_context)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'register_load_context_function'. Did you mean: 'register_call_context_function'?
sachinprasadhs commented 7 months ago

Could you please install the latest Tensorflow and then upgrade your keras-cv and Keras version to latest and try again. Thanks

said-ml commented 7 months ago

i try it but it does not work

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.