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,500 以上のモデル がホストされています。これらのモデルは 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!

tf-kerasモデルをHubにホストすることもできます。ただし、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