Reusable SavedModel API กำหนดวิธีทั่วไปในการโหลด SavedModel กลับเข้าไปในโปรแกรม Python และนำมาใช้ใหม่โดยเป็นส่วนหนึ่งของโมเดล TensorFlow ที่ใหญ่กว่า
การใช้งานขั้นพื้นฐาน:
obj=hub.load("path/to/model")# That's tf.saved_model.load() after download.outputs=obj(inputs,training=False)# Invokes the tf.function obj.__call__.
สำหรับผู้ใช้ Keras คลาส hub.KerasLayer อาศัย API นี้เพื่อรวม Reusable SavedModel เป็น Keras Layer (ป้องกันผู้ใช้ Keras จากรายละเอียด) โดยมีอินพุตและเอาต์พุตตาม API เฉพาะงานที่แสดงด้านล่าง
[null,null,["อัปเดตล่าสุด 2025-01-04 UTC"],[],[],null,["# Common SavedModel APIs for TF Hub\n\n\u003cbr /\u003e\n\nIntroduction\n------------\n\n[TensorFlow Hub](https://tfhub.dev) hosts models for a variety of tasks. Models\nfor the same task are encouraged to implement a common API so that model\nconsumers can easily exchange them without modifying the code that uses them,\neven if they come from different publishers.\n\nThe goal is to make exchanging different models for the same task as simple as\nswitching a string-valued hyperparameter. With that, model consumers can easily\nfind the best one for their problem.\n\nThis directory collects specifications of common APIs for models in the\n[TF2 SavedModel format](../tf2_saved_model). (It replaces the\n[Common Signatures](../common_signatures/index) for the now-deprecated\n[TF1 Hub format](../tf1_hub_module).)\n\nReusable SavedModel: the common foundation\n------------------------------------------\n\nThe [Reusable SavedModel API](../reusable_saved_models) defines general\nconventions how to load a SavedModel back into a Python program and reuse it as\npart of a bigger TensorFlow model.\n\nBasic usage: \n\n obj = hub.load(\"path/to/model\") # That's tf.saved_model.load() after download.\n outputs = obj(inputs, training=False) # Invokes the tf.function obj.__call__.\n\n| **Key Point:** This uses the object-based interface to restored SavedModels that was added in TensorFlow 2, not the SavedModel signatures for serving.\n\nFor Keras users, the [`hub.KerasLayer`](https://www.tensorflow.org/hub/api_docs/python/hub/KerasLayer) class relies on this API to wrap the\nReusable SavedModel as a Keras Layer (shielding Keras users from its details),\nwith inputs and outputs according to the task-specific APIs listed below.\n\nTask-specific APIs\n------------------\n\nThese refine the [Reusable SavedModel API](../reusable_saved_models) with\nconventions for particular ML tasks and types of data.\n\n- [Image tasks](/hub/common_saved_model_apis/images)\n- [Text tasks](/hub/common_saved_model_apis/text)"]]