Canny Edge Detection StableDiffusionControlNet and StableDiffusionControlNetImg2Img Pipelines #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The changes include adding the
StableDiffusionControlNet
pipeline, specifically the Canny Edge Detection model along with the pre-processing function required to get the ControlNet input image which is done using OpenCV.js. The ControlNet pipeline is similar to the Image-To-Image pipeline since they both require an image as input. The main difference between them is that the Image-To-Image pipeline takes the input image with added noise and uses it as the input latent instead of random noise and the ControlNet pipeline takes the input image and other arguments as input to the ControlNet model which returns outputs (down block samples and middle block sample) that are used as input to the UNET model. The shape of the ControlNet inputs were taken from here and the shape of the UNET inputs were inferred based on the shapes and not the names.In addition, the Image-To-Image feature was added to the
StableDiffusionControlNet
pipeline which resulted in the creation of theStableDiffusionControlNetImg2Img
pipeline.Convert Command
The command that I used to convert the model was:
python conv_sd_to_onnx.py --model_path "runwayml/stable-diffusion-v1-5" --output_path "./model/sd1-5_fp16_cn_canny" --controlnet_path "lllyasviel/control_v11p_sd15_canny" --fp16 --attention-slicing auto
from the converter that you use.Specific Changes
src/pipelines/StableDiffusionControlNetPipeline.ts
file.getRgbData()
anduploadImage()
functions inexamples/react/src/App.tsx
to account for ControlNet image upload.@techstark/opencv-js
andreact-app-rewired
packages to theexamples/react/package.json
file and replace somereact-scripts
withreact-app-rewired
in order to use the OpenCV.js functions.examples/react/config-overrides.js
file which is necessary to use OpenCV.js. Taken from here.Pre-Processing Libraries
In this section I'll include all of the pre-processing libraries that I found in case you want to use another one or add other ControlNet model:
Issues / Future Work