keras-nlp icon indicating copy to clipboard operation
keras-nlp copied to clipboard

KerasHub has mandatory dependency on tensorflow-text but it isn't mandatory

Open jamesmyatt opened this issue 10 months ago • 14 comments

Can tensorflow-text be removed as a mandatory dependency, please? e.g. move it to an optional dependency group, e.g. "nlp"

As far as I can tell, this dependency makes it impossible to either:

  • have a tensorflow-free environment
  • install KerasHub at all on Windows

Both of these seem to be contrary to Keras 3's mission, especially if you only want the CV parts of KerasHub.

Furthermore, the NoTensorflow integration tests show that it's acceptable to manually uninstall tensorflow and tensorflow-text after installing keras-hub. But it's not possible to never install them in the first place.

I think this was tolerable when this package was KerasNLP (e.g. https://github.com/keras-team/keras-hub/pull/1585, https://github.com/keras-team/keras/issues/19542), but now that it's KerasHub, it's a serious issue.

jamesmyatt avatar Feb 14 '25 12:02 jamesmyatt

+1 agree

Can't install keras-hub when I have enforced tensorflow<2.18 on MacOS as tensorflow-text don't support that.
It's quite annoying as I'm using keras-hub for its CV use-case.

Lundez avatar Feb 17 '25 07:02 Lundez

Thanks for bringing this up!

abheesht17 avatar Feb 18 '25 23:02 abheesht17

Thanks

jamesmyatt avatar Feb 19 '25 14:02 jamesmyatt

Shoot! I think we actually might need to roll this back. tensorflow and tensorflow-text are indeed optional at import time, but really just as a power user feature. No task will work without tensorflow installed because we currently use tf.data for all preprocessing in the library. The no-tensorflow approach only works if you want to do all preprocessing and task setup yourself (very valid to do, but not our biggest usage path).

On a clean system, if you run pip install keras-hub and then the following...

import keras_hub
classifier = keras_hub.models.ImageClassifier.from_preset(
    "resnet_50_imagenet",
)

You would now get an error saying tensorflow is required (when trying to create image preprocessing layers). That's a breaking change I don't think we want! And even more confusing that the fix is to append "nlp" to the install line.

mattdangerw avatar Feb 27 '25 05:02 mattdangerw

Instead I think we need the following for now.

  1. pip install keras-hub should pull in tensorflow-text and tensorflow for now. We want a usable experience out of the box.
  2. We can exclude tensorflow-text on the windows platform since tensorflow dropped support. Of course that means keras-hub is barely usable on native windows, but our recommend path for windows development is WSL.
  3. For power users that know what they are doing and do not want the task API, the no tf approach will require pip install keras-hub --no-deps.

The better solution will need to be one of the following.

  1. If https://peps.python.org/pep-0771/ gets approved, then pip install keras-hub can keep giving a usable out of box experience, and pip install keras-hub[base] can give the pared down installation.
  2. If not, we could consider a separate package, so pip install keras-hub is what most people use, and pip install keras-hub-base gives you the pared down list of requirements.
  3. Finally, and ideally, we could ditch our dependency on tensorflow for preprocessing. We would love to do this honestly, and then tensorflow could really be optional for the average user! However this is a larger undertaking.

I know this is less than ideal, but hopefully we can start making progress towards making tf.data actually optional, and till then use --no-deps as work around.

mattdangerw avatar Feb 27 '25 05:02 mattdangerw

This disappointing. There really needs to be a version of KerasHub that doesn't have a mandatory dependency on tensorflow, for either of the reasons listed above.

Even on linux, if KerasHub has a mandatory dependency on tensorflow, then it negates any the benefit of the multi-backend capability of Keras 3. For example, do you really want to spend time coordinating which versions of tensorflow and pytorch can be installed in the same venv with the same version of cuda/nocuda and all of the other dependencies?

One interim question is whether it will work with tensorflow "core" as a mandatory (linux) dependency and tensorflow-text as an optional "nlp" dependency, if the main issue is tf.data? At least that avoids the extra complexity of the tensorflow-text project.

KerasHub (as successor to KerasCV and KerasNLP) is advertised as a replacement for the discontinued tf.addons project, and that has to be taken into account too. It's not just a Keras wrapper for third-party models. At least as I understand it.

jamesmyatt avatar Feb 27 '25 13:02 jamesmyatt

Agreed, this too me is a big problem as I'd like to use another backend for my CV project... Which is one of the major "selling-points" of Keras 3.

Lundez avatar Feb 27 '25 13:02 Lundez

KerasHub doesn't necessarily need to be totally backend agnostic, just needs to respect to the backend selected for Keras itself. So if it depends on tf.data (for example) currently, then that should to be abstracted and adapted for the other backends. There may even already be something in Keras 3.

jamesmyatt avatar Feb 27 '25 17:02 jamesmyatt

@jamesmyatt @Lundez yeah the issue moreso than tf-text is that all preprocessing is currently run through tf.data. So tf.data will feed your jax or torch program for a pure vision model. Which at a performance level is actually great, tf.data is quite efficient.

So the expected use today is for the library is a cpu install of tensorflow with a gpu torch or jax (see here and here), or a gpu install of tf. Cuda version aligning across frameworks is indeed tricky, Colab and Kaggle do it but I wouldn't recommend for a local development.

I agree tough this dep kinda sucks. Tensorflow is a huge binary. It would be great to relax this constraint, and thing things like our ObjectDetection and ImageClassifier tasks would be runnable without a tf install and tf would only be in the loop for text models. But we should start that work at the code level, just ditching the dep today will break people for little gain.

So for today...

  • The common workflow is tf, jax or torch with a cpu only tf install for preprocessing. API works as advertise on all three backends.
  • The power user workflow is a --no-deps install, use only backbone APIs and do all your own preprocessing, task construction, etc.

mattdangerw avatar Feb 27 '25 20:02 mattdangerw

I opened #2128 as a first step for this.

mattdangerw avatar Mar 06 '25 01:03 mattdangerw

I opened #2128 as a first step for this.

Exciting.

While I understand the issue that Keras Hub relies on TF Datasets, and the perks of efficient pipelines makes sense. The same could be said about making Keras multi-framework in 3.0, TF isn't a slow framework (if you apply XLA).

I'm happy that the investigation starts now to drop the reliance as it'd be very welcome! Perhaps if TF Dataset didn't rely on TF it could be a very good compromise, but I guess that's an even bigger project 😂

Once again, thanks for initiating a move in the right direction!

EDIT: I hope I find the time to look into #2128

Lundez avatar Mar 07 '25 15:03 Lundez

Instead I think we need the following for now.

  1. pip install keras-hub should pull in and for now. We want a usable experience out of the box.tensorflow-text``tensorflow
  2. We can exclude on the windows platform since tensorflow dropped support. Of course that means is barely usable on native windows, but our recommend path for windows development is WSL.tensorflow-text``keras-hub
  3. For power users that know what they are doing and do not want the task API, the no tf approach will require .pip install keras-hub --no-deps

The better solution will need to be one of the following.

  1. If https://peps.python.org/pep-0771/ gets approved, then can keep giving a usable out of box experience, and can give the pared down installation.pip install keras-hub``pip install keras-hub[base]
  2. If not, we could consider a separate package, so is what most people use, and gives you the pared down list of requirements.pip install keras-hub``pip install keras-hub-base
  3. Finally, and ideally, we could ditch our dependency on tensorflow for preprocessing. We would love to do this honestly, and then tensorflow could really be optional for the average user! However this is a larger undertaking.

I know this is less than ideal, but hopefully we can start making progress towards making actually optional, and till then use as work around.tf.data``--no-deps

Although TensorFlow no longer supports Windows, PyTorch currently still provides native support.

Most students use either mac or windows as their first development platform when they start learning.

As a framework suitable for beginners, it seems unreasonable that Keras_hub is not natively supported on the Windows platform that beginners prefer.

I don't think tf.data is a very urgent issue. After all, tensorflow-cpu can be installed on all platforms.

But tf-text is not. A naive approach would be to convert the dependencies of tfds into those of huggingface. This would reduce the workload significantly.

pass-lin avatar Apr 15 '25 04:04 pass-lin

Instead of moving away from tf.data, a much easier goal is to make keras-hub work well with tensorflow-cpu. tensorflow-cpu should not introduce conflicts with any parts of jax/torch/cuda generally.

Unfortunately, overriding tensorflow-text's dependency on tensorflow with tensorflow-cpu leads to an error today. My guess is this is best fixed with a new release of tensorflow-text, but I'm posting here since the tensorflow-text repo does not appear to have a motivated maintainer today.

echo 'tensorflow; sys_platform == "never"' > override.txt
export KERAS_BACKEND=jax

UV_OVERRIDE=override.txt uv tool run \
  --isolated --python 3.11 \
  --with keras-hub --with jax[cuda12] \
  --with tensorflow-cpu --with tensorflow-text -- \
  python -c 'import sys; print(sys.executable); import tensorflow_text; import keras_hub; keras_hub.models.ImageSegmenter.from_preset("sam_huge_sa1b")'

This produces for me:

/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/bin/python
2025-10-04 09:20:06.759049: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/tensorflow_text/__init__.py", line 20, in <module>
    from tensorflow_text.core.pybinds import tflite_registrar
ImportError: /home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/tensorflow_text/core/pybinds/tflite_registrar.so: undefined symbol: _ZN4absl12lts_2023080216raw_log_internal21internal_log_functionB5cxx11E

If I remove the import tensorflow_text snippet then keras-hub swallows the original exception and gives a much different (and bigger) one

Error from keras_hub

Traceback (most recent call last):
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/ops/operation.py", line 255, in from_config
    return cls(**config)
           ^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/layers/preprocessing/image_converter.py", line 216, in __init__
    super().__init__(**kwargs)
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/layers/preprocessing/preprocessing_layer.py", line 10, in __init__
    assert_tf_libs_installed(self.__class__.__name__)
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/utils/tensor_utils.py", line 276, in assert_tf_libs_installed
    raise ImportError(
ImportError: SAMImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install

If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors.

KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/saving/serialization_lib.py", line 733, in deserialize_keras_object
    instance = cls.from_config(inner_config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/ops/operation.py", line 257, in from_config
    raise TypeError(
TypeError: Error when deserializing class 'SAMImageConverter' using config={'name': 'sam_image_converter', 'trainable': True, 'dtype': 'float32', 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}.

Exception encountered: SAMImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install

If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors.

KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/saving/serialization_lib.py", line 733, in deserialize_keras_object
    instance = cls.from_config(inner_config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/models/preprocessor.py", line 122, in from_config
    config["image_converter"] = keras.layers.deserialize(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/layers/__init__.py", line 243, in deserialize
    obj = serialization_lib.deserialize_keras_object(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/saving/serialization_lib.py", line 735, in deserialize_keras_object
    raise TypeError(
TypeError: <class 'keras_hub.src.models.sam.sam_image_converter.SAMImageConverter'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method.

config={'module': 'keras_hub.src.models.sam.sam_image_converter', 'class_name': 'SAMImageConverter', 'config': {'name': 'sam_image_converter', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}, 'registered_name': 'keras_hub>SAMImageConverter'}.

Exception encountered: Error when deserializing class 'SAMImageConverter' using config={'name': 'sam_image_converter', 'trainable': True, 'dtype': 'float32', 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}.

Exception encountered: SAMImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install

If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors.

KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/saving/serialization_lib.py", line 733, in deserialize_keras_object
    instance = cls.from_config(inner_config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/models/task.py", line 119, in from_config
    config["preprocessor"] = keras.layers.deserialize(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/layers/__init__.py", line 243, in deserialize
    obj = serialization_lib.deserialize_keras_object(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/saving/serialization_lib.py", line 735, in deserialize_keras_object
    raise TypeError(
TypeError: <class 'keras_hub.src.models.sam.sam_image_segmenter_preprocessor.SAMImageSegmenterPreprocessor'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method.

config={'module': 'keras_hub.src.models.sam.sam_image_segmenter_preprocessor', 'class_name': 'SAMImageSegmenterPreprocessor', 'config': {'name': 'sam_image_segmenter_preprocessor', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_converter': {'module': 'keras_hub.src.models.sam.sam_image_converter', 'class_name': 'SAMImageConverter', 'config': {'name': 'sam_image_converter', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}, 'registered_name': 'keras_hub>SAMImageConverter'}, 'config_file': 'preprocessor.json'}, 'registered_name': 'keras_hub>SAMImageSegmenterPreprocessor'}.

Exception encountered: <class 'keras_hub.src.models.sam.sam_image_converter.SAMImageConverter'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method.

config={'module': 'keras_hub.src.models.sam.sam_image_converter', 'class_name': 'SAMImageConverter', 'config': {'name': 'sam_image_converter', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}, 'registered_name': 'keras_hub>SAMImageConverter'}.

Exception encountered: Error when deserializing class 'SAMImageConverter' using config={'name': 'sam_image_converter', 'trainable': True, 'dtype': 'float32', 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}.

Exception encountered: SAMImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install

If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors.

KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/models/task.py", line 198, in from_preset
    return loader.load_task(cls, load_weights, load_task_weights, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/utils/preset_utils.py", line 695, in load_task
    task = self._load_serialized_object(task_config, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras_hub/src/utils/preset_utils.py", line 734, in _load_serialized_object
    return keras.saving.deserialize_keras_object(config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tomasz/.cache/R/reticulate/uv/cache/archive-v0/uyhIrDP5u0hZIzIXEAUrk/lib/python3.11/site-packages/keras/src/saving/serialization_lib.py", line 735, in deserialize_keras_object
    raise TypeError(
TypeError: <class 'keras_hub.src.models.sam.sam_image_segmenter.SAMImageSegmenter'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method.

config={'module': 'keras_hub.src.models.sam.sam_image_segmenter', 'class_name': 'SAMImageSegmenter', 'config': {'backbone': <SAMBackbone name=sam_backbone, built=True>, 'preprocessor': {'module': 'keras_hub.src.models.sam.sam_image_segmenter_preprocessor', 'class_name': 'SAMImageSegmenterPreprocessor', 'config': {'name': 'sam_image_segmenter_preprocessor', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_converter': {'module': 'keras_hub.src.models.sam.sam_image_converter', 'class_name': 'SAMImageConverter', 'config': {'name': 'sam_image_converter', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}, 'registered_name': 'keras_hub>SAMImageConverter'}, 'config_file': 'preprocessor.json'}, 'registered_name': 'keras_hub>SAMImageSegmenterPreprocessor'}, 'name': 'sam_image_segmenter'}, 'registered_name': 'keras_hub>SAMImageSegmenter'}.

Exception encountered: <class 'keras_hub.src.models.sam.sam_image_segmenter_preprocessor.SAMImageSegmenterPreprocessor'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method.

config={'module': 'keras_hub.src.models.sam.sam_image_segmenter_preprocessor', 'class_name': 'SAMImageSegmenterPreprocessor', 'config': {'name': 'sam_image_segmenter_preprocessor', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_converter': {'module': 'keras_hub.src.models.sam.sam_image_converter', 'class_name': 'SAMImageConverter', 'config': {'name': 'sam_image_converter', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}, 'registered_name': 'keras_hub>SAMImageConverter'}, 'config_file': 'preprocessor.json'}, 'registered_name': 'keras_hub>SAMImageSegmenterPreprocessor'}.

Exception encountered: <class 'keras_hub.src.models.sam.sam_image_converter.SAMImageConverter'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method.

config={'module': 'keras_hub.src.models.sam.sam_image_converter', 'class_name': 'SAMImageConverter', 'config': {'name': 'sam_image_converter', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}, 'registered_name': 'keras_hub>SAMImageConverter'}.

Exception encountered: Error when deserializing class 'SAMImageConverter' using config={'name': 'sam_image_converter', 'trainable': True, 'dtype': 'float32', 'image_size': [1024, 1024], 'scale': 0.00392156862745098, 'offset': None, 'interpolation': 'bilinear', 'crop_to_aspect_ratio': True}.

Exception encountered: SAMImageConverter requires `tensorflow` and `tensorflow-text` for text processing. Run `pip install tensorflow-text` to install both packages or visit https://www.tensorflow.org/install

If `tensorflow-text` is already installed, try importing it in a clean python session. Your installation may have errors.

KerasHub uses `tf.data` and `tensorflow-text` to preprocess text on all Keras backends. If you are running on Jax or Torch, this installation does not need GPU support.

t-kalinowski avatar Oct 04 '25 13:10 t-kalinowski

I'm guessing the current incompatibility between tensorflow-text (ergo, keras-hub) and tensorflow-cpu is a known issue; I just noticed that tensorflow-cpu is pinned to ~=2.18.1 in keras-team/keras CI, which doesn't have the same issues.

t-kalinowski avatar Oct 05 '25 21:10 t-kalinowski