
Mitsua Likesã«è§ŠããŠã¿ãïŒWindows+CUDAãVRAM 8GBïŒ
â» Last update 12-18-2024
â» 3.ã«ãŠãçæãã16æã®ç»åãšãã©ã¡ãŒã¿ãŒãæ²èŒããŠããŸãã
â» å©çšã®éã¯å¿
ããMitsua Likes 衚瀺-éå¶å©ã©ã€ã»ã³ã¹ãã確èªããŠãã ããã
â» CUDA Toolkitã¯12.1以äžã§ãHuggingFaceã®ã¢ã«ãŠã³ããšGitãå¿
èŠã§ããVRAMã¯8GBã§ããã°ååã§ãã
â 0. æŠèŠ
⌠0-0. ã¯ããã«
ãæ¬èšäºã§ã¯ãMitsua Likesããå©çšããŠã¿ãŸãããã®ã¢ãã«ã¯ãæç€ºçãªããã€ã³ã§èš±è«ŸãåŸãããŒã¿ããªãŒãã³ã©ã€ã»ã³ã¹åã³ãããªãã¯ãã¡ã€ã³ã®ããŒã¿ã®ã¿ãã䜿çšãããã¢ãã«ã®ã¢ãŒããã¯ãã£å šäœ(CLIP Text Encoder, VAE, UNet)ããä»ã®ã¢ãã«ã®ç¥èã䜿çšããããšãªããå®å šã«ãŒãããåŠç¿ãããããã®ãšã®ããšã§ãã詳现ã¯äžèšã®ãªã³ã¯å ãã確èªããŠãã ããã
⌠0-1. ã¢ãã«ç
Mitsua Likes : A Text-to-Image Diffusion Model trained on Opt-In Contributors' "Likes"
https://huggingface.co/Mitsua/mitsua-likesÂ
Mitsua Likes Demo
https://huggingface.co/spaces/Mitsua/Likes-demoÂ
⌠0-2. é¢é£ãªã³ã¯
çµµèããã¢
https://elanmitsua.com/Â
https://x.com/elanmitsuaÂ
æ ªåŒäŒç€Ÿã¢ãã¹ãã©ã¯ããšã³ãžã³
https://abstractengine.ltd/Â
ïŒ2021å¹Žã«æ ªåŒäŒç€Ÿã©ã€ãŸããã£ã¯ã¹ãã瀟å倿ŽïŒ
â 1. å©çšã®æºå
⌠1-1. ã¯ããã«
ãCUDA ToolkitïŒ12.1以äžïŒãšGitãã€ã³ã¹ããŒã«ãããŠããããšãHuggingFaceã®ã¢ã«ãŠã³ããååŸããŠããããšãåæãšããŠã以éã®æé ãé²ããŸãã
⌠1-2. ã¢ã¯ã»ã¹èš±å¯ã®ããã®åæ
ãhttps://huggingface.co/Mitsua/mitsua-likes ãžã¢ã¯ã»ã¹ããŠãã¢ãã«ãžã¢ã¯ã»ã¹ããããã®åæãè¡ã£ãŠãã ãããäžèšã¯åèã®ããæ²èŒããŸãã

Mitsua Likes 衚瀺-éå¶å©ã©ã€ã»ã³ã¹
https://elanmitsua.notion.site/Mitsua-Likes-15baa85a9b278005bba5f30866a35f48Â
Abstract Engineã®ãã©ã€ãã·ãŒããªã·ãŒ
https://elanmitsua.notion.site/2023-1-16-664669b0aebc4b1d90aba7c068bd7c86
⌠1-3. ã¢ãã«ã®ã¢ã¯ã»ã¹èš±å¯åŸ ã¡
ãäžèšã®è¡šç€ºãåºãŠããéã¯ããŸã ã¢ã¯ã»ã¹èš±å¯ãåºãŠããªãã®ã§ããŠã³ããŒããã§ããŸãããå ã«1-4.ïœ1-5.ã®æé ãè¡ã£ãŠãããšè¯ãã§ãããã

