始める無料で始める

最も人気のあるテキストから画像生成モデルを見つける

Hugging Face Hub で、CompVis のテキストから画像生成用 Stable Diffusion モデルの中から最も人気のあるものを絞り込んで見つけ、読み込んでみましょう。

Photo of a labrador chasing a ball

Hugging Face Hub API(api)と、diffusers ライブラリの StableDiffusionPipeline モジュールはすでに読み込まれています。Stable Diffusion モデルでは、たとえば「a black labrador chasing a tennis ball(黒いラブラドールがテニスボールを追いかけている)」のように、任意のプロンプトから画像を生成できます。

この演習はコースの一部です

Hugging Face で学ぶマルチモーダルモデル

コースを見る

演習の手順

  • text-to-image タスク向けのモデルのみを使用します。
  • diffusers ライブラリの StableDiffusionPipeline クラスで読み込めるよう、適切なタグを指定します。
  • 結果は "likes" の数で並べ替えます。
  • models から、ID を使って最も人気のあるモデルを読み込みます。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

models = api.list_models(
    # Filter for text-to-image tasks
    task="____",
    author="CompVis",
    # Filter for models that can be loaded by the diffusers library
    tags="diffusers:____",
    # Sort according to the most popular
    sort="____"
)

models = list(models)

# Load the most popular model from models
pipe = StableDiffusionPipeline.from_pretrained(models[0].____)
コードを編集して実行