TensorFlow Hub 库概述
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 tensorflow_hub
库,您能够以最少的代码量在 TensorFlow 程序中下载并重用经过训练的模型。加载训练的模型的主要方式是使用 hub.KerasLayer
API。
import tensorflow_hub as hub
embed = hub.KerasLayer("https://tfhub.dev/google/nnlm-en-dim128/2")
embeddings = embed(["A long sentence.", "single-word", "http://example.com"])
print(embeddings.shape, embeddings.dtype)
设置下载的缓存位置。
默认情况下,tensorflow_hub
使用系统范围的临时目录来缓存下载和未压缩的模型。有关使用其他可能更持久位置的选项,请参阅缓存。
API 稳定性
尽管我们希望避免重大变更,但此项目仍在积极开发中,尚不能保证具有一个稳定的 API 或模型格式。
公平性
与所有机器学习一样,公平性是一个重要考量因素。许多预训练的模型都是基于大型数据集训练的。在重用任何模型时,请务必牢记该模型基于哪些数据进行了训练(以及其中是否存在任何现有偏差)与这些数据如何影响您的使用。
安全性
由于它们包含任意 TensorFlow 计算图,因此可以将模型视为程序。安全地使用 TensorFlow 描述了从不受信任的来源引用模型带来的安全隐患。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-01-11。
[null,null,["最后更新时间 (UTC):2024-01-11。"],[],[],null,["# TensorFlow Hub Library Overview\n\n\u003cbr /\u003e\n\nThe [`tensorflow_hub`](https://github.com/tensorflow/hub) library lets you\ndownload and reuse trained models in your TensorFlow program with a minimum\namount of code. The main way to load a trained model is using the\n[`hub.KerasLayer`](https://www.tensorflow.org/hub/api_docs/python/hub/KerasLayer) API. \n\n import tensorflow_hub as hub\n\n embed = hub.KerasLayer(\"https://tfhub.dev/google/nnlm-en-dim128/2\")\n embeddings = embed([\"A long sentence.\", \"single-word\", \"http://example.com\"])\n print(embeddings.shape, embeddings.dtype)\n\n**Note:** This documentation uses TFhub.dev URL handles in examples. See more\ninformation regarding other valid handle types [here](/hub/tf2_saved_model#model_handles).\n\nSetting the cache location for downloads.\n-----------------------------------------\n\nBy default, `tensorflow_hub` uses a system-wide, temporary directory to cache\ndownloaded and uncompressed models. See [Caching](/hub/caching) for options to use\nother, possibly more persistent locations.\n\nAPI stability\n-------------\n\nAlthough we hope to prevent breaking changes, this project is still under active\ndevelopment and is not yet guaranteed to have a stable API or model format.\n\nFairness\n--------\n\nAs in all of machine learning, [fairness](http://ml-fairness.com) is an\n[important](https://research.googleblog.com/2016/10/equality-of-opportunity-in-machine.html)\nconsideration. Many pre-trained models are trained on large datasets. When\nreusing any model, it's important to be mindful of what data the model was\ntrained on (and whether there are any existing biases there), and how these\nmight impact your use of it.\n\nSecurity\n--------\n\nSince they contain arbitrary TensorFlow graphs, models can be thought of as\nprograms.\n[Using TensorFlow Securely](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md)\ndescribes the security implications of referencing a model from an untrusted\nsource.\n\nNext Steps\n----------\n\n- [Use the library](/hub/tf2_saved_model)\n- [Reusable SavedModels](/hub/reusable_saved_models)"]]