{"id":7338,"library":"keras-hub","title":"Keras Hub (Legacy)","description":"The `keras-hub` library, version 0.27.1, was a wrapper released in 2019 to provide a convenient Keras API for loading models from TensorFlow Hub. It is now considered abandoned and is not compatible with modern Keras (3.x) or recent TensorFlow versions due to significant API changes and Python version requirements. Users should directly use the `tensorflow_hub` library with modern Keras installations.","status":"abandoned","version":"0.27.1","language":"en","source_language":"en","source_url":"https://github.com/tensorflow/hub","tags":["keras","tensorflow","machine-learning","pretrained-models","hub","legacy","abandoned"],"install":[{"cmd":"pip install keras-hub","lang":"bash","label":"Install `keras-hub` (legacy)"}],"dependencies":[{"reason":"Core functionality wrapped by this library; requires an old, compatible version of tensorflow-hub and TensorFlow.","package":"tensorflow-hub","optional":false}],"imports":[{"note":"This was the primary import for the `keras-hub` wrapper. With modern Keras, you should import `KerasLayer` directly from `tensorflow_hub`.","symbol":"KerasLayer","correct":"from keras_hub import KerasLayer"},{"note":"This was used for creating feature columns from Hub modules. Direct use of `tensorflow_hub.feature_column.url_to_feature_column` is now recommended.","symbol":"url_to_feature_column","correct":"from keras_hub import url_to_feature_column"}],"quickstart":{"code":"import keras\nfrom keras_hub import KerasLayer\nimport tensorflow as tf # Required for data types and model building\n\n# This code block demonstrates the intended usage of keras-hub (0.27.1).\n# It is NOT runnable with modern Python (3.8+) or Keras 3.x without\n# specific, older TensorFlow/Keras versions and their corresponding\n# Python environment. \n# For a runnable example using modern Keras, see the 'warnings' section below.\n\ntry:\n    # Example: Use a pre-trained image feature vector module from TensorFlow Hub\n    # Note: The actual module URL would need to be valid for the TensorFlow Hub\n    # version compatible with keras-hub 0.27.1 (circa 2019).\n    feature_extractor_url = \"https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4\"\n    \n    # Create a KerasLayer from the Hub module\n    # keras-hub's KerasLayer defaults trainable=False\n    hub_layer = KerasLayer(feature_extractor_url, input_shape=(224, 224, 3))\n\n    # Build a simple Keras model\n    model = keras.Sequential([\n        keras.Input(shape=(224, 224, 3)),\n        hub_layer,\n        keras.layers.Dense(2, activation='softmax')\n    ])\n\n    model.summary()\n    print(f\"KerasLayer trainable: {hub_layer.trainable}\")\n\nexcept ImportError:\n    print(\"\\n'keras-hub' or its dependencies not found. This library is abandoned.\")\n    print(\"Install with 'pip install keras-hub' requires older Python/TensorFlow environment.\")\nexcept Exception as e:\n    print(f\"\\nAn error occurred during keras-hub usage (likely due to environment incompatibility): {e}\")\n\n# --- Modern Keras/TensorFlow Hub approach (RECOMMENDED) ---\n# For current environments, use tensorflow_hub directly:\n# import tensorflow_hub as hub\n# import keras\n# \n# feature_extractor_url_modern = \"https://tfhub.dev/google/efficientnet/b0/feature-vector/1\" # Example modern URL\n# hub_layer_modern = hub.KerasLayer(feature_extractor_url_modern, trainable=False, input_shape=(224, 224, 3))\n# model_modern = keras.Sequential([\n#     keras.Input(shape=(224, 224, 3)),\n#     hub_layer_modern,\n#     keras.layers.Dense(2, activation='softmax')\n# ])\n# model_modern.summary()\n","lang":"python","description":"This example illustrates how `KerasLayer` from `keras-hub` was intended to be used to integrate TensorFlow Hub modules into Keras models. **Please note: This code block is for historical context and is not runnable with Python 3.8+ or Keras 3.x due to the library's abandonment and dependency incompatibilities.** For a working example with modern Keras, refer to the 'warnings' section below which uses `tensorflow_hub` directly."},"warnings":[{"fix":"Do not use `keras-hub` for new projects. Instead, directly import and use `KerasLayer` from `tensorflow_hub` for modern Keras installations. Ensure `tensorflow-hub` is installed: `pip install tensorflow-hub`.","message":"The `keras-hub` library (0.27.1) is incompatible with Python 3.8+ and modern Keras (3.x) / TensorFlow (2.x) due to outdated dependencies and significant API changes. Attempting to use it will likely result in `ModuleNotFoundError`, `AttributeError`, or runtime crashes.","severity":"breaking","affected_versions":"0.27.1"},{"fix":"Migrate to using `tensorflow_hub` directly. The `tensorflow_hub.KerasLayer` provides the same core functionality and is actively maintained. For Keras 3.x and TensorFlow 2.x, the usage pattern is nearly identical to what `keras-hub` offered, but without the compatibility issues.","message":"The `keras-hub` package is abandoned, with its last release in 2019. It served as a thin wrapper for `tensorflow_hub.KerasLayer` and is no longer maintained or necessary with current Keras/TensorFlow versions.","severity":"deprecated","affected_versions":"0.27.1"},{"fix":"Always explicitly set the `trainable` argument when using `tensorflow_hub.KerasLayer` to ensure desired behavior. For example, `hub.KerasLayer(module_url, trainable=False, ...)`.","message":"While `keras-hub.KerasLayer` defaulted `trainable=False`, `tensorflow_hub.KerasLayer` often defaults `trainable=True` for many feature vector modules. This subtle difference can lead to unexpected model training behavior if the `trainable` argument is not explicitly set.","severity":"gotcha","affected_versions":"0.27.1 (when comparing to `tensorflow_hub` behavior)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"For modern Keras, use `tensorflow_hub` directly. Ensure `pip install tensorflow-hub` is run and then use `from tensorflow_hub import KerasLayer`. Do not attempt to install `keras-hub` for new projects.","cause":"The `keras-hub` package is not installed, or the current Python environment does not have access to it. This library is largely obsolete.","error":"ModuleNotFoundError: No module named 'keras_hub'"},{"fix":"The `keras-hub` library is incompatible with current versions. Remove `keras-hub` from your project dependencies. Instead, use `tensorflow_hub.KerasLayer` directly, ensuring your `tensorflow-hub` and `keras` installations are up-to-date and compatible with each other.","cause":"Attempting to use `keras-hub` (which relies on very old TensorFlow/Keras APIs) with a modern Keras 3.x or TensorFlow 2.x installation, leading to severe API incompatibility.","error":"AttributeError: module 'tensorflow.keras.layers' has no attribute 'Dense' (or similar Keras/TF API mismatch errors)"}]}