Commit
·
4d25a21
0
Parent(s):
Duplicate from ControlNet-1-1-preview/control_v11p_sd15s2_lineart_anime
Browse files- .gitattributes +34 -0
- README.md +152 -0
- config.json +42 -0
- control_net_lineart_anime.py +52 -0
- diffusion_pytorch_model.bin +3 -0
- diffusion_pytorch_model.fp16.bin +3 -0
- diffusion_pytorch_model.fp16.safetensors +3 -0
- diffusion_pytorch_model.safetensors +3 -0
- images/control.png +0 -0
- images/image_out.png +0 -0
- images/input.png +0 -0
- sd.png +0 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: openrail
|
3 |
+
base_model: runwayml/stable-diffusion-v1-5
|
4 |
+
tags:
|
5 |
+
- art
|
6 |
+
- controlnet
|
7 |
+
- stable-diffusion
|
8 |
+
duplicated_from: ControlNet-1-1-preview/control_v11p_sd15s2_lineart_anime
|
9 |
+
---
|
10 |
+
|
11 |
+
# Controlnet - v1.1 - *lineart_anime Version*
|
12 |
+
|
13 |
+
**Controlnet v1.1** is the successor model of [Controlnet v1.0](https://huggingface.co/lllyasviel/ControlNet)
|
14 |
+
and was released in [lllyasviel/ControlNet-v1-1](https://huggingface.co/lllyasviel/ControlNet-v1-1) by [Lvmin Zhang](https://huggingface.co/lllyasviel).
|
15 |
+
|
16 |
+
This checkpoint is a conversion of [the original checkpoint](https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15s2_lineart_anime.pth) into `diffusers` format.
|
17 |
+
It can be used in combination with **Stable Diffusion**, such as [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5).
|
18 |
+
|
19 |
+
|
20 |
+
For more details, please also have a look at the [🧨 Diffusers docs](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/controlnet).
|
21 |
+
|
22 |
+
|
23 |
+
ControlNet is a neural network structure to control diffusion models by adding extra conditions.
|
24 |
+
|
25 |
+

|
26 |
+
|
27 |
+
This checkpoint corresponds to the ControlNet conditioned on **lineart_anime images**.
|
28 |
+
|
29 |
+
## Model Details
|
30 |
+
- **Developed by:** Lvmin Zhang, Maneesh Agrawala
|
31 |
+
- **Model type:** Diffusion-based text-to-image generation model
|
32 |
+
- **Language(s):** English
|
33 |
+
- **License:** [The CreativeML OpenRAIL M license](https://huggingface.co/spaces/CompVis/stable-diffusion-license) is an [Open RAIL M license](https://www.licenses.ai/blog/2022/8/18/naming-convention-of-responsible-ai-licenses), adapted from the work that [BigScience](https://bigscience.huggingface.co/) and [the RAIL Initiative](https://www.licenses.ai/) are jointly carrying in the area of responsible AI licensing. See also [the article about the BLOOM Open RAIL license](https://bigscience.huggingface.co/blog/the-bigscience-rail-license) on which our license is based.
|
34 |
+
- **Resources for more information:** [GitHub Repository](https://github.com/lllyasviel/ControlNet), [Paper](https://arxiv.org/abs/2302.05543).
|
35 |
+
- **Cite as:**
|
36 |
+
|
37 |
+
@misc{zhang2023adding,
|
38 |
+
title={Adding Conditional Control to Text-to-Image Diffusion Models},
|
39 |
+
author={Lvmin Zhang and Maneesh Agrawala},
|
40 |
+
year={2023},
|
41 |
+
eprint={2302.05543},
|
42 |
+
archivePrefix={arXiv},
|
43 |
+
primaryClass={cs.CV}
|
44 |
+
}
|
45 |
+
|
46 |
+
## Introduction
|
47 |
+
|
48 |
+
Controlnet was proposed in [*Adding Conditional Control to Text-to-Image Diffusion Models*](https://arxiv.org/abs/2302.05543) by
|
49 |
+
Lvmin Zhang, Maneesh Agrawala.
|
50 |
+
|
51 |
+
The abstract reads as follows:
|
52 |
+
|
53 |
+
*We present a neural network structure, ControlNet, to control pretrained large diffusion models to support additional input conditions.
|
54 |
+
The ControlNet learns task-specific conditions in an end-to-end way, and the learning is robust even when the training dataset is small (< 50k).
|
55 |
+
Moreover, training a ControlNet is as fast as fine-tuning a diffusion model, and the model can be trained on a personal devices.
|
56 |
+
Alternatively, if powerful computation clusters are available, the model can scale to large amounts (millions to billions) of data.
|
57 |
+
We report that large diffusion models like Stable Diffusion can be augmented with ControlNets to enable conditional inputs like edge maps, segmentation maps, keypoints, etc.
|
58 |
+
This may enrich the methods to control large diffusion models and further facilitate related applications.*
|
59 |
+
|
60 |
+
## Example
|
61 |
+
|
62 |
+
It is recommended to use the checkpoint with [Stable Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5) as the checkpoint
|
63 |
+
has been trained on it.
|
64 |
+
Experimentally, the checkpoint can be used with other diffusion models such as dreamboothed stable diffusion.
|
65 |
+
|
66 |
+
**Note**: If you want to process an image to create the auxiliary conditioning, external dependencies are required as shown below:
|
67 |
+
|
68 |
+
1. Install https://github.com/patrickvonplaten/controlnet_aux
|
69 |
+
|
70 |
+
```sh
|
71 |
+
$ pip install controlnet_aux==0.3.0
|
72 |
+
```
|
73 |
+
|
74 |
+
2. Let's install `diffusers` and related packages:
|
75 |
+
|
76 |
+
```
|
77 |
+
$ pip install diffusers transformers accelerate
|
78 |
+
```
|
79 |
+
|
80 |
+
3. Run code:
|
81 |
+
|
82 |
+
```python
|
83 |
+
import torch
|
84 |
+
import os
|
85 |
+
from huggingface_hub import HfApi
|
86 |
+
from pathlib import Path
|
87 |
+
from diffusers.utils import load_image
|
88 |
+
from PIL import Image
|
89 |
+
import numpy as np
|
90 |
+
from controlnet_aux import LineartAnimeDetector
|
91 |
+
from transformers import CLIPTextModel
|
92 |
+
|
93 |
+
from diffusers import (
|
94 |
+
ControlNetModel,
|
95 |
+
StableDiffusionControlNetPipeline,
|
96 |
+
UniPCMultistepScheduler,
|
97 |
+
)
|
98 |
+
|
99 |
+
checkpoint = "lllyasviel/control_v11p_sd15s2_lineart_anime"
|
100 |
+
|
101 |
+
image = load_image(
|
102 |
+
"https://huggingface.co/lllyasviel/control_v11p_sd15s2_lineart_anime/resolve/main/images/input.png"
|
103 |
+
)
|
104 |
+
image = image.resize((512, 512))
|
105 |
+
|
106 |
+
prompt = "A warrior girl in the jungle"
|
107 |
+
processor = LineartAnimeDetector.from_pretrained("lllyasviel/Annotators")
|
108 |
+
|
109 |
+
control_image = processor(image)
|
110 |
+
control_image.save("./images/control.png")
|
111 |
+
|
112 |
+
# we skip one layer of the encoder
|
113 |
+
text_encoder = CLIPTextModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="text_encoder", num_hidden_layers=11, torch_dtype=torch.float16)
|
114 |
+
|
115 |
+
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
|
116 |
+
|
117 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
118 |
+
"runwayml/stable-diffusion-v1-5", text_encoder=text_encoder, controlnet=controlnet, torch_dtype=torch.float16
|
119 |
+
)
|
120 |
+
|
121 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
122 |
+
pipe.enable_model_cpu_offload()
|
123 |
+
|
124 |
+
generator = torch.manual_seed(0)
|
125 |
+
image = pipe(prompt, num_inference_steps=30, generator=generator, image=control_image).images[0]
|
126 |
+
|
127 |
+
image.save('images/image_out.png')
|
128 |
+
|
129 |
+
```
|
130 |
+
|
131 |
+

|
132 |
+
|
133 |
+

|
134 |
+
|
135 |
+

|
136 |
+
|
137 |
+
## Other released checkpoints v1-1
|
138 |
+
|
139 |
+
The authors released 14 different checkpoints, each trained with [Stable Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5)
|
140 |
+
on a different type of conditioning:
|
141 |
+
|
142 |
+
| Model Name | Control Image Overview| Control Image Example | Generated Image Example |
|
143 |
+
|---|---|---|---|
|
144 |
+
TODO
|
145 |
+
|
146 |
+
### Training
|
147 |
+
|
148 |
+
TODO
|
149 |
+
|
150 |
+
### Blog post
|
151 |
+
|
152 |
+
For more information, please also have a look at the [Diffusers ControlNet Blog Post](https://huggingface.co/blog/controlnet).
|
config.json
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_class_name": "ControlNetModel",
|
3 |
+
"_diffusers_version": "0.16.0.dev0",
|
4 |
+
"_name_or_path": "/home/patrick/controlnet_v1_1/control_v11p_sd15s2_lineart_anime",
|
5 |
+
"act_fn": "silu",
|
6 |
+
"attention_head_dim": 8,
|
7 |
+
"block_out_channels": [
|
8 |
+
320,
|
9 |
+
640,
|
10 |
+
1280,
|
11 |
+
1280
|
12 |
+
],
|
13 |
+
"class_embed_type": null,
|
14 |
+
"conditioning_embedding_out_channels": [
|
15 |
+
16,
|
16 |
+
32,
|
17 |
+
96,
|
18 |
+
256
|
19 |
+
],
|
20 |
+
"controlnet_conditioning_channel_order": "rgb",
|
21 |
+
"cross_attention_dim": 768,
|
22 |
+
"down_block_types": [
|
23 |
+
"CrossAttnDownBlock2D",
|
24 |
+
"CrossAttnDownBlock2D",
|
25 |
+
"CrossAttnDownBlock2D",
|
26 |
+
"DownBlock2D"
|
27 |
+
],
|
28 |
+
"downsample_padding": 1,
|
29 |
+
"flip_sin_to_cos": true,
|
30 |
+
"freq_shift": 0,
|
31 |
+
"in_channels": 4,
|
32 |
+
"layers_per_block": 2,
|
33 |
+
"mid_block_scale_factor": 1,
|
34 |
+
"norm_eps": 1e-05,
|
35 |
+
"norm_num_groups": 32,
|
36 |
+
"num_class_embeds": null,
|
37 |
+
"only_cross_attention": false,
|
38 |
+
"projection_class_embeddings_input_dim": null,
|
39 |
+
"resnet_time_scale_shift": "default",
|
40 |
+
"upcast_attention": false,
|
41 |
+
"use_linear_projection": false
|
42 |
+
}
|
control_net_lineart_anime.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import torch
|
3 |
+
import os
|
4 |
+
from huggingface_hub import HfApi
|
5 |
+
from pathlib import Path
|
6 |
+
from diffusers.utils import load_image
|
7 |
+
from controlnet_aux import LineartAnimeDetector
|
8 |
+
from transformers import CLIPTextModel
|
9 |
+
|
10 |
+
from diffusers import (
|
11 |
+
ControlNetModel,
|
12 |
+
StableDiffusionControlNetPipeline,
|
13 |
+
UniPCMultistepScheduler,
|
14 |
+
)
|
15 |
+
import sys
|
16 |
+
|
17 |
+
checkpoint = sys.argv[1]
|
18 |
+
|
19 |
+
url = "https://static.wikia.nocookie.net/unanything/images/a/a0/Unnamed.png/revision/latest/scale-to-width-down/350?cb=20230326002111"
|
20 |
+
image = load_image(url)
|
21 |
+
|
22 |
+
prompt = "warrior girl"
|
23 |
+
|
24 |
+
processor = LineartAnimeDetector.from_pretrained("lllyasviel/Annotators")
|
25 |
+
image = processor(image)
|
26 |
+
image.save("/home/patrick/images/check.png")
|
27 |
+
|
28 |
+
text_encoder = CLIPTextModel.from_pretrained("Linaqruf/anything-v3.0", subfolder="text_encoder", num_hidden_layers=11, torch_dtype=torch.float16)
|
29 |
+
|
30 |
+
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
|
31 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
32 |
+
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, text_encoder=text_encoder, torch_dtype=torch.float16
|
33 |
+
)
|
34 |
+
|
35 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
36 |
+
pipe.enable_model_cpu_offload()
|
37 |
+
|
38 |
+
generator = torch.manual_seed(33)
|
39 |
+
out_image = pipe(prompt, num_inference_steps=25, generator=generator, image=image).images[0]
|
40 |
+
|
41 |
+
path = os.path.join(Path.home(), "images", "aa.png")
|
42 |
+
out_image.save(path)
|
43 |
+
|
44 |
+
api = HfApi()
|
45 |
+
|
46 |
+
api.upload_file(
|
47 |
+
path_or_fileobj=path,
|
48 |
+
path_in_repo=path.split("/")[-1],
|
49 |
+
repo_id="patrickvonplaten/images",
|
50 |
+
repo_type="dataset",
|
51 |
+
)
|
52 |
+
print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")
|
diffusion_pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a93db77e1cac8d298d4313c183d942ffbb51c61e77104d7f17ef70217638d09b
|
3 |
+
size 1445254969
|
diffusion_pytorch_model.fp16.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4e628ab978db5d0094f3ab9a8608b44a8715e3bfe4c4ef425cb244d0f8d70f25
|
3 |
+
size 722698343
|
diffusion_pytorch_model.fp16.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d9619372316fb8ade82353be0c2b7821fa1da60ae3842d8c99afacf1d45ff73f
|
3 |
+
size 722598642
|
diffusion_pytorch_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6d55de2de4cd8813b88e0fb603e52616c9e5ee6cb019e28f0f64ef370e363fff
|
3 |
+
size 1445157124
|
images/control.png
ADDED
![]() |
images/image_out.png
ADDED
![]() |
images/input.png
ADDED
![]() |
sd.png
ADDED
![]() |