{"id":3292,"library":"tensorflow-hub","title":"TensorFlow Hub","description":"TensorFlow Hub (TF-Hub) is a library designed to promote the publication, discovery, and consumption of reusable parts of machine learning models. It provides a repository of pre-trained model components, facilitating transfer learning and accelerating development in various domains like image classification, text embedding, and object detection. The library is actively maintained, with its latest version being 0.16.1, and typically follows a regular release cadence to align with TensorFlow's ecosystem.","status":"active","version":"0.16.1","language":"en","source_language":"en","source_url":"https://github.com/tensorflow/hub","tags":["tensorflow","machine-learning","transfer-learning","deep-learning","AI","models"],"install":[{"cmd":"pip install tensorflow-hub","lang":"bash","label":"PyPI"},{"cmd":"conda install -c conda-forge tensorflow-hub","lang":"bash","label":"Conda"}],"dependencies":[{"reason":"Required for Keras 2 integration and functionality introduced in v0.16.0 and v0.16.1.","package":"tf-keras","optional":false},{"reason":"Required for serialization and deserialization of data, specifically version >=3.19.6 since v0.13.0.","package":"protobuf","optional":false},{"reason":"Fundamental package for numerical computing with Python, version >=1.12.0.","package":"numpy","optional":false},{"reason":"Minimum Python version required is 3.9+ since v0.15.0.","package":"python","optional":false}],"imports":[{"note":"The standard and recommended import alias for brevity and convention.","symbol":"tensorflow_hub","correct":"import tensorflow_hub as hub"}],"quickstart":{"code":"import tensorflow as tf\nimport tensorflow_hub as hub\n\n# Load a pre-trained text embedding model from TensorFlow Hub\n# This model generates 128-dimensional embeddings for text inputs.\nmodel_url = \"https://tfhub.dev/google/nnlm-en-dim128/2\"\nembed = hub.KerasLayer(model_url, input_shape=[], dtype=tf.string, trainable=False)\n\n# Example usage: Generate embeddings for a list of sentences\nsentences = [\n    \"Hello TensorFlow Hub!\",\n    \"This is a test sentence for text embedding.\",\n    \"Machine learning is fun.\"\n]\n\nembeddings = embed(tf.constant(sentences))\n\nprint(f\"Input sentences: {sentences}\")\nprint(f\"Generated embeddings shape: {embeddings.shape}\")\nprint(f\"First embedding (first 5 values): {embeddings[0, :5].numpy()}\")\n\n# You can then use these embeddings as input to another Keras layer\n# for tasks like classification.\nclassifier_model = tf.keras.Sequential([\n    embed,\n    tf.keras.layers.Dense(16, activation='relu'),\n    tf.keras.layers.Dense(1, activation='sigmoid')\n])\nclassifier_model.summary()","lang":"python","description":"This quickstart demonstrates how to load a pre-trained text embedding model from TensorFlow Hub using `hub.KerasLayer` and generate embeddings for sample text. It also shows how to integrate this `hub.KerasLayer` into a larger Keras Sequential model for transfer learning tasks like text classification."},"warnings":[{"fix":"Ensure `tf-keras>=2.14.1` is installed in your environment: `pip install tf-keras`.","message":"Versions 0.16.0 and 0.16.1 enforce the use of Keras 2 by requiring `tf-keras` to be installed. Older versions might have used a bundled Keras or a different Keras installation strategy.","severity":"breaking","affected_versions":"0.16.0, 0.16.1"},{"fix":"Migrate your code to use TensorFlow 2.x APIs, primarily `hub.KerasLayer` and SavedModels for model export/import.","message":"Deprecated TensorFlow 1 (TF1) APIs, such as `LatestModuleExporter` and `register_module_for_export`, were removed in v0.16.0. Code relying on these TF1 APIs will break.","severity":"breaking","affected_versions":">=0.16.0"},{"fix":"Upgrade your Python environment to Python 3.9 or a later compatible version.","message":"Starting with version 0.15.0, TensorFlow Hub requires Python 3.9 or higher. Previous versions supported older Python versions (e.g., 3.7+ from v0.13.0).","severity":"breaking","affected_versions":">=0.15.0"},{"fix":"Refactor your code to implement these functionalities using `hub.KerasLayer` and standard TensorFlow/Keras operations, or look for alternative tools/models on tfhub.dev (Kaggle Models).","message":"The `make_image_classifier` and `make_nearest_neighbour_index` tools were removed in version 0.14.0.","severity":"breaking","affected_versions":">=0.14.0"},{"fix":"Use Kaggle Models counterparts for `tfhub.dev` links. If you were using one of the unmigrated models, you must find an alternative or retrain your own model. Check official TensorFlow Hub documentation for the list of deleted models and migration FAQs.","message":"As of November 15, 2023, `tfhub.dev` model links redirect to Kaggle Models. Crucially, unmigrated models (a specific list, including some iNaturalist and NVIDIA models) were permanently deleted on March 18, 2024, and are no longer retrievable via their old `tfhub.dev` handles.","severity":"gotcha","affected_versions":"All versions (affects model availability)"},{"fix":"Always prefer `hub.KerasLayer` for loading models in TensorFlow 2.x environments. Avoid `hub.Module` for new development and migrate existing code where possible.","message":"The `hub.Module` class, part of the TensorFlow 1 API, is deprecated and has known compatibility issues with newer TensorFlow 2.x versions, especially concerning `tf.compat.v1.ragged.placeholder()` with TF2.3.","severity":"gotcha","affected_versions":"All versions when used with TF2.x"},{"fix":"Pin `tensorflow-hub` to a specific version in your `requirements.txt` or `pyproject.toml` to ensure consistent behavior across deployments. Regularly check release notes for upcoming changes.","message":"The TensorFlow Hub API is under active development and is not yet guaranteed to have a stable API or model format, meaning future updates might introduce breaking changes even outside of major version bumps.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}