Hub documentation

TF-Keras(旧版)

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

TF-Keras(旧版)

tf-keras 是 Keras 2.x 版本的名称。它现在作为独立的 GitHub 仓库托管在此处。尽管它是一个遗留框架,但 Hub 上仍托管着4.5k+ 个模型。这些模型可以使用 huggingface_hub 库进行加载。您必须在机器上安装 tf-keras 或 keras<3.x。

如果您对 Keras 3.x 支持感兴趣,请查看此指南。

安装完成后,您只需使用 from_pretrained_keras 方法即可从 Hub 加载模型。有关 from_pretrained_keras 的更多信息,请参见此处。

from huggingface_hub import from_pretrained_keras

model = from_pretrained_keras("keras-io/mobile-vit-xxs")
prediction = model.predict(image)
prediction = tf.squeeze(tf.round(prediction))
print(f'The image is a {classes[(np.argmax(prediction))]}!')

<CopyLLMTxtMenu containerStyle="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"></CopyLLMTxtMenu>

# The image is a sunflower!

您还可以在 Hub 上托管您的 tf-keras 模型。但请注意,tf-keras 是一个遗留框架。为了触达最多的用户,我们建议使用 Keras 3.x 创建模型,并按照上述方法以原生方式共享。有关上传 tf-keras 模型的更多详细信息,请参阅 push_to_hub_keras 文档。

from huggingface_hub import push_to_hub_keras

push_to_hub_keras(model,
    "your-username/your-model-name",
    "your-tensorboard-log-directory",
    tags = ["object-detection", "some_other_tag"],
    **model_save_kwargs,
)

其他资源

Update on GitHub