commit c4445cb905f780c3aea31c091ac6172a75ac9911 Author: ailab Date: Sat Jun 8 02:54:42 2024 +0800 first commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ce9cadb --- /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-medium-couple.png filter=lfs diff=lfs merge=lfs -text +cann-medium-hf-ofice.png filter=lfs diff=lfs merge=lfs -text +cann-medium-megatron.png filter=lfs diff=lfs merge=lfs -text +cann-medium-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..502b4e3 --- /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 5x 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-medium-hf-ofice.png) + +prompt: a woman, close up, detailed, beautiful, street photography, photorealistic, detailed, Kodak ektar 100, natural, candid shot +![images_1)](./cann-medium-woman.png) + +prompt: megatron in an apocalyptic world ground, runied city in the background, photorealistic +![images_2)](./cann-medium-megatron.png) + +prompt: a couple watching sunset, 4k photo +![images_3)](./cann-medium-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-mid", + 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-medium-couple.png b/cann-medium-couple.png new file mode 100644 index 0000000..42a4588 --- /dev/null +++ b/cann-medium-couple.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca8723fad4a8a25466006f6c3823575688c100335b507875032e2bd535541d21 +size 7363709 diff --git a/cann-medium-hf-ofice.png b/cann-medium-hf-ofice.png new file mode 100644 index 0000000..9c985b0 --- /dev/null +++ b/cann-medium-hf-ofice.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9098a7eb88934e241ea085825ad22ef2bc29f66c2029ed75710cb21d31a87acc +size 7349269 diff --git a/cann-medium-megatron.png b/cann-medium-megatron.png new file mode 100644 index 0000000..a3fd9b4 --- /dev/null +++ b/cann-medium-megatron.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d9cf0d931c7fda4f57f51a8bd7ccd81880e819bf595320a6eeef2cd097ef24d +size 4343604 diff --git a/cann-medium-woman.png b/cann-medium-woman.png new file mode 100644 index 0000000..9a8a110 --- /dev/null +++ b/cann-medium-woman.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07d2608c9e097ec103af1d6f755e5466c859fe084458130936f7177f747049bc +size 7032291 diff --git a/config.json b/config.json new file mode 100644 index 0000000..d2cb05f --- /dev/null +++ b/config.json @@ -0,0 +1,57 @@ +{ + "_class_name": "ControlNetModel", + "_diffusers_version": "0.20.0.dev0", + "_name_or_path": "valhalla/c-n-1a", + "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", + "CrossAttnDownBlock2D", + "CrossAttnDownBlock2D" + ], + "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, + 1 + ], + "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..ac9b20d --- /dev/null +++ b/diffusion_pytorch_model.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97c9bedfe1f595ed9c3a2a410d07f6f26a36704bd30389fda37d6a025de0889e +size 1090432353 diff --git a/diffusion_pytorch_model.fp16.bin b/diffusion_pytorch_model.fp16.bin new file mode 100644 index 0000000..e510483 --- /dev/null +++ b/diffusion_pytorch_model.fp16.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9acc477f99bd7da9fd2b6f2d9c8ce5a00f9dd7907951985c3d535037b61d539c +size 545261387 diff --git a/diffusion_pytorch_model.fp16.safetensors b/diffusion_pytorch_model.fp16.safetensors new file mode 100644 index 0000000..c37b0bc --- /dev/null +++ b/diffusion_pytorch_model.fp16.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15d4d3dd9f7c8dca5fad38f16b0fa18c71ca83008359a47919689680b8b844fe +size 545197729 diff --git a/diffusion_pytorch_model.safetensors b/diffusion_pytorch_model.safetensors new file mode 100644 index 0000000..65fe2c3 --- /dev/null +++ b/diffusion_pytorch_model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b204159b430458045412807de55d52bfaeb7b55af8781072e4bda2060b5a703 +size 1090369822 diff --git a/hug_lab_grid.png b/hug_lab_grid.png new file mode 100644 index 0000000..ab26a62 --- /dev/null +++ b/hug_lab_grid.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aba1927620761eff5b6a5821a18f1b7732c5eacd72492a5596bb3fcb45368235 +size 1986596