Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to transfer controlnet to your own model: Update readme #35

Closed
specblades opened this issue Feb 14, 2023 · 21 comments
Closed

How to transfer controlnet to your own model: Update readme #35

specblades opened this issue Feb 14, 2023 · 21 comments
Labels
documentation Improvements or additions to documentation

Comments

@specblades
Copy link

Please, add more detailed tutorial how to transfer controlnet to your own model

@Mikubill Mikubill added the documentation Improvements or additions to documentation label Feb 14, 2023
@2blackbar
Copy link

2blackbar commented Feb 14, 2023

I think each model for use with this code it has built in SD1.5 + its own weights for features detection, but it ignores its own SD1.5 and uses your modl from get go when you use this repo code...
What i would like instead is separating feature detection weights from SD1.5 so the file is smaller loads faster and then it would work the same as its working now ( isuppose) It kinda loads SD1.5 twice when you use it on plain 1.5 model from what i read

@Mikubill
Copy link
Owner

separating feature detection weights from SD1.5

use https://github.com/Mikubill/sd-webui-controlnet/blob/main/extract_controlnet.py

@2blackbar
Copy link

thats grat ill use it and report if it works

@nasenbaer43
Copy link

Unless I don' tunderstand it: the script extracts the controlnet from the 5.7 GB files (see https://huggingface.co/lllyasviel/ControlNet/tree/main/models). I guess the resulting files will be quite smaller?

Is there any chance that someone who has already downloaded all these models to please upload the extracted results somewhere?

Seems like a bit of "waste" for everyone to download 7 * 5.7 GB.

@2blackbar
Copy link

WORKED !!! Thanks a lot !!!
For anyone else , make bat file and place in models directory, then run it, bat looks like this inside , just change path to yours and change names accordingly
python extract_controlnet.py --src F:\sd\extensions\sd-webui-controlnet\models\control_sd15_canny.pth --dst F:\sd\extensions\sd-webui-controlnet\models\control_canny.pth

@2blackbar
Copy link

2blackbar commented Feb 14, 2023

Unless I don' tunderstand it: the script extracts the controlnet from the 5.7 GB files (see https://huggingface.co/lllyasviel/ControlNet/tree/main/models). I guess the resulting files will be quite smaller?

Is there any chance that someone who has already downloaded all these models to please upload the extracted results somewhere?

Seems like a bit of "waste" for everyone to download 7 * 5.7 GB.

i posted how to do it in post above , make bat file and just run it, its easy, im going to extract more, you can do it on your own and it gives you 1.4gb model not 5.6gb modl, so it saves VRAM and loads fast , tested and works.
Imo they should upload these to huggingface repo...

@nasenbaer43
Copy link

Sorry you misunderstood me. I was talking about the extracted models, aka your 1.4 GB files.
Of course I can download the 5.7 GB files and extract them myself :)

Since you already did it: any chance you can please upload them anywhere?

@2blackbar
Copy link

Sorry you misunderstood me. I was talking about the extracted models, aka your 1.4 GB files. Of course I can download the 5.7 GB files and extract them myself :)

Since you already did it: any chance you can please upload them anywhere?

Here you have 3, you want more try to convert with the way i posted , its really very easy
https://drive.google.com/file/d/1iVlm_LDOiCirGnxrGrzZtVyJf2PeMvoR/view?usp=share_link
https://drive.google.com/file/d/13BerWa0M_jpvWOiLvxJd5zqadkZ8hZwd/view?usp=share_link
https://drive.google.com/file/d/1sfyZH8N_7lWbFBb8Pb_9J_6o9g3q3yJt/view?usp=share_link

@MadLightTheDoggo
Copy link

WORKED !!! Thanks a lot !!! For anyone else , make bat file and place in models directory, then run it, bat looks like this inside , just change path to yours and change names accordingly python extract_controlnet.py --src F:\sd\extensions\sd-webui-controlnet\models\control_sd15_canny.pth --dst F:\sd\extensions\sd-webui-controlnet\models\control_canny.pth

