ความเข้ากันได้ของรุ่นสำหรับ TF1/TF2
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
TF Hub นำเสนอชิ้นส่วนโมเดลที่ใช้ซ้ำได้ซึ่งสามารถโหลดกลับ สร้างต่อ และอาจฝึกใหม่ในโปรแกรม TensorFlow สิ่งเหล่านี้มาในสองรูปแบบที่แตกต่างกัน:
สามารถดูรูปแบบโมเดลได้ในหน้าโมเดลบน tfhub.dev การโหลด/การอนุมาน โมเดล การปรับแต่งอย่างละเอียด หรือ การสร้างโมเดล อาจไม่รองรับใน TF1/2 ทั้งนี้ขึ้นอยู่กับรูปแบบของโมเดล
ความเข้ากันได้ของรูปแบบ TF1 Hub
การดำเนินการ | โหมดรองรับ TF1/ TF1 ใน TF2 [1] | ทีเอฟ2 |
กำลังโหลด/อนุมาน | รองรับอย่างเต็มที่ ( คู่มือการโหลดรูปแบบ TF1 Hub ฉบับสมบูรณ์ ) m = hub.Module(handle)
outputs = m(inputs) | ขอแนะนำให้ใช้ hub.load อย่างใดอย่างหนึ่งm = hub.load(handle)
outputs = m.signatures["sig"](inputs) หรือ hub.KerasLayer m = hub.KerasLayer(handle, signature="sig")
outputs = m(inputs) |
การปรับแต่งแบบละเอียด | รองรับอย่างเต็มที่ ( คู่มือการปรับแต่งรูปแบบ TF1 Hub ที่สมบูรณ์ ) m = hub.Module(handle,
trainable=True,
tags=["train"]*is_training)
outputs = m(inputs) หมายเหตุ: โมดูลที่ไม่ต้องการกราฟรถไฟแยกต่างหากจะไม่มีแท็กรถไฟ | ไม่รองรับ |
การสร้าง | รองรับอย่างเต็มที่ (ดู คู่มือการสร้างรูปแบบ TF1 Hub ฉบับสมบูรณ์ )
หมายเหตุ: รูปแบบ TF1 Hub มุ่งเน้นไปที่ TF1 และรองรับเพียงบางส่วนใน TF2 เท่านั้น พิจารณาสร้าง TF2 SavedModel | ไม่รองรับ |
ความเข้ากันได้ของ TF2 SavedModel
ไม่รองรับก่อน TF1.15
การดำเนินการ | โหมดรองรับ TF1.15/ TF1 ใน TF2 [1] | ทีเอฟ2 |
กำลังโหลด/อนุมาน | ใช้ hub.load อย่างใดอย่างหนึ่งm = hub.load(handle)
outputs = m(inputs) หรือ hub.KerasLayer m = hub.KerasLayer(handle)
outputs = m(inputs) | รองรับอย่างเต็มที่ ( คู่มือการโหลด TF2 SavedModel ฉบับสมบูรณ์ ) ใช้ hub.load อย่างใดอย่างหนึ่งm = hub.load(handle)
outputs = m(inputs) หรือ hub.KerasLayer m = hub.KerasLayer(handle)
outputs = m(inputs) |
การปรับแต่งแบบละเอียด | รองรับฮับ KerasLayer ที่ใช้ใน tf.keras.Model เมื่อฝึกฝนกับ Model.fit() หรือฝึกฝนใน Estimator ซึ่ง model_fn ล้อม Model ตาม คำแนะนำ model_fn ที่กำหนดเอง
หมายเหตุ: hub.KerasLayer ไม่ได้ เติมคอลเลกชันกราฟเหมือนที่ tf.compat.v1.layers หรือ hub.Module API แบบเก่าทำ | รองรับอย่างเต็มที่ ( คู่มือการปรับแต่ง TF2 SavedModel ฉบับสมบูรณ์ ) ใช้ hub.load อย่างใดอย่างหนึ่ง:m = hub.load(handle)
outputs = m(inputs, training=is_training) หรือฮับ KerasLayer: m = hub.KerasLayer(handle, trainable=True)
outputs = m(inputs) |
การสร้าง | TF2 API tf.saved_model.save() สามารถเรียกได้จากภายในโหมดที่เข้ากันได้ | รองรับอย่างเต็มที่ (ดู คู่มือการสร้าง TF2 SavedModel ฉบับสมบูรณ์ ) |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],[],null,["# Model compatibility for TF1/TF2\n\n\u003cbr /\u003e\n\nTF Hub model formats\n--------------------\n\nTF Hub offers reusable model pieces that can be loaded back, built upon, and\npossibly be retrained in a TensorFlow program. These come in two different\nformats:\n\n- The custom [TF1 Hub format](https://www.tensorflow.org/hub/tf1_hub_module) . Its main intended use is in TF1 (or TF1 compatibility mode in TF2) via its [hub.Module API](https://www.tensorflow.org/hub/api_docs/python/hub/Module). Full compatibility details [below](#compatibility_of_hubmodule).\n- The native [TF2 SavedModel](https://www.tensorflow.org/hub/tf2_saved_model) format. Its main intended use is in TF2 via the [hub.load](https://www.tensorflow.org/hub/api_docs/python/hub/load) and [hub.KerasLayer](https://www.tensorflow.org/hub/api_docs/python/hub/KerasLayer) APIs. Full compatibility details [below](#compatibility_of_tf2_savedmodel).\n\nThe model format can be found on the model page on\n[tfhub.dev](https://tfhub.dev). Model **loading/inference** , **fine-tuning** or\n**creation** might not be supported in TF1/2 based on the model formats.\n\nCompatibility of the TF1 Hub format\n-----------------------------------\n\n|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Operation | TF1/ TF1 compat mode in TF2 [\\[1\\]](#compatfootnote) | TF2 |\n| Loading / Inference | Fully supported ([complete TF1 Hub format loading guide](https://www.tensorflow.org/hub/tf1_hub_module#using_a_module)) ``` m = hub.Module(handle) outputs = m(inputs) ``` | It's recommended to use either hub.load ``` m = hub.load(handle) outputs = m.signatures[\"sig\"](inputs) ``` or hub.KerasLayer ``` m = hub.KerasLayer(handle, signature=\"sig\") outputs = m(inputs) ``` |\n| Fine-tuning | Fully supported ([complete TF1 Hub format fine-tuning guide](https://www.tensorflow.org/hub/tf1_hub_module#for_consumers)) ``` m = hub.Module(handle, trainable=True, tags=[\"train\"]*is_training) outputs = m(inputs) ``` Note: modules that don't need a separate train graph don't have a train tag. | Not supported |\n| Creation | Fully supported (see [complete TF1 Hub format creation guide](https://www.tensorflow.org/hub/tf1_hub_module#general_approach)) Note: The TF1 Hub format is geared towards TF1 and is only partially supported in TF2. Consider creating a TF2 SavedModel. | Not supported |\n\nCompatibility of TF2 SavedModel\n-------------------------------\n\nNot supported before TF1.15.\n\n|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Operation | TF1.15/ TF1 compat mode in TF2 [\\[1\\]](#compatfootnote) | TF2 |\n| Loading / Inference | Use either hub.load ``` m = hub.load(handle) outputs = m(inputs) ``` or hub.KerasLayer ``` m = hub.KerasLayer(handle) outputs = m(inputs) ``` | Fully supported ([complete TF2 SavedModel loading guide](https://www.tensorflow.org/hub/tf2_saved_model#using_savedmodels_from_tf_hub)). Use either hub.load ``` m = hub.load(handle) outputs = m(inputs) ``` or hub.KerasLayer ``` m = hub.KerasLayer(handle) outputs = m(inputs) ``` |\n| Fine-tuning | Supported for a hub.KerasLayer used in tf.keras.Model when trained with Model.fit() or trained in an Estimator whose model_fn wraps the Model per the [custom model_fn guide](https://www.tensorflow.org/guide/migrate#using_a_custom_model_fn). Note: hub.KerasLayer does not fill in graph collections like the old tf.compat.v1.layers or hub.Module APIs did. | Fully supported ([complete TF2 SavedModel fine-tuning guide](https://www.tensorflow.org/hub/tf2_saved_model#for_savedmodel_consumers)). Use either hub.load: ``` m = hub.load(handle) outputs = m(inputs, training=is_training) ``` or hub.KerasLayer: ``` m = hub.KerasLayer(handle, trainable=True) outputs = m(inputs) ``` |\n| Creation | The TF2 API [tf.saved_model.save()](https://www.tensorflow.org/api_docs/python/tf/saved_model/save) can be called from within compat mode. | Fully supported (see [complete TF2 SavedModel creation guide](https://www.tensorflow.org/hub/tf2_saved_model#creating_savedmodels_for_tf_hub)) |\n\n\u003cbr /\u003e\n\n\\[1\\] \"TF1 compat mode in TF2\" refers to the combined\neffect of importing TF2 with\n`import tensorflow.compat.v1 as tf`\nand running\n`tf.disable_v2_behavior()`\nas described in the\n[TensorFlow Migration guide](https://www.tensorflow.org/guide/migrate)."]]