Skip to content

Commit ece97a0

Browse files
authored
Merge pull request #57 from intel/version_1_5
Version 1 5
2 parents 17f6f01 + 730ebb6 commit ece97a0

File tree

6 files changed

+652
-36
lines changed

6 files changed

+652
-36
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This branch is currently under development. <br>Dedicated for GIMP 3, Python 3 a
99
[2] Style-Transfer <br>
1010
[3] Inpainting <br>
1111
[4] Semantic-Segmentation <br>
12-
[5] Stable-Diffusion (Suppports - SD 1.4, SD 1.5 (landscape & portrait), SD 1.5 Inpainting, SD 1.5 Controlnet-Openpose) <br>
12+
[5] Stable-Diffusion (Suppports - SD 1.4, SD 1.5 (landscape & portrait), SD 1.5 Inpainting, SD 1.5 Controlnet-OpenPose, SD 1.5 Controlnet-CannyEdge) <br>
1313

1414
# Objectives
1515
[1] Provides a set of OpenVino based plugins that add AI features to GIMP. <br>
@@ -102,6 +102,15 @@ Skip steps 1 and 2 if you already have Python3 and Git on Windows
102102
![](gifs/controlnet-openpose.png)
103103

104104

105+
#### E. Stable-Diffusion-1.5 Controlnet-CannyEdge - Make sure to download and convert the model during install process.
106+
1. Open an image that you want to use for generating the new image. <br>
107+
2. Select Stable Diffusion from the drop down list in layers -> OpenVINO-AI-Plugins <br>
108+
3. Choose the controlnet_canny model and device from the drop down list.<br>
109+
4. Make sure to select -- "Use Initial Image" option from the GUI. If not selected then it will fail.
110+
5. Follow steps 4,5 from section A. <br>
111+
5. Click on “Run Inference”. Wait for the total inference steps to get completed. <br>
112+
113+
105114
*If create gif option is selected, please note that performance will reduce. The generated gif is located in below path. You can play it in GIMP by going to Filters -> Animations -> Playback* <br>
106115
```C:\Users\<user_name>\openvino-ai-plugins-gimp\gif\stable_diffusion.gif``` <br>
107116

choose_sd_model.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,28 @@
2525
print("5 - Landscape_768x512 (768x512 output image), will take time since model is large ")
2626
print("6 - SD-1.5 Inapinting model (512x512 output image) ")
2727
print("7 - SD-1.5 Controlnet-Openpose model (512x512 output image) ")
28-
print("8 - ALL the above SD-1.5 models ")
29-
print("9 - Only Square, Landscape, Portrait")
30-
print("10 - Skip All SD-1.5 Model setup ")
28+
print("8 - SD-1.5 Controlnet-CannyEdge model (512x512 output image) ")
29+
print("9 - ALL the above SD-1.5 models ")
30+
print("10 - Only Square, Landscape, Portrait")
31+
print("11 - Skip All SD-1.5 Model setup ")
3132
choice = input("Enter the Number for the model you want to download & convert: ")
3233

3334
# setup all the SD1.5 models
34-
if choice=="8":
35+
if choice=="9":
3536
for i in range(1,7):
3637

3738
subprocess.call([sd_python_path, chose_model, str(i)])
3839

3940
subprocess.call([sd_python_path, chose_model_controlnet, "7"])
41+
subprocess.call([sd_python_path, chose_model_controlnet, "8"])
4042
break
4143
# setup only square, landscape and Portrait
42-
elif choice=="9":
44+
elif choice=="10":
4345
for i in range(1,4):
4446

4547
subprocess.call([sd_python_path, chose_model, str(i)])
46-
break
47-
elif choice=="10":
48+
49+
elif choice=="11":
4850
print("Exiting SD-1.5 Model setup.........")
4951
break
5052
elif choice in ["1","2","3","4","5","6"]:
@@ -53,8 +55,11 @@
5355
elif choice == "7":
5456

5557
subprocess.call([sd_python_path, chose_model_controlnet, choice])
58+
elif choice == "8":
59+
60+
subprocess.call([sd_python_path, chose_model_controlnet, choice])
5661

57-
#break
62+
5863

5964
else:
6065
print("Wrong option selected.")

controlnet_model_conversion.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@
5555
ht = 512
5656
weight_path = os.path.join(SD_path, "controlnet-openpose")
5757

58-
59-
60-
61-
58+
6259
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_openpose", torch_dtype=torch.float32)
6360

6461
pipe = StableDiffusionControlNetPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", controlnet=controlnet)
@@ -103,33 +100,56 @@
103100

104101
print('OpenPose successfully converted to IR')
105102
else:
106-
print(f"OpenPose will be loaded from {OPENPOSE_OV_PATH}")
103+
print(f"OpenPose will be loaded from {OPENPOSE_OV_PATH}")
104+
105+
if not os.path.isdir(weight_path):
106+
os.makedirs(weight_path)
107+
108+
print("weight path is :", weight_path)
109+
110+
111+
CONTROLNET_ONNX_PATH = Path(weight_path) / 'controlnet-pose.onnx'
112+
CONTROLNET_OV_PATH = Path(weight_path) / 'controlnet-pose.xml'
107113