You have to place the .bat into the directory with extract_controlnet.py and NOT INTO \models\ folder.

@Hetaneko
Copy link

Hetaneko commented Feb 14, 2023

here i uploaded the trimmed models with safetensors format
https://huggingface.co/Hetaneko/Controlnet-models/tree/main/controlnet_safetensors

@Echolink50
Copy link

here i uploaded the trimmed models with safetensors format https://huggingface.co/Hetaneko/Controlnet-models/tree/main/controlnet_safetensors

Sweet. Thanks a lot

@ClashSAN
Copy link
Contributor

here's pruned f16 safetensors set - https://huggingface.co/webui/ControlNet-modules-safetensors/tree/main

@cerarslan
Copy link

Excuse me guys, what is use case of above the models? Just merge our custom models with those?

@Echolink50
Copy link

Excuse me guys, what is use case of above the models? Just merge our custom models with those?

No. Just leave your chosen model selected in it's usual location. Load your chosen preprocessor and controlnet model in the drop-down menu

@GrennKren
Copy link

here's pruned f16 safetensors set - https://huggingface.co/webui/ControlNet-modules-safetensors/tree/main

take off sunglasses
Oh my..

@paulo-coronado
Copy link

paulo-coronado commented Feb 23, 2023

Excuse me guys, but I think the initial question was how to transfer ControlNet to a custom model (such as Anythingv3, RealisticVision, Deliberate etc.). I found amazing how you extract the weights and reduce the file size, but I would like to know how @Mikubill transferred ControlNet to a model, did he merged SD15Model + ControlNet?... I used this guide to create a control_any3_openpose.pth file. However, I compared the images created by this model and by ControlNet extension (by @Mikubill), using same seed and configs, and the results are a bit different... I don't know why... any thoughts?

These are the results I got (same prompt, seed etc.):
Blank 2 Grids Collage (1)

@deifos
Copy link

deifos commented Mar 5, 2023

@paulo-coronado I'm looking for the same thing how can I merge a controlnet model to my custom one, where you able to get that going?

@paulo-coronado
Copy link

paulo-coronado commented Mar 5, 2023

@deifos Hey brother! You can merge by following this guide. Although, the author is not recommending merging that way anymore, because the results are a little bit different. The recommendation is to use A1111 and its API. If you really need to merge them using the tool_transfer will make the job nicely!

@deifos
Copy link

deifos commented Mar 5, 2023

@deifos Hey brother! You can merge by following this guide. Although, the author is not recommending merging that way anymore, because the results are a little bit different. The recommendation is to use A1111 and its API. If you really need to merge them using the tool_transfer will make the job nicely!

Thank man, I was able to merge it but how did you use it, did you load it inside the controlnet/models folder or the stable diffusion models folder because it does not seem to have any effect on my generations.

@paulo-coronado
Copy link

I am not sure if you can use it in A1111 (maybe replacing control_canny-fp16.safetensors with your merged model). The way lllyasviel created was to use it in gradio_pose2image.py - just replace the following line as the guide suggests:

model.load_state_dict(load_state_dict('./models/control_any3_openpose.pth', location='cpu'))

@alelordelo
Copy link

WORKED !!! Thanks a lot !!!
For anyone else , make bat file and place in models directory, then run it, bat looks like this inside , just change path to yours and change names accordingly
python extract_controlnet.py --src F:\sd\extensions\sd-webui-controlnet\models\control_sd15_canny.pth --dst F:\sd\extensions\sd-webui-controlnet\models\control_canny.pth

HI @2blackbar and @paulo-coronado ,

I tried now to extract but the converted.ckpt model has the same size ocustomtrainedCN.ckpt, which is 8.5GB.

Shouldn't this reduce the file size?

reported issue here:
#895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests