Skip to content

Commit 644e2a2

Browse files
committed
fix: mlsd issue, add resize mode radio(AUTOMATIC1111#3)
1 parent 4fdf3e5 commit 644e2a2

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Thanks & Inspired: kohya-ss/sd-webui-additional-networks
1212
* Dragging large file on the Web UI may freeze the entire page. It is better to use the upload file option instead.
1313
* ~~Batch size > 1 or Latent Upscale will encounter errors.~~(fixed)
1414
* MiDas Mode not working due to init issue.
15+
* Processor thresholds are set in `scripts/processor.py`. Change it if needed.
1516

1617
### Install
1718

annotator/mlsd/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
modeldir = os.path.join(extensions.extensions_dir, "sd-webui-controlnet", "mlsd")
1515

1616
def apply_mlsd(input_image, thr_v, thr_d):
17-
global modelpath
17+
global modelpath, mlsdmodel
1818
if mlsdmodel is None:
1919
modelpath = os.path.join(modeldir, "mlsd_large_512_fp32.pth")
2020
if not os.path.exists(modelpath):

scripts/controlnet.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ def ui(self, is_img2img):
155155
])
156156
model_dropdowns.append(model)
157157

158-
def refresh_all_models(*dropdowns):
158+
def refresh_all_models(dropdowns):
159159
update_cn_models()
160160
updates = []
161161
for dd in dropdowns:
162+
dd = dd["value"] if isinstance(dd, dict) else dd
162163
if dd in cn_models:
163164
selected = dd
164165
else:
@@ -175,14 +176,16 @@ def refresh_all_models(*dropdowns):
175176
def create_canvas(h, w):
176177
return np.zeros(shape=(h, w, 3), dtype=np.uint8) + 255
177178

178-
canvas_width = gr.Slider(label="Canvas Width", minimum=256, maximum=1024, value=512, step=1)
179-
canvas_height = gr.Slider(label="Canvas Height", minimum=256, maximum=1024, value=512, step=1)
179+
resize_mode = gr.Radio(choices=["Scale to Fit", "Just Resize"], value="Scale to Fit", label="Resize Mode")
180+
with gr.Row():
181+
canvas_width = gr.Slider(label="Canvas Width", minimum=256, maximum=1024, value=512, step=64)
182+
canvas_height = gr.Slider(label="Canvas Height", minimum=256, maximum=1024, value=512, step=64)
180183
create_button = gr.Button(label="Start", value='Open drawing canvas!')
181184
input_image = gr.Image(source='upload', type='numpy', tool='sketch')
182185
gr.Markdown(value='Change your brush width to make it thinner if you want to draw something.')
183186

184187
create_button.click(fn=create_canvas, inputs=[canvas_height, canvas_width], outputs=[input_image])
185-
ctrls += (input_image, scribble_mode)
188+
ctrls += (input_image, scribble_mode, resize_mode)
186189

187190
return ctrls
188191

@@ -212,7 +215,7 @@ def restore_networks():
212215
self.latest_network.restore(unet)
213216
self.latest_network = None
214217

215-
enabled, module, model, weight,image, scribble_mode = args
218+
enabled, module, model, weight,image, scribble_mode, resize_mode = args
216219

217220
if not enabled:
218221
restore_networks()
@@ -262,8 +265,12 @@ def restore_networks():
262265

263266
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
264267
control = rearrange(control, 'h w c -> c h w')
265-
control = Resize(h if h>w else w, interpolation=InterpolationMode.BICUBIC)(control)
266-
control = CenterCrop((h, w))(control)
268+
269+
if resize_mode == "Scale to Fit":
270+
control = Resize(h if h>w else w, interpolation=InterpolationMode.BICUBIC)(control)
271+
control = CenterCrop((h, w))(control)
272+
else:
273+
control = Resize((h,w), interpolation=InterpolationMode.BICUBIC)(control)
267274

268275
self.control = control
269276
# control = torch.stack([control for _ in range(bsz)], dim=0)

0 commit comments

Comments
 (0)