EditAnything icon indicating copy to clipboard operation
EditAnything copied to clipboard

Convert your ControlNet model to A1111/lllyasviel format

Open continue-revolution opened this issue 1 year ago • 19 comments

I am the author of sd-webui-segment-anything. The only thing your work is not compatible with Mikubill ControlNet extension and my SAM extension is your ControlNet model format. Please convert your ControlNet model to lllyasviel format, similar to this (1 yaml + 1 model state dict, the state dict keys should be the same as other models here, the yaml filename should be the same as the model filename, except the file extension) and your work can soon be compatible with A1111 sd-webui and be accessible to the broad stable diffusion community.

continue-revolution avatar Apr 19 '23 21:04 continue-revolution

The model is converted to support diffusers package. Do you mean that you need the unconverted model?

gasvn avatar Apr 20 '23 09:04 gasvn

Yes

continue-revolution avatar Apr 20 '23 09:04 continue-revolution

I have an old ckpt in hugglingface: https://huggingface.co/shgao/edit-anything-v0-1/tree/main And the config file is https://github.com/sail-sg/EditAnything/blob/main/models/cldm_v21.yaml Can you please check if these two files are want you need. If so, I'll update the hugglingface and upload the new model with this format. Thanks~

gasvn avatar Apr 21 '23 03:04 gasvn

I have checked. Just need one more step which is something like this. I do not need base model. Thanks for your help.

BTW, do you think your model can work for SD1.5? The majority of community models are based on sd1.5, so if your models are compatible with SD1.5, it would be very appealing to the SD community (including a large amount of non-research, or even non-CS people).

import torch
sd = torch.load('../tmp/edit-anything-ckpt-v0-1.ckpt')['state_dict']
idx = 0
sd_cnet_only = {}
for key, val in sd.items():
    if 'control_model' in key:
        sd_cnet_only[key] = val
torch.save(sd_cnet_only, '../tmp/control_v11p_sd15_sam.pth')

continue-revolution avatar Apr 25 '23 21:04 continue-revolution

Thanks, I will upload a new model with the required form. And I can train a SD1.5 model for the community. I will keep you updated once I finished the training.

gasvn avatar Apr 26 '23 06:04 gasvn

@continue-revolution hi, I have trained new sam condition models based on sd15 and sd21. These models are trained with more images and longer iterations. I have converted the format as you requested https://huggingface.co/shgao/edit-anything-v0-4-lllyasviel-format/tree/main

gasvn avatar May 01 '23 13:05 gasvn

Thank you very much, this is very helpful. I will test and update a tutorial for people who use A1111 SD webui. Appreciate your effort and contribution.

continue-revolution avatar May 01 '23 16:05 continue-revolution

@continue-revolution , did you port this to A1111 SD webui? : )

alelordelo avatar May 05 '23 17:05 alelordelo

Yes, but there seem to be some problem since I didn’t get the expected performance. I suspect that my code for detect map (control image) might be problematic and I have to try their demo to see what their detection map looks like, but recently I fell into an extremely busy life so that I have not tried their demo yet. I cannot give you an exact time on when it could me available, but if @gasvn can show me a detect map for a sample image then the progress could be significantly speed up.

continue-revolution avatar May 05 '23 19:05 continue-revolution

@continue-revolution Can you share me with the code link so I can check it?

gasvn avatar May 06 '23 03:05 gasvn

https://github.com/continue-revolution/sd-webui-segment-anything/blob/master/scripts/auto.py#L73-L93

Another probably useful way is to show me a detect map (not random segmentation, I know that is not detect map) for whatever image

continue-revolution avatar May 06 '23 03:05 continue-revolution

Sorry for the late reply. You can copy the function in https://github.com/sail-sg/EditAnything/blob/10374ef2a9fc92e272691c38d8cbd39f15ddf45c/sam2edit_lora.py#L354 to replace your sam condition generation.

gasvn avatar May 10 '23 08:05 gasvn

https://github.com/sail-sg/EditAnything/blob/main/sam2image.py#L95

It seems that this line is unnecessary. Why did you ever sort it?

continue-revolution avatar May 22 '23 06:05 continue-revolution

I was finally able to create some meaningful image. I will soon be publishing this support to my extension

Edit: published

continue-revolution avatar May 22 '23 12:05 continue-revolution

@continue-revolution , the plugin is for SAM generated map -> SD -> output? Can you prompt per mask region?

alelordelo avatar May 22 '23 12:05 alelordelo

@alelordelo you can do this one time per each mask region. I will look into the controlnet source code to see if it is possible to generate one image with different condition/uncondition for different mask regions.

continue-revolution avatar May 22 '23 12:05 continue-revolution

@alelordelo Today I looked into the source code of A1111 and I would say yes, it IS possible to do this. I think your proposal is really cool and will be supported in near furture.

continue-revolution avatar May 31 '23 12:05 continue-revolution

awesome! I am working on a dataset for this. DO you think COCO JSON would be a good fit?

alelordelo avatar Jun 08 '23 17:06 alelordelo

@continue-revolution

alelordelo avatar Jun 08 '23 17:06 alelordelo