• Stars
    star
    303
  • Rank 136,824 (Top 3 %)
  • Language
    Jupyter Notebook
  • License
    Apache License 2.0
  • Created about 1 year ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Low-rank adaptation for Erasing COncepts from diffusion models.

LECO ✏️

Open In Colab

Low-rank adaptation for Erasing COncepts from diffusion models.

The original repository: Erasing Concepts from Diffusion Models

and the project page: https://erasing.baulab.info/

(Not only for erasing concepts, but also emphasizing or swapping them by devising prompts and LoRA weight. See ConceptMod for more details)

Setup

conda create -n leco python=3.10
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
pip install xformers
pip install -r requirements.txt

Train

You need 8GB VRAM at least.

python ./train_lora.py --config_file "./examples/config.yaml"

config.yaml:

prompts_file: "./prompts.yaml"

pretrained_model:
  name_or_path: "stabilityai/stable-diffusion-2-1" # you can also use .ckpt or .safetensors models
  v2: true # true if model is v2.x
  v_pred: true # true if model uses v-prediction

network:
  type: "lierla" # or "c3lier"
  rank: 4
  alpha: 1.0

train:
  precision: "bfloat16"
  noise_scheduler: "ddim" # or "ddpm", "lms", "euler_a"
  iterations: 500
  lr: 1e-4
  optimizer: "AdamW"
  lr_scheduler: "constant"

save:
  name: "van_gogh"
  path: "./output"
  per_steps: 200
  precision: "bfloat16"

logging:
  use_wandb: false
  verbose: false

other:
  use_xformers: true

prompts.yaml:

- target: "van gogh" # what word for erasing the positive concept from
  positive: "van gogh" # concept to erase
  unconditional: "" # word to take the difference from the positive concept
  neutral: "" # starting point for conditioning the target
  action: "erase" # erase or enhance
  guidance_scale: 1.0
  resolution: 512
  dynamic_resolution: false
  batch_size: 2

See the example config for more details.

Note: You can use float16 but it is unstable and not recommended. Please use bfloat16 or float32.

Pretrained weights

You can use the pretrained weights on AUTOMATIC1111's webui.

🤗 HuggingFace: https://huggingface.co/p1atdev/leco

SDv1.5

  • Van Gogh style (trained to erase the concept of "van gogh style" on SDv1.5)

Results of oil painting of van gogh by himself:

van gogh

Generation settings
oil painting of van gogh by himself
Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 3870472781, Size: 512x512, Model hash: cc6cb27103, Model: v1-5-pruned-emaonly, Clip skip: 2, AddNet Enabled: True, AddNet Module 1: LoRA, AddNet Model 1: van_gogh_4_last(db68853d039b), AddNet Weight A 1: -1.0, AddNet Weight B 1: -1.0, Script: X/Y/Z plot, X Type: AddNet Weight 1, X Values: "-1, 0, 1", Version: v1.3.0

Results of painting of scenery by monet:

monet

Generation settings
painting of scenery by monet
Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 1284787312, Size: 512x512, Model hash: cc6cb27103, Model: v1-5-pruned-emaonly, Clip skip: 2, AddNet Enabled: True, AddNet Module 1: LoRA, AddNet Model 1: van_gogh_4_last(db68853d039b), AddNet Weight A 1: -1.0, AddNet Weight B 1: -1.0, Script: X/Y/Z plot, X Type: AddNet Weight 1, X Values: "-1, 0, 1", Version: v1.3.0

SDv2.1-768

  • Mona Lisa (trained to erase the concept of "mona lisa" on SDv2.1-768)

Results of mona lisa with jewelry:

mona lisa

Generation settings
mona lisa with jewelry
Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 3630495347, Size: 512x512, Model hash: 832eb50c0c, Model: v2-1_768-ema-pruned, Clip skip: 2, AddNet Enabled: True, AddNet Module 1: LoRA, AddNet Model 1: mona_lisa2_last(393beb35c4b1), AddNet Weight A 1: -1.0, AddNet Weight B 1: -1.0, Script: X/Y/Z plot, X Type: AddNet Weight 1, X Values: "-1, 0, 1", Version: v1.3.0

Results of photo of a cute cat:

mona lisa

Generation settings
photo of a cute cat
Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 900866192, Size: 512x512, Model hash: 832eb50c0c, Model: v2-1_768-ema-pruned, Clip skip: 2, AddNet Enabled: True, AddNet Module 1: LoRA, AddNet Model 1: mona_lisa2_last(393beb35c4b1), AddNet Weight A 1: -1.0, AddNet Weight B 1: -1.0, Script: X/Y/Z plot, X Type: AddNet Weight 1, X Values: "-1, 0, 1", Version: v1.3.0

WD1.5 beta3

  • Cat ears (trained to replace "1girl" with "1girl, cat ears" on WD1.5 beta3 )

Cat ears will be attached forcibly when using with 1.0~3.0 weight.

If -1.0~-3.0, cat ears will never appear.

Training settings: see configs.

cat ears

Generation settings
masterpiece, best quality, exceptional, best aesthetic, anime, 1girl, school uniform, upper body, smile
Negative prompt: worst quality, low quality, bad aesthetic, oldest, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry
Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 4103955758, Size: 512x512, Model hash: d38e779546, Model: wd-beta3-base-fp16, Clip skip: 2, Script: X/Y/Z plot, X Type: AddNet Weight 1, X Values: "0, 2, 3, 4", Version: v1.3.0
  • Unreal (trained to erase "realistic", "real life", "instagram" on WD1.5 beta3)

