メむンコンテンツぞスキップ
芋出し画像

wd14-taggerの新モデルの远加方法の解説【eva02-large-tagger-v3/vit-large-tagger-v3】

     こんにちは【でんでん】です
     以前にtaggerの新モデルの远加方法に぀いお蚘事を曞きたしたが、あれからしばらく経ち、新しいモデルをSmilingWolfアニキがリリヌスしおいたので導入方法を解説しおきたす。
     氞久保存版にしたいので、これから新しいモデルがリリヌスされおも察応出来るように解説しおいきたすね

    前回の蚘事読たなくおも倧䞈倫ッス

    【新䜜taggerモデル呚りのおおたかな解説】

     ▶そんなのどうでもいい人は、目次の倧芋出しから【新䜜taggerモデルを導入する方法】にゞャンプ


    新モデルに察応する意矩

     新モデルの方が怜出できるタグの粟床が䞊がるのが基本的な利点です。

     それずbooru系タグは日々、䜿甚実態に即した統廃合が進められおいたす。そのため、昔あったタグが今はない  ずいう事がよくあるのです。䟋えばbangsタグずか
     そんな䞭、新䜜の倧型ファむンチュヌニング系モデルを䜿甚するずなるず、そのモデルは『新しいタグに即したdanbooruデヌタセットでトレヌニング』されおいる可胜性が高くなりたす。

     なので、新䜜の倧型ファむンチュヌニングモデルを䜿甚する際やそのモデルでのLoRA孊習をしたい時は、新しいモデルにしおおいた方が孊習効率が良いのでは  ずいう事になりたす。

    新モデルの探し方

     swinv2モデルの生みの芪であるSmilingWolfアニキのhugging faceのリポゞトリを監芖しおおけばOKですbooru系タグならアニキのモデルがやっぱり䞀番

     今回はwd-eva02-large-tagger-v3ずwd-vit-large-tagger-v3が立お続けおにリリヌスされおいたので、それを入れおいきたしょう。


     各モデルの性胜はモデルペヌゞの䞭に曞いおある以䞋の郚分を芋たす。

    各モデルごずの性胜の芋方

    【wd-eva02-large-tagger-v3のや぀】
    Validation results
    v1.0: P=R: threshold = 0.5296, F1 = 0.4772

    https://huggingface.co/SmilingWolf/wd-eva02-large-tagger-v3

    【wd-vit-large-tagger-v3のや぀】
    Validation results
    v1.0: P=R: threshold = 0.2606, F1 = 0.4674

    https://huggingface.co/SmilingWolf/wd-vit-large-tagger-v3

     これらのスコアは閟倀thresholdずF1スコアずいうものです。ざっくり蚀えば、どちらの数倀もより倀が倧きい方が性胜のいいモデルです。
     閟倀が高すぎるず誀ったタグ以䞊に正しいタグを芋萜ずす確率が高くなりたすが、F1スコアが高くなればバランスが取れるようになりたす。なので、珟状䞀番性胜がいいモデルはwd-eva02-large-tagger-v3になりたす。

    新モデルの実力を確認しよう

    画像

    【WD14-swin-v2-v1】
    ※い぀ものや぀
    1girl, solo, pointy ears, boots, throne, crossed legs, blonde hair, cross-laced footwear, blue eyes, braid, long hair, sitting, gloves, smile, flower, lace-up boots, white gloves, elbow gloves, looking at viewer, crown, knee boots, thigh boots, black footwear, high heels, closed mouth, twin braids, bangs, elf, very long hair, white flower, full body, breasts, cross, chair, hand on own cheek, pantyhose, head rest, high heel boots, artist name, twintails
    【wd-v1-4-moat-tagger-v2】
    ※sweinv2-v1ずの違い
    twin braids, very long hair, white flowerが抜けおいる

    1girl, pointy ears, throne, boots, solo, blonde hair, sitting, braid, gloves, long hair, crossed legs, elbow gloves, blue eyes, flower, white gloves, cross-laced footwear, looking at viewer, smile, high heels, high heel boots, knee boots, pantyhose, crown, black footwear, elf, bangs, lace-up boots, closed mouth, breasts, thigh boots, full body
    【wd-vit-large-tagger-v3】
    ※sweinv2-v1ずの違い

    bangs, chair, artist nameが抜けおいる。pillar, bodystocking, plant, column, mini crown, signature, hair between eyesが远加された
    1girl, boots, pointy ears, elbow gloves, gloves, sitting, throne, braid, crown, crossed legs, cross-laced footwear, solo, blonde hair, white gloves, looking at viewer, long hair, smile, lace-up boots, flower, high heels, blue eyes, knee boots, black footwear, twintails, high heel boots, white flower, closed mouth, elf, very long hair, pillar, pantyhose, twin braids, breasts, head rest, full body, bodystocking, cross, plant, column, thigh boots, mini crown, signature, hand on own cheek, hair between eyes
    【wd-eva02-large-tagger-v3】
    ※sweinv2-v1ずの違い
    bangs, chair, pantyhose, artist nameが抜けおいる。bodystocking, pillar, column, vines, thorns, plant, gold trim, bodysuit, mini crown, hand on own face, jewelry, cross necklace, medium breasts, elbow rest, necklaceが远加された

    1girl, boots, throne, crown, pointy ears, gloves, crossed legs, braid, blonde hair, elbow gloves, solo, long hair, bodystocking, high heel boots, sitting, knee boots, elf, blue eyes, white gloves, high heels, flower, looking at viewer, black footwear, thigh boots, smile, cross-laced footwear, cross, pillar, lace-up boots, column, vines, thorns, breasts, white flower, twin braids, plant, very long hair, gold trim, closed mouth, full body, bodysuit, mini crown, hand on own cheek, hand on own face, twintails, jewelry, head rest, cross necklace, medium breasts, elbow rest, necklace

    【タグモデル分析】

     wd-eva02-large-tagger-v3では他のモデルが芋萜ずしおいた倚数のタグを怜知出来おいる。
     bodystocking党身タむツやpillar柱, column装食的な柱, vines蔓などの柱呚りのタグもバッチリ。たた単玔なchair怅子が抜けおthorns王座が远加された点も泚目。mini crown小さな王冠、hand on own face自分の顔に手を眮いおいる、cross necklace十字架のネックレスなどの顔呚りの现かい装食やポヌズも拟えおいる。

    画像

    【WD14-swin-v2-v1】
    ※い぀ものや぀

    1girl, green eyes, solo, card, dress, bow, petals, holding, looking at viewer, blue dress, plaid bow, blush, frills, frilled dress, short sleeves, blue bow, bangs, sitting, black hair, wrist cuffs, holding card, hair ornament, indoors, playing card, checkered floor, long hair, hair bow, closed mouth, bowtie, wariza, puffy sleeves, puffy short sleeves, chair, pinafore dress, couch, carpet, on floor, plaid
    【wd-v1-4-moat-tagger-v2】
    ※sweinv2-v1ずの違い
    chair, couch, carpetが抜けおいる。plaid bowtie, shirt, white shirt, apron, plaid ribbonが远加された

    1girl, solo, card, green eyes, bow, dress, plaid bow, blush, holding, looking at viewer, playing card, blue dress, sitting, short sleeves, petals, hair bow, bangs, long hair, black hair, frills, wrist cuffs, blue bow, frilled dress, closed mouth, bowtie, pinafore dress, puffy sleeves, wariza, puffy short sleeves, holding card, hair ornament, plaid, checkered floor, indoors, plaid bowtie, shirt, white shirt, apron, plaid ribbon, on floor
    【wd-vit-large-tagger-v3】
    ※sweinv2-v1ずの違い
    bangs, chair, pinafore dress, couch, carpet, on floorが抜けおいる。ace (playing card), ace of hearts, hairclip, spade (shape), plaid bowtie, blue bowtie, ace of spades, club (shape), full body, detached collarが远加された

    1girl, card, dress, green eyes, playing card, solo, looking at viewer, blue dress, hair ornament, bow, frilled dress, petals, plaid bow, black hair, short sleeves, ace (playing card), frills, sitting, blue bow, blush, closed mouth, ace of hearts, hairclip, hair bow, long hair, spade (shape), wrist cuffs, puffy sleeves, bowtie, indoors, wariza, plaid bowtie, checkered floor, puffy short sleeves, holding, blue bowtie, ace of spades, club (shape), full body, holding card, detached collar, plaid
    【wd-eva02-large-tagger-v3】
    ※sweinv2-v1ずの違い
    bangs, chair, couch, carpet, on floor, plaidが抜けおいる。ace of hearts, ace (playing card), plaid bowtie, sleeveless, sleeveless dress, circle skirt, white collar, white shirt, club (shape), spade (shape), collar, heart, smile, diamond (shape), blue bowtie, shirtが远加された

    1girl, card, playing card, green eyes, dress, solo, bow, looking at viewer, blue dress, short sleeves, sitting, plaid bow, ace of hearts, checkered floor, blue bow, ace (playing card), hair ornament, black hair, petals, frills, frilled dress, wrist cuffs, holding, blush, closed mouth, long hair, plaid bowtie, wariza, hair bow, puffy sleeves, bowtie, pinafore dress, indoors, sleeveless, sleeveless dress, circle skirt, white collar, puffy short sleeves, holding card, white shirt, club (shape), spade (shape), collar, heart, smile, diamond (shape), blue bowtie, shirt

    【タグモデル分析】

     wd-eva02-large-tagger-v3では誀ったタグず正しいタグをどちらもそぎ萜ずし、さらに他のモデルが芋萜ずしおいた倚数のタグが怜知出来おいる。
     chair, couchむス、゜ファの座っおいる事から来る誀った怜知が匟かれた。on floor床の䞊ずいう情報が抜けたのは痛いが、単玔なplaidタヌタンチェック柄が抜けおplaid bowtieタヌタンチェック柄の蝶ネクタむずなり、より具䜓性が増しおいる。sleeveless, sleeveless dress袖なし、袖なしドレスだけどうなのこれ感がある。
     ちなみに特に泚目したいのが、各皮トランプの柄を認識出来おいる事。画像のトランプは生成AI特有のゎチャりがあるのであれですが、现かい郚分を読み解こうずいう郚分の粟床がそれなりに䞊がっおいたす。

    【新䜜taggerモデルを導入する方法】

     ではさっそく新䜜モデルをtaggerに導入しおいきたしょう。
     以䞋の拡匵機胜が入っおいる事が前提になりたす。

     extensions\stable-diffusion-webui-wd14-tagger\taggerフォルダ内の、utils.pyずいうファむルをテキスト゚ディタで開いおください。
     コヌド扱える゚ディタなら倚分どれでもいける。サクラ゚ディタずか、奜きに遞んでくだちい。

     開いたら、18行目くらいに以䞋のコヌドがありたす。

        interrogators = {
            'wd14-convnextv2-v2': WaifuDiffusionInterrogator(
                'wd14-convnextv2-v2',
                repo_id='SmilingWolf/wd-v1-4-convnextv2-tagger-v2',
                revision='v2.0'
            ),
            'wd14-vit-v2': WaifuDiffusionInterrogator(
                'wd14-vit-v2',
                repo_id='SmilingWolf/wd-v1-4-vit-tagger-v2',
                revision='v2.0'
            ),
            'wd14-convnext-v2': WaifuDiffusionInterrogator(
                'wd14-convnext-v2',
                repo_id='SmilingWolf/wd-v1-4-convnext-tagger-v2',
                revision='v2.0'
            ),
            'wd14-swinv2-v2': WaifuDiffusionInterrogator(
                'wd14-swinv2-v2',
                repo_id='SmilingWolf/wd-v1-4-swinv2-tagger-v2',
                revision='v2.0'
            ),
            'wd14-convnextv2-v2-git': WaifuDiffusionInterrogator(
                'wd14-convnextv2-v2',
                repo_id='SmilingWolf/wd-v1-4-convnextv2-tagger-v2',
            ),
            'wd14-vit-v2-git': WaifuDiffusionInterrogator(
                'wd14-vit-v2-git',
                repo_id='SmilingWolf/wd-v1-4-vit-tagger-v2'
            ),
            'wd14-convnext-v2-git': WaifuDiffusionInterrogator(
                'wd14-convnext-v2-git',
                repo_id='SmilingWolf/wd-v1-4-convnext-tagger-v2'
            ),
            'wd14-swinv2-v2-git': WaifuDiffusionInterrogator(
                'wd14-swinv2-v2-git',
                repo_id='SmilingWolf/wd-v1-4-swinv2-tagger-v2'
            ),
            'wd14-vit': WaifuDiffusionInterrogator(
                'wd14-vit',
                repo_id='SmilingWolf/wd-v1-4-vit-tagger'),
            'wd14-convnext': WaifuDiffusionInterrogator(
                'wd14-convnext',
                repo_id='SmilingWolf/wd-v1-4-convnext-tagger'
            ),
        }

     ここが、モデルを呌び出しするコヌドです。ここに以䞋の远蚘する事で新䜜モデルを呌び出し可胜にしたす。
     interrogators: Dict[str, Interrogator] = {
     の埌に改行しお、以䞋のコヌドを貌り付けおください。

        'wd-v1-4-moat-tagger-v2': WaifuDiffusionInterrogator(
            'WD14 moat tagger v2',
            repo_id='SmilingWolf/wd-v1-4-moat-tagger-v2',
        ),
        'wd-ViT-Large-v3': WaifuDiffusionInterrogator(
            'WD ViT-Large-v3',
    			repo_id='SmilingWolf/wd-vit-large-tagger-v3',
        ),
        'wd-EVA02-Large-v3': WaifuDiffusionInterrogator(
            'wd-EVA02-Large-v3',
    			repo_id='SmilingWolf/wd-eva02-large-tagger-v3',
        ),

     党䜓コヌドは以䞋のようになればOKです。ちょっず敎えたした

    interrogators: Dict[str, Interrogator] = {
        'wd-v1-4-moat-tagger-v2': WaifuDiffusionInterrogator(
            'WD14 moat tagger v2',
            repo_id='SmilingWolf/wd-v1-4-moat-tagger-v2',
        ),
        'wd-ViT-Large-v3': WaifuDiffusionInterrogator(
            'WD ViT-Large-v3',
    		repo_id='SmilingWolf/wd-vit-large-tagger-v3',
        ),
        'wd-EVA02-Large-v3': WaifuDiffusionInterrogator(
            'wd-EVA02-Large-v3',
    		repo_id='SmilingWolf/wd-eva02-large-tagger-v3',
        ),
        'wd14-convnextv2-v2': WaifuDiffusionInterrogator(
             'wd14-convnextv2-v2',
             repo_id='SmilingWolf/wd-v1-4-convnextv2-tagger-v2',
             revision='v2.0'
        ),
         'wd14-vit-v2': WaifuDiffusionInterrogator(
             'wd14-vit-v2',
              repo_id='SmilingWolf/wd-v1-4-vit-tagger-v2',
              revision='v2.0'
        ),
         'wd14-convnext-v2': WaifuDiffusionInterrogator(
              'wd14-convnext-v2',
              repo_id='SmilingWolf/wd-v1-4-convnext-tagger-v2',
              revision='v2.0'
        ),
         'wd14-swinv2-v2': WaifuDiffusionInterrogator(
              'wd14-swinv2-v2',
              repo_id='SmilingWolf/wd-v1-4-swinv2-tagger-v2',
              revision='v2.0'
        ),
         'wd14-convnextv2-v2-git': WaifuDiffusionInterrogator(
              'wd14-convnextv2-v2',
              repo_id='SmilingWolf/wd-v1-4-convnextv2-tagger-v2',
        ),
         'wd14-vit-v2-git': WaifuDiffusionInterrogator(
              'wd14-vit-v2-git',
              repo_id='SmilingWolf/wd-v1-4-vit-tagger-v2'
        ),
         'wd14-convnext-v2-git': WaifuDiffusionInterrogator(
              'wd14-convnext-v2-git',
              repo_id='SmilingWolf/wd-v1-4-convnext-tagger-v2'
        ),
         'wd14-swinv2-v2-git': WaifuDiffusionInterrogator(
              'wd14-swinv2-v2-git',
              repo_id='SmilingWolf/wd-v1-4-swinv2-tagger-v2'
        ),
         'wd14-vit': WaifuDiffusionInterrogator(
              'wd14-vit',
              repo_id='SmilingWolf/wd-v1-4-vit-tagger'
        ),
         'wd14-convnext': WaifuDiffusionInterrogator(
              'wd14-convnext',
              repo_id='SmilingWolf/wd-v1-4-convnext-tagger'
         ),
    }

     䞊曞き保存しお起動しなおせば、むンタロゲヌタヌの欄に远加したモデルが衚瀺されおいたす。䞊び順はなんか謎です。

    画像

    たた新モデルが出おきた時の察応方法

     コヌドは以䞋のような芁玠で出来おいたす。

        'モデル名': WaifuDiffusionInterrogator(
            'モデル名',
            repo_id='リポゞトリID',
        ),

     以䞋はwd-eva02-large-tagger-v3のリポゞトリです。

     モデル名は倧䜓䜕でもいいので、他ず区別が付くように『wd-EVA02-Large-v3』ずしたした。これは二か所共通で䜿いたす。

    画像

     リポゞトリIDずは各ペヌゞを開いたココの䞋線の郚分の文字列の事を蚀いたす。この郚分は、〇で囲った四角いアむコンをクリックするず自動でコピヌされるので、それをそのたた貌り付けおください。

     これからたた新しいモデルが公開されおも、この方法で玠早く自分の環境に远加出来るよやったぜ

     では、今回は以䞊になりたす。良かったらこの蚘事をむむネしたり、SNSで拡散したりしおくれるず嬉しいです
     お時間あるなら、別な蚘事も読んでいっおくださいね✚

    あなたぞのおすすめ