INSTALL REQUIREMENTS


!wget -q https://github.com/ShivamShrirao/diffusers/raw/main/examples/dreambooth/train_dreambooth.py
!wget -q https://github.com/ShivamShrirao/diffusers/raw/main/scripts/convert_diffusers_to_original_stable_diffusion.py
%pip install -qq git+https://github.com/ShivamShrirao/diffusers
%pip install -q -U --pre triton
%pip install -q accelerate transformers ftfy bitsandbytes==0.35.0 gradio natsort safetensors


WEIGHTS


save_to_gdrive = False 
if save_to_gdrive:
    from google.colab import drive
    drive.mount('/content/drive')


MODEL_NAME = "runwayml/stable-diffusion-v1-5" 


OUTPUT_DIR = "stable_diffusion_weights/zwx" 
if save_to_gdrive:
    OUTPUT_DIR = "/content/drive/MyDrive/" + OUTPUT_DIR
else:
    OUTPUT_DIR = "/content/" + OUTPUT_DIR


print(f"[*] Weights will be saved at {OUTPUT_DIR}")


!mkdir -p $OUTPUT_DIR


CONCEPT LIST
concepts_list = [
    {
        "instance_prompt":      "photo of sacristy",
        "class_prompt":         "photo of a room",
        "instance_data_dir":    "/content/data/sacristy",
        "class_data_dir":       "/content/data/room"
    },
     {
         "instance_prompt":      "photo of screens furniture",
         "class_prompt":         "photo of a furniture",
         "instance_data_dir":    "/content/data/screens",
         "class_data_dir":       "/content/data/furniture"
    }
]


import json
import os
for c in concepts_list:
    os.makedirs(c["instance_data_dir"], exist_ok=True)


with open("concepts_list.json", "w") as f:
    json.dump(concepts_list, f, indent=4)
UPLOADS


import os
from google.colab import files
import shutil


for c in concepts_list:
    print(f"Uploading instance images for `{c['instance_prompt']}`")
    uploaded = files.upload()
    for filename in uploaded.keys():
        dst_path = os.path.join(c['instance_data_dir'], filename)
        shutil.move(filename, dst_path)




TRAINING


!accelerate launch train_dreambooth.py \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --pretrained_vae_name_or_path="stabilityai/sd-vae-ft-mse" \
  --output_dir=$OUTPUT_DIR \
  --revision="fp16" \
  --with_prior_preservation --prior_loss_weight=1.0 \
  --seed=1337 \
  --resolution=512 \
  --train_batch_size=1 \
  --train_text_encoder \
  --mixed_precision="fp16" \
  --use_8bit_adam \
  --gradient_accumulation_steps=1 \
  --learning_rate=1e-6 \
  --lr_scheduler="constant" \
  --lr_warmup_steps=0 \
  --num_class_images=50 \
  --sample_batch_size=4 \
  --max_train_steps=800 \
  --save_interval=10000 \
  --concepts_list="concepts_list.json"
region:us
{"pretty_name": "sacristy"}
TAGS
#region-us 

INSTALL REQUIREMENTS


!wget -q URL
!wget -q URL
%pip install -qq git+URL
%pip install -q -U --pre triton
%pip install -q accelerate transformers ftfy bitsandbytes==0.35.0 gradio natsort safetensors


WEIGHTS


save_to_gdrive = False 
if save_to_gdrive:
    from URL import drive
    URL('/content/drive')


MODEL_NAME = "runwayml/stable-diffusion-v1-5" 


OUTPUT_DIR = "stable_diffusion_weights/zwx" 
if save_to_gdrive:
    OUTPUT_DIR = "/content/drive/MyDrive/" + OUTPUT_DIR
else:
    OUTPUT_DIR = "/content/" + OUTPUT_DIR


print(f"[*] Weights will be saved at {OUTPUT_DIR}")


!mkdir -p $OUTPUT_DIR


CONCEPT LIST
concepts_list = [
    {
        "instance_prompt":      "photo of sacristy",
        "class_prompt":         "photo of a room",
        "instance_data_dir":    "/content/data/sacristy",
        "class_data_dir":       "/content/data/room"
    },
     {
         "instance_prompt":      "photo of screens furniture",
         "class_prompt":         "photo of a furniture",
         "instance_data_dir":    "/content/data/screens",
         "class_data_dir":       "/content/data/furniture"
    }
]


import json
import os
for c in concepts_list:
    os.makedirs(c["instance_data_dir"], exist_ok=True)


with open("concepts_list.json", "w") as f:
    URL(concepts_list, f, indent=4)
UPLOADS


import os
from URL import files
import shutil


for c in concepts_list:
    print(f"Uploading instance images for '{c['instance_prompt']}'")
    uploaded = URL()
    for filename in URL():
        dst_path = URL(c['instance_data_dir'], filename)
        URL(filename, dst_path)




TRAINING


!accelerate launch train_dreambooth.py \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --pretrained_vae_name_or_path="stabilityai/sd-vae-ft-mse" \
  --output_dir=$OUTPUT_DIR \
  --revision="fp16" \
  --with_prior_preservation --prior_loss_weight=1.0 \
  --seed=1337 \
  --resolution=512 \
  --train_batch_size=1 \
  --train_text_encoder \
  --mixed_precision="fp16" \
  --use_8bit_adam \
  --gradient_accumulation_steps=1 \
  --learning_rate=1e-6 \
  --lr_scheduler="constant" \
  --lr_warmup_steps=0 \
  --num_class_images=50 \
  --sample_batch_size=4 \
  --max_train_steps=800 \
  --save_interval=10000 \
  --concepts_list="concepts_list.json"
TAGS
#region-us 

passage: TAGS
#region-us 