ãã¢ã¯ã»ã¹èš±å¯ãåºããšãäžèšã®è¡šç€ºã«åãæ¿ãããŸãã

⌠1-4. å®è¡ãã£ã¬ã¯ããªã®æºå
ãäœæ¥ãã£ã¬ã¯ããªãã\aiworkããå®è¡ãã£ã¬ã¯ããªãã\aiwork\mitsua-likes-testããšããŠããŸãã®ã§ãã奜ã¿ã®å Žæã«èªã¿æ¿ããŠãã ããã
ãäžèšã®ã³ãã³ããé ã«å®è¡ããŠãã ãããå®è¡ãã£ã¬ã¯ããªãäœæããŠããã®äžã«ç§»åããŸãã
cd \aiwork
mkdir mitsua-likes-test
cd mitsua-likes-test⌠1-5. å®è¡ç°å¢ã®æºå
ãäžèšã®ã³ãã³ããé ã«å®è¡ããŠãã ããããpip installãå®è¡æã«ãããŠã³ããŒãçã§è¥å¹²ã®æéãèŠããŸãã
python -m venv venv
venv\Scripts\activate
python -m pip install --upgrade pip
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
pip install accelerate protobuf transformers==4.44.2 diffusers==0.31.0 sentencepiece==0.2.0
⌠1-6. ã¢ã¯ã»ã¹ããŒã¯ã³ã®ç¢ºèª
ãã¢ãã«ãããŠã³ããŒãããéã«ã¢ã¯ã»ã¹ããŒã¯ã³ãå¿ èŠã§ããæå¹ãªããŒã¯ã³ãåãã£ãŠããå Žåã¯ãããå©çšã§ããŸããäžèšã¯ããŒã¯ã³ãååŸããæé ã§ãã
ãæåã« https://huggingface.co/settings/profile ãžã¢ã¯ã»ã¹ããŠãå·ŠåŽããAccess TokensãéžæããŸããæ¢ã«ååšããããŒã¯ã³ãæŽæ°ããŠãè¯ãå Žåã¯ãå³åŽã®äžç¹ãã¯ãªãã¯ããŠãInvalidate and refreshããéžã¶ãšæ°ããããŒã¯ã³ã衚瀺ãããŸãããããã¯ããCreate new tokenããã¯ãªãã¯ããŠãToken typeãã¯ãreadããéžã³ãé©åœãªååãä»ããŠãCreate tokenããã¯ãªãã¯ãããšè¡šç€ºãããŸããããŒã¯ã³ã®å€ã¯å衚瀺ã§ããªãã®ã§æ³šæããŠãã ãããä»ã§å©çšããŠããªããã°ããã®éœåºŠãInvalidate and refreshããè¡ã£ãŠååŸããŠãæ§ããŸããã
⌠1-7. ã¢ãã«ã®ããŠã³ããŒã
ãäžèšã®ã³ãã³ããå®è¡ããŠãã ããããEnter your tokenïœããšè¡šç€ºããããã1-6.ã§ç¢ºèªããã¢ã¯ã»ã¹ããŒã¯ã³ãå ¥åããŸãããAdd token as git credential? (Y/n)ãã§ã¯ããã®ãŸãŸEnterãæŒããŸãããLogin successfulããšè¡šç€ºããããå®äºã§ãã
huggingface-cli loginãæ¬¡ã«ãäžèšã®ã³ãã³ããé ã«å®è¡ããŠãã ãããæ£ããã¢ã¯ã»ã¹èš±å¯ãåºãŠããã°ã¢ãã«ãããŠã³ããŒãã§ããŸãã
ãããŠã³ããŒããå®äºãããããã£ããã³ãã³ãããã³ããã®ãŠã€ã³ããŠãéããŠãã ãããæ¬åœã¯éããªããŠãè¯ãã®ã§ããã2åç®ä»¥éã®èµ·åæé ã確èªããŠããã ããããã®ããã«ããŠããŸãã
git lfs install
git clone https://huggingface.co/Mitsua/mitsua-likes
â 2. ç»åã®çæ
⌠2-1. çæçšã®ã³ãŒãã«ã€ããŠïŒCUIçïŒ
ããµã³ãã«ã³ãŒããåèã«äœæããŸãããã³ãŒãã®äžéšã¯ChatGPTãå©çšããŠããŸããç°¡çŽ ãªããäžèšã®æ©èœããããŸãã
ã³ãã³ãã©ã€ã³ã«ãŠããã³ããã®æå®ãå¯èœ
ç»åã«ã¯ã¬ãžããã衚瀺ïŒã©ã€ã»ã³ã¹äžãçæç»åãå ¬éãå ±æããå Žåã¯å¿ é ïŒ
çæã®èšå®ã倿Žå¯èœïŒã³ãŒããçŽæ¥æžãæãïŒ
çæææ°ã®æå®ãå¯èœïŒããã©ã«ãã¯5ïŒ
é¡äŒŒåºŠããã©ã¡ãŒã¿ãŒãç»åã«èšé²
ãèªå·±è²¬ä»»ã«ãããŠãæ¬èšäºã«æ²èŒããã³ãŒããèªç±ã«å€æŽãããåå ¬éãããããããšãã§ããŸãããã®å Žåã¯ãMitsua Likesã®ã©ã€ã»ã³ã¹ããã確èªããŠãã ããã
⌠2-2. çæçšã®ã³ãŒãïŒCUIçïŒ
ãäžèšã®ã³ãŒãããå®è¡ãã£ã¬ã¯ããªïŒ\aiwork\mitsua-likes-test çïŒã«èšçœ®ããŠãã ããã
ãå°ãé·ããªããŸãããäžèšãã¡ã€ã«ã®å šã³ãŒããæ²èŒããŸãã
# Mitsua Likes Image Generator
# Model: https://huggingface.co/Mitsua/mitsua-likes
# License: https://elanmitsua.notion.site/Mitsua-Likes-15baa85a9b278005bba5f30866a35f48
# usage:
# python mitsua-test.py [Prompt]
# example:
# python mitsua-test.py
# python mitsua-test.py ç¬ãçµµèããã¢
# python mitsua-test.py "upper body, girl, smile, digital illustration"
# èšå® / Settings
# çæææ° / Number of images
num_images = 5
# åºåå
/ Output directory
output_dir = "output"
# ãã©ã¡ãŒã¿ãŒ / Generation parameters
prompt = '''çµµèããã¢ãšè±çãå
çã¢ãŒã'''
negative_prompt = '''elan doodle, lowres'''
width = 768
height = 768
guidance_scale = 5.0
guidance_rescale= 0.7
num_inference_steps = 40
# Tips.
# ã¹ã¿ã€ã« / Style
# "å
çã¢ãŒã" or "sensei art"
# "ããžã¿ã«ã€ã©ã¹ã" or "digital illustration"
# "ã¢ããã°ã€ã©ã¹ã" or "analog illustration"
# "3d cg"
# "èžè¡äœå" or "artworks"
# è§£ååºŠïŒæšªãçžŠïŒ / resolution (width, height)
# 1024, 576 (16: 9)
# 896, 672 ( 4: 3)
# 768, 768 ( 1: 1)
# 672, 896 ( 3: 4)
# 576,1024 ( 9:16)
# ãã©ã³ã / Font
font_name = "Arial.ttf"
##########################################################
### 以äžã¯å€æŽäžèŠã§ã / No changes are required below ###
##########################################################
import os
import sys
import torch
from diffusers import DiffusionPipeline
from datetime import datetime
from PIL import ImageDraw, ImageFont, PngImagePlugin
# Make output dir
os.makedirs(output_dir, exist_ok=True)
# Prompt from commandline
if len(sys.argv) > 1:
prompt = sys.argv[1]
# Device configuration
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16
# Set up the pipeline
pipe = DiffusionPipeline.from_pretrained("./mitsua-likes").to(device, dtype=dtype)
#pipe = DiffusionPipeline.from_pretrained("Mitsua/mitsua-likes", trust_remote_code=True).to(device, dtype=dtype) # original diffusers model
# Image generation loop
for i in range(num_images):
# Generate a seed
seed = torch.seed()
generator = torch.Generator(device=device).manual_seed(seed)
# Generate image
ret = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
guidance_scale=guidance_scale,
guidance_rescale=guidance_rescale,
width=width,
height=height,
num_inference_steps=num_inference_steps,
)
# Similarity detection model output
similarity_detection = (
f"Similarity Restriction: {ret.detected_public_fictional_characters[0]}\n"
"Similarity Measure:\n"
+ "\n".join(
f"{k} : {v:.3%}"
for k, v in ret.detected_public_fictional_characters_info[0].items()
)
)
print (similarity_detection)
# Output image
image = ret.images[0]
# Add credit *** DO NOT REMOVE ***
font_path = os.path.join(os.environ["WINDIR"], "Fonts", font_name)
if not os.path.isfile(font_path):
raise FileNotFoundError(f"Font file not found: {font_path}")
font_size = 32
text = "Generated by Mitsua Likes"
font = ImageFont.truetype(font_path, font_size)
draw = ImageDraw.Draw(image)
text_bbox = draw.textbbox((0, 0), text, font=font)
text_width, text_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
x = image.width - text_width - 20
y = image.height - text_height - 20
draw.text((x + 2, y + 2), text, font=font, fill="black")
draw.text((x, y), text, font=font, fill="white")
# Set metadata
img_parameters = (
f"\n"
f"Prompt: {prompt} \n"
f"Negative prompt: {negative_prompt} \n"
f"Steps: {num_inference_steps} \n"
f"Guidance Scale: {guidance_scale} \n"
f"Guidance Rescale: {guidance_rescale} \n"
f"Seed: {seed} \n"
f"Width: {width} \n"
f"Height: {height} \n"
f"Model: https://huggingface.co/Mitsua/mitsua-likes \n"
f"{similarity_detection}\n"
)
metadata = PngImagePlugin.PngInfo()
metadata.add_text("parameters", img_parameters)
# Save an image
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{output_dir}/{timestamp}-{seed}-mitsua_likes.png"
image.save(filename, "PNG", pnginfo=metadata)
print(f"Saved: {filename}")
⌠2-3. çæã®å®è¡
ãã³ãã³ãããã³ãããéããŠãããäžèšã®ã³ãã³ããé ã«å®è¡ããŠãã ãããå®è¡ãã£ã¬ã¯ããªã«ç§»åããŠä»®æ³ç°å¢ãæå¹åããŸãã
cd \aiwork\mitsua-likes-test
venv\Scripts\activateããªããå®è¡ãã£ã¬ã¯ããªã«äžèšã®å 容ã§ããããã¡ã€ã«ïŒãã¡ã€ã«å㯠activate_venv.bat çïŒãçšæããŠãããšããšã¯ã¹ãããŒã©ãŒäžããå®è¡ããã ãã§æžãã®ã§ããããã§ãã
@echo off
cd %~dp0
call venv\Scripts\activate.bat
cmd /kãäžèšã®ã³ãã³ããå®è¡ãããšãMitsua Likesã®ã¢ãã«ãèªã¿èŸŒãã§ç»åã5æçæãããoutputsããã£ã¬ã¯ããªã«ä¿åããŸãã
python mitsua-test.pyãããã©ã«ãã®ããã³ããã¯ãçµµèããã¢ãšè±çãå çã¢ãŒããã«ãªã£ãŠããŸããå®è¡æã«ããã³ãããæå®ããŠå€æŽãã§ããŸãã
python mitsua-test.py è¡ã®å€æ¯ãæç©ºãè±èªããã³ããçã§åè§ã¹ããŒã¹ãå ¥ãããå Žåã¯ãããã«ã¯ãªãŒããŒã·ã§ã³ïŒ""ïŒã§å²ãã§ãã ããã
python mitsua-test.py "tomato on table, artworks"⌠2-4. èšå®ã®å€æŽ
ãèšå®ã倿Žãããå Žåã¯ãã³ãŒããçŽæ¥æžãæããŠãã ãããåèãŸã§ã該åœããéšåãåæ²èŒããŸããããã³ããã«èšå·ã䜿ããããã«ãpromptãšnegative_promptã¯ããªãã«ã¯ãªãŒããŒã·ã§ã³ã§å²ã£ãŠããŸãã
# çæææ° / Number of images
num_images = 5
# åºåå
/ Output directory
output_dir = "output"
# ãã©ã¡ãŒã¿ãŒ / Generation parameters
prompt = '''çµµèããã¢ãšè±çãå
çã¢ãŒã'''
negative_prompt = '''elan doodle, lowres'''
width = 768
height = 768
guidance_scale = 5.0
guidance_rescale= 0.7
num_inference_steps = 40
# Tips.
# ã¹ã¿ã€ã« / Style
# "å
çã¢ãŒã" or "sensei art"
# "ããžã¿ã«ã€ã©ã¹ã" or "digital illustration"
# "ã¢ããã°ã€ã©ã¹ã" or "analog illustration"
# "3d cg"
# "èžè¡äœå" or "artworks"
# è§£ååºŠïŒæšªãçžŠïŒ / resolution (width, height)
# 1024, 576 (16: 9)
# 896, 672 ( 4: 3)
# 768, 768 ( 1: 1)
# 672, 896 ( 3: 4)
# 576,1024 ( 9:16)
# ãã©ã³ã / Font
font_name = "Arial.ttf"â 3. ã®ã£ã©ãªãŒ
⌠3-1. çæããç»å
ã2.ã«æ²èŒããã³ãŒãã§ãMitsua LikesãçšããŠçæããç»åã§ããã¯ãªãªãã£ã¯ããŸã远æ±ããŠããªãã®ã§ããããŸã§åèãšããŠãã ãããäžéšãããã³ããã«åŠç¿æžã¿ãã£ã©ã¯ã¿ãŒã®ååãå«ãã§ããŸãã
æ±åããåã»ããã ããïŒæ±åã€ã¿ã³ãæ±åãããããååœããããä¹å·ãããäžåœããããå€§æ±æžã¡ããããå«ãïŒ

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 24758018820400, Width: 1024, Height: 576
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['çµµèããã¢']
Similarity Measure: çµµèãã㢠: 99.609%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 23553548394200, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['çµµèããã¢']
Similarity Measure: çµµèãã㢠: 99.268%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 24094295981700, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: []
Similarity Measure:

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: []
Similarity Measure: ã€ããã¿ã¡ãã : 98.828%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: []
Similarity Measure: æ±åããå : 98.584%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['ããã ãã']
Similarity Measure: ããã ãã : 99.951%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['玡ãã³']
Similarity Measure: 玡ãã³ : 100.000%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['ãã£ãŒã¡ãã']
Similarity Measure: ãã£ãŒã¡ãã : 100.000%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: []
Similarity Measure: æ±åã€ã¿ã³ : 97.021%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['æ±åãããã']
Similarity Measure: æ±åãããã : 99.902%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['ååœããã']
Similarity Measure: ååœããã : 99.805%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: []
Similarity Measure: ä¹å·ãã : 12.146% å€§æ±æžã¡ããã : 10.522%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['äžåœããã']
Similarity Measure: äžåœããã : 99.707%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768 Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: ['å€§æ±æžã¡ããã']
Similarity Measure: å€§æ±æžã¡ããã : 99.902%

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: []
Similarity Measure:

Negative prompt: elan doodle, lowres
Steps: 40, Guidance Scale: 5.0, Guidance Rescale: 0.7
Seed: 25657794262800, Width: 768, Height: 768
Model: https://huggingface.co/Mitsua/mitsua-likes
Similarity Restriction: []
Similarity Measure:
â 4. ãã®ä»
ãç§ãæžããä»ã®èšäºã¯ãã¡ãã¥ãŒãããã©ã£ãŠãã ããã
ãèšäºã«é¢ããããšã§äœããããŸããããXã®@riddi0908ãŸã§ãé¡ãããŸãã