Training settings: see configs.

With "real life, instagram":

unreal

Generation settings
real life, instagram, masterpiece, best quality, exceptional, best aesthetic, 1girl, cat ears, blue hair, school uniform, upper body
Negative prompt: worst quality, low quality, bad aesthetic, oldest, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry
Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 757542759, Size: 768x768, Model hash: d38e779546, Model: wd-beta3-base-fp16, Clip skip: 2, AddNet Enabled: True, AddNet Module 1: LoRA, AddNet Model 1: unreal_6_many_prompts_200steps(fff5917285da), AddNet Weight A 1: -1.0, AddNet Weight B 1: -1.0, Script: X/Y/Z plot, X Type: AddNet Weight 1, X Values: "-1, 0, 1", Version: v1.3.0

Without "real life, instagram":

unreal

Generation settings
masterpiece, best quality, exceptional, best aesthetic,, 1girl, aqua eyes, baseball cap, blonde hair, closed mouth, earrings, green background, hat, hoop earrings, jewelry, looking at viewer, shirt, short hair, simple background, solo, upper body, yellow shirt,
Negative prompt: worst quality, low quality, bad aesthetic, oldest, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry
Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 2867636749, Size: 768x768, Model hash: d38e779546, Model: wd-beta3-base-fp16, Clip skip: 2, AddNet Enabled: True, AddNet Module 1: LoRA, AddNet Model 1: unreal_6_many_prompts_200steps(fff5917285da), AddNet Weight A 1: -1.0, AddNet Weight B 1: -1.0, Script: X/Y/Z plot, X Type: AddNet Weight 1, X Values: "-1, 0, 1", Version: v1.3.0

References

I am deeply inspired by and my work relies on the outstanding efforts of the following projects. I want to express my profound gratitude to these projects and their developers:

More Repositories

1

sd-danbooru-tags-upsampler

Makes the prompts for generating anime images more detailed by upsampling Danbooru tags.
Python
78
star
2

stable-diffusion-webui-blip2-captioner

BLIP2 captioning tool as an extension of AUTOMATIC's WebUI
Python
59
star
3

stable-diffusion-webui-adverse-cleaner-tab

An extension of AUTOMATIC1111's webui to remove adverse noise from images.
Python
55
star
4

stable-diffusion-webui-cafe-aesthetic

An extension of cafe_aesthetic for AUTOMATIC1111's Stable Diffusion Web UI
Python
36
star
5

whisper

A client that wraps the API behind Twitter.
TypeScript
27
star
6

stable-journey-bot

Discord bot client for AUTOMATIC1111's stable-diffusion-webui.
TypeScript
24
star
7

Real-CUGAN-GUI

Real-CUGAN GUI tool
Dart
15
star
8

stable-diffusion-webui-laion-aesthetic

LAION Aesthetic Predictor for AUTOMATIC111's WebUI
Python
10
star
9

stable-diffusion-webui-video-extractor

Python
8
star
10

twitterql

Unofficial Twitter API Client for Deno
TypeScript
7
star
11

MonsterSiren

Arknights OST Player
Swift
6
star
12

huggingface_dl

A download tool for huggingface in CLI
Python
6
star
13

danbooru-tags-transformer

Jupyter Notebook
5
star
14

booru-wizard

TypeScript
4
star
15

manga-dl

Download mangas from official manga website tool made in Deno
TypeScript
3
star
16

twimedia-wizard

Twitter Media Downloader
TypeScript
3
star
17

shadowban-backend-deno

Check if a Twitter user is being shadow banned.
TypeScript
3
star
18

dart-training

Jupyter Notebook
3
star
19

tchecker.js

JavaScript
2
star
20

pinterest-wizard

Scrape Pinterest
Python
2
star
21

sd-annotators

Python
2
star
22

discordeno_sample

Discord bot sample with discordeno
TypeScript
2
star
23

edge-sdxl

SDXL with Cloudflare Workers AI
TypeScript
2
star
24

dartrs

Rust
2
star
25

monster_siren

Monster Siren API Client for Dart
Dart
1
star
26

simple-mitm

Go
1
star
27

homete-bot

褒めて!!!
TypeScript
1
star
28

siren

Arknights OST Downloader with Deno
TypeScript
1
star
29

DMGer

Bypass restricting DMG file extracting...
Python
1
star
30

KawaiiDiffusion

My diffusion kawaii-illustration generatiion laboratory
Jupyter Notebook
1
star
31

Pipe

JavaScript
1
star
32

p1at-newt-blog

Plat Dev Blog
TypeScript
1
star
33

shadowban-frontend

Twitter shadowban checker website's frontend
Vue
1
star
34

manga-scraper

Python
1
star
35

booru-tags-vscode

TypeScript
1
star
36

lingojam

TypeScript
1
star
37

wordle-solver

Wordle Solver with Deno
TypeScript
1
star
38

mangas

A python library for scraping mangas
Python
1
star
39

stablelm_lora

Python
1
star
40

onionskey

Misskey over Tor
TypeScript
1
star
41

noexes-code-builder

Build cheat code from noexes pointer
TypeScript
1
star