From 381603471e094841c1e5a709a21f9adaf33b0fc1 Mon Sep 17 00:00:00 2001 From: ailab Date: Sat, 8 Jun 2024 02:42:16 +0800 Subject: [PATCH] first commit --- .gitattributes | 40 +++++++++ README.md | 108 +++++++++++++++++++++++ cann-small-couple.png | 3 + cann-small-hf-ofice.png | 3 + cann-small-megatron.png | 3 + cann-small-woman.png | 3 + config.json | 57 ++++++++++++ diffusion_pytorch_model.bin | 3 + diffusion_pytorch_model.fp16.bin | 3 + diffusion_pytorch_model.fp16.safetensors | 3 + diffusion_pytorch_model.safetensors | 3 + hug_lab_grid.png | 3 + 12 files changed, 232 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 cann-small-couple.png create mode 100644 cann-small-hf-ofice.png create mode 100644 cann-small-megatron.png create mode 100644 cann-small-woman.png create mode 100644 config.json create mode 100644 diffusion_pytorch_model.bin create mode 100644 diffusion_pytorch_model.fp16.bin create mode 100644 diffusion_pytorch_model.fp16.safetensors create mode 100644 diffusion_pytorch_model.safetensors create mode 100644 hug_lab_grid.png diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..13b50dc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,40 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +cann-small-couple.png filter=lfs diff=lfs merge=lfs -text +cann-small-hf-ofice.png filter=lfs diff=lfs merge=lfs -text +cann-small-megatron.png filter=lfs diff=lfs merge=lfs -text +cann-small-woman.png filter=lfs diff=lfs merge=lfs -text +hug_lab_grid.png filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000..880d504 --- /dev/null +++ b/README.md @@ -0,0 +1,108 @@ +--- +license: openrail++ +base_model: stabilityai/stable-diffusion-xl-base-1.0 +tags: +- stable-diffusion-xl +- stable-diffusion-xl-diffusers +- text-to-image +- diffusers +- controlnet +inference: false +--- + +# Small SDXL-controlnet: Canny + +These are small controlnet weights trained on stabilityai/stable-diffusion-xl-base-1.0 with canny conditioning. This checkpoint is 7x smaller than the original XL controlnet checkpoint. +You can find some example images in the following. + +prompt: aerial view, a futuristic research complex in a bright foggy jungle, hard lighting +![images_0)](./cann-small-hf-ofice.png) + +prompt: a woman, close up, detailed, beautiful, street photography, photorealistic, detailed, Kodak ektar 100, natural, candid shot +![images_1)](./cann-small-woman.png) + +prompt: megatron in an apocalyptic world ground, runied city in the background, photorealistic +![images_2)](./cann-small-megatron.png) + +prompt: a couple watching sunset, 4k photo +![images_3)](./cann-small-couple.png) + + +## Usage + +Make sure to first install the libraries: + +```bash +pip install accelerate transformers safetensors opencv-python diffusers +``` + +And then we're ready to go: + +```python +from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL +from diffusers.utils import load_image +from PIL import Image +import torch +import numpy as np +import cv2 + +prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting" +negative_prompt = "low quality, bad quality, sketches" + +image = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png") + +controlnet_conditioning_scale = 0.5 # recommended for good generalization + +controlnet = ControlNetModel.from_pretrained( + "diffusers/controlnet-canny-sdxl-1.0-small", + torch_dtype=torch.float16 +) +vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16) +pipe = StableDiffusionXLControlNetPipeline.from_pretrained( + "stabilityai/stable-diffusion-xl-base-1.0", + controlnet=controlnet, + vae=vae, + torch_dtype=torch.float16, +) +pipe.enable_model_cpu_offload() + +image = np.array(image) +image = cv2.Canny(image, 100, 200) +image = image[:, :, None] +image = np.concatenate([image, image, image], axis=2) +image = Image.fromarray(image) + +images = pipe( + prompt, negative_prompt=negative_prompt, image=image, controlnet_conditioning_scale=controlnet_conditioning_scale, +).images + +images[0].save(f"hug_lab.png") +``` + +![hug_lab_grid)](./hug_lab_grid.png) + +To more details, check out the official documentation of [`StableDiffusionXLControlNetPipeline`](https://huggingface.co/docs/diffusers/main/en/api/pipelines/controlnet_sdxl). + +🚨 Please note that this checkpoint is experimental and there's a lot of room for improvement. We encourage the community to build on top of it, improve it, and provide us with feedback. 🚨 + +### Training + +Our training script was built on top of the official training script that we provide [here](https://github.com/huggingface/diffusers/blob/main/examples/controlnet/README_sdxl.md). +You can refer to [this script](https://github.com/huggingface/diffusers/blob/7b93c2a882d8e12209fbaeffa51ee2b599ab5349/examples/research_projects/controlnet/train_controlnet_webdataset.py) for full discolsure. + +* This checkpoint does not perform distillation. We just use a smaller ControlNet initialized from the SDXL UNet. We +encourage the community to try and conduct distillation too. This resource might be of help in [this regard](https://huggingface.co/blog/sd_distillation). +* To learn more about how the ControlNet was initialized, refer to [this code block](https://github.com/huggingface/diffusers/blob/7b93c2a882d8e12209fbaeffa51ee2b599ab5349/examples/research_projects/controlnet/train_controlnet_webdataset.py#L981C1-L999C36). +* It does not have any attention blocks. +* The model works pretty good on most conditioning images. But for more complex conditionings, the bigger checkpoints might be better. We are still working on improving the quality of this checkpoint and looking for feedback from the community. +* We recommend playing around with the `controlnet_conditioning_scale` and `guidance_scale` arguments for potentially better +image generation quality. + +#### Training data +The model was trained on 3M images from LAION aesthetic 6 plus subset, with batch size of 256 for 50k steps with constant learning rate of 3e-5. + +#### Compute +One 8xA100 machine + +#### Mixed precision +FP16 \ No newline at end of file diff --git a/cann-small-couple.png b/cann-small-couple.png new file mode 100644 index 0000000..13d665b --- /dev/null +++ b/cann-small-couple.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:513454e60d9d10714601841c16ad054927adb0e5a4644c49b6bb43f1c1410f10 +size 5943286 diff --git a/cann-small-hf-ofice.png b/cann-small-hf-ofice.png new file mode 100644 index 0000000..aadabfd --- /dev/null +++ b/cann-small-hf-ofice.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e8c1f3a4bfba76a87e78575874454ea974a8d3159f5d660f69218837bd96436 +size 5670486 diff --git a/cann-small-megatron.png b/cann-small-megatron.png new file mode 100644 index 0000000..0d8c9b0 --- /dev/null +++ b/cann-small-megatron.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5598120a2aaafc12fd93359476d1ac6c192585d7b0f85750ef13f299ecc6d89 +size 3273165 diff --git a/cann-small-woman.png b/cann-small-woman.png new file mode 100644 index 0000000..6decc48 --- /dev/null +++ b/cann-small-woman.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39f2b8a77d63ca0173a4225e858864ef8ceeaa34360642a3eaac69e6b680f0ed +size 5228775 diff --git a/config.json b/config.json new file mode 100644 index 0000000..c30f69c --- /dev/null +++ b/config.json @@ -0,0 +1,57 @@ +{ + "_class_name": "ControlNetModel", + "_diffusers_version": "0.20.0.dev0", + "_name_or_path": "valhalla/c-n-a-fixed", + "act_fn": "silu", + "addition_embed_type": "text_time", + "addition_embed_type_num_heads": 64, + "addition_time_embed_dim": 256, + "attention_head_dim": [ + 5, + 10, + 20 + ], + "block_out_channels": [ + 320, + 640, + 1280 + ], + "class_embed_type": null, + "conditioning_channels": 3, + "conditioning_embedding_out_channels": [ + 16, + 32, + 96, + 256 + ], + "controlnet_conditioning_channel_order": "rgb", + "cross_attention_dim": 2048, + "down_block_types": [ + "DownBlock2D", + "DownBlock2D", + "DownBlock2D" + ], + "downsample_padding": 1, + "encoder_hid_dim": null, + "encoder_hid_dim_type": null, + "flip_sin_to_cos": true, + "freq_shift": 0, + "global_pool_conditions": false, + "in_channels": 4, + "layers_per_block": 2, + "mid_block_scale_factor": 1, + "norm_eps": 1e-05, + "norm_num_groups": 32, + "num_attention_heads": null, + "num_class_embeds": null, + "only_cross_attention": false, + "projection_class_embeddings_input_dim": 2816, + "resnet_time_scale_shift": "default", + "transformer_layers_per_block": [ + 0, + 0, + 0 + ], + "upcast_attention": null, + "use_linear_projection": true +} diff --git a/diffusion_pytorch_model.bin b/diffusion_pytorch_model.bin new file mode 100644 index 0000000..bc40f76 --- /dev/null +++ b/diffusion_pytorch_model.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dcee8ba42e5f38090b0b7036bd99ed1bc4e62d68cd038dd572fe3705435c9a04 +size 640496521 diff --git a/diffusion_pytorch_model.fp16.bin b/diffusion_pytorch_model.fp16.bin new file mode 100644 index 0000000..ac88a42 --- /dev/null +++ b/diffusion_pytorch_model.fp16.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d46ba4e980e18d39526f7d86b6aafe74d2b1bf3ed97b727bca098b4d4955936 +size 320274895 diff --git a/diffusion_pytorch_model.fp16.safetensors b/diffusion_pytorch_model.fp16.safetensors new file mode 100644 index 0000000..d7d47b8 --- /dev/null +++ b/diffusion_pytorch_model.fp16.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fde4888a5f0a5648118991cc50e0ac4d60a2356dbaddf5e0649dd69c1119a2f9 +size 320237179 diff --git a/diffusion_pytorch_model.safetensors b/diffusion_pytorch_model.safetensors new file mode 100644 index 0000000..19d2534 --- /dev/null +++ b/diffusion_pytorch_model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97b75ce51fae5cfc4d5ea98445292d482d911b241b9a82fd8260dbaa2269031a +size 640459467 diff --git a/hug_lab_grid.png b/hug_lab_grid.png new file mode 100644 index 0000000..ad793a2 --- /dev/null +++ b/hug_lab_grid.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0fd1403e21cc4ddd1229361d2878f88858e104875af8f5e91de13c5e3024ecf4 +size 2082762