108114

109-
#elif choice == "2":
110-
# wt = 640
111-
# ht = 360
112-
# weight_path = os.path.join(SD_path, "landscape")
113-
# print("============SD-1.5 landscape Model setup============")
114-
#elif choice == "3":
115-
# wt = 360
116-
# ht = 640
117-
# weight_path = os.path.join(SD_path, "portrait")
118-
# print("============SD-1.5 portrait Model setup============")
115+
if choice == "8":
116+
print("============SD-1.5 Controlnet-Canny Model setup============----")
117+
wt = 512
118+
ht = 512
119+
weight_path = os.path.join(SD_path, "controlnet-canny")
120+
121+
122+
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny", torch_dtype=torch.float32)
123+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
124+
"runwayml/stable-diffusion-v1-5", controlnet=controlnet
125+
)
126+
127+
128+
if not os.path.isdir(os.path.join(SD_path,"UniPCMultistepScheduler_config")):
129+
print("Saving scheduler config") # TODO: change
130+
pipe = StableDiffusionControlNetPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", controlnet=controlnet)
131+
scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
132+
scheduler.save_config(os.path.join(SD_path,"UniPCMultistepScheduler_config"))
133+
134+
if not os.path.isdir(weight_path):
135+
os.makedirs(weight_path)
136+
137+
print("weight path is :", weight_path)
138+
139+
140+
CONTROLNET_ONNX_PATH = Path(weight_path) / 'controlnet-canny.onnx'
141+
CONTROLNET_OV_PATH = Path(weight_path) / 'controlnet-canny.xml'
119142

120143
else:
121144
print("============Select option 7============----")
145+
146+
122147

123148

124149

125-
if not os.path.isdir(weight_path):
126-
os.makedirs(weight_path)
127150

128-
print("weight path is :", weight_path)
129151

130152

131-
CONTROLNET_ONNX_PATH = Path(weight_path) / 'controlnet-pose.onnx'
132-
CONTROLNET_OV_PATH = Path(weight_path) / 'controlnet-pose.xml'
133153
UNET_ONNX_PATH = Path(weight_path) / 'unet_controlnet' / 'unet_controlnet.onnx'
134154
UNET_OV_PATH = Path(weight_path) / 'unet_controlnet.xml'
135155

gimpopenvino/plugins/stable-diffusion-ov/stable-diffusion-ov.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class SDDialogResponse(IntEnum):
9797
def list_models(weight_path, SD):
9898
model_list = []
9999
flag = False
100-
flag_openpose = False
100+
flag_controlnet = False
101101
if SD == "SD_1.4":
102102
dir_path = os.path.join(weight_path, "stable-diffusion-ov/stable-diffusion-1.4")
103103
flag = True
@@ -107,17 +107,23 @@ def list_models(weight_path, SD):
107107
flag = True
108108
if SD == "controlnet_openpose":
109109
dir_path = os.path.join(weight_path, "stable-diffusion-ov/controlnet-openpose")
110-
flag_openpose = True
111-
print("flag_openpose", flag_openpose)
110+
flag_controlnet = True
111+
print("flag_controlnet", flag_controlnet)
112112

113-
if flag_openpose:
113+
if SD == "controlnet_canny":
114+
dir_path = os.path.join(weight_path, "stable-diffusion-ov/controlnet-canny")
115+
flag_controlnet = True
116+
print("flag_controlnet", flag_controlnet)
117+
118+
if flag_controlnet:
114119
text = Path(dir_path) / 'text_encoder.xml'
115120
unet = Path(dir_path) / 'unet_controlnet.xml'
116121
vae = Path(dir_path) / 'vae_decoder.xml'
117122

118123
if os.path.isfile(text) and os.path.isfile(unet) and os.path.isfile(vae):
119124
print("ALL OKAY !?")
120125
model_list.append(SD)
126+
flag_controlnet = False
121127

122128
return model_list
123129

@@ -418,7 +424,7 @@ def run(procedure, run_mode, image, n_drawables, layer, args, data):
418424
if n_layers == 2:
419425
model_list = list_models(config_path_output["weight_path"],"SD_1.5_Inpainting")
420426
else:
421-
model_list = list_models(config_path_output["weight_path"],"SD_1.4") + list_models(config_path_output["weight_path"],"SD_1.5") + list_models(config_path_output["weight_path"],"controlnet_openpose")
427+
model_list = list_models(config_path_output["weight_path"],"SD_1.4") + list_models(config_path_output["weight_path"],"SD_1.5") + list_models(config_path_output["weight_path"],"controlnet_openpose") + list_models(config_path_output["weight_path"],"controlnet_canny")
422428

423429
model_name_enum = DeviceEnum(model_list)
424430

0 commit comments

Comments
 (0)