(p: processing.StableDiffusionProcessing, output)
| 240 | |
| 241 | |
| 242 | def process_hires(p: processing.StableDiffusionProcessing, output): |
| 243 | # optional second pass |
| 244 | if (output is None) or not hasattr(output, 'images') or (output.images is None): |
| 245 | return output |
| 246 | if p.enable_hr: |
| 247 | jobid = shared.state.begin('Hires') |
| 248 | p.is_hr_pass = True |
| 249 | if hasattr(p, 'init_hr'): |
| 250 | p.init_hr(p.hr_scale, p.hr_upscaler, force=p.hr_force) |
| 251 | else: |
| 252 | if not p.is_hr_pass: # fake hires for img2img if not actual hr pass |
| 253 | p.hr_scale = p.scale_by |
| 254 | p.hr_upscaler = p.resize_name |
| 255 | p.hr_resize_mode = p.resize_mode |
| 256 | p.hr_resize_context = p.resize_context |
| 257 | p.hr_upscale_to_x = int(p.width * p.hr_scale) if p.hr_resize_x == 0 else p.hr_resize_x |
| 258 | p.hr_upscale_to_y = int(p.height * p.hr_scale) if p.hr_resize_y == 0 else p.hr_resize_y |
| 259 | |
| 260 | # hires runs on original pipeline |
| 261 | if hasattr(shared.sd_model, 'restore_pipeline') and (shared.sd_model.restore_pipeline is not None) and (not shared.opts.control_hires): |
| 262 | shared.sd_model.restore_pipeline() |
| 263 | if (getattr(shared.sd_model, 'controlnet', None) is not None) and (((isinstance(shared.sd_model.controlnet, list) and len(shared.sd_model.controlnet) > 1)) or ('Multi' in type(shared.sd_model.controlnet).__name__)): |
| 264 | log.warning(f'Process: control={type(shared.sd_model.controlnet)} not supported in hires') |
| 265 | return output |
| 266 | |
| 267 | # upscale |
| 268 | if hasattr(p, 'height') and hasattr(p, 'width') and p.hr_resize_mode > 0 and (p.hr_upscaler != 'None' or p.hr_resize_mode == 5): |
| 269 | log.info(f'Upscale: mode={p.hr_resize_mode} upscaler="{p.hr_upscaler}" context="{p.hr_resize_context}" resize={p.hr_resize_x}x{p.hr_resize_y} upscale={p.hr_upscale_to_x}x{p.hr_upscale_to_y}') |
| 270 | p.ops.append('upscale') |
| 271 | if shared.opts.samples_save and not p.do_not_save_samples and shared.opts.save_images_before_highres_fix and hasattr(shared.sd_model, 'vae'): |
| 272 | save_intermediate(p, latents=output.images, suffix="-before-hires") |
| 273 | output.images = resize_hires(p, latents=output.images) |
| 274 | sd_hijack_hypertile.hypertile_set(p, hr=True) |
| 275 | elif torch.is_tensor(output.images) and output.images.shape[-1] == 3: # nhwc |
| 276 | if output.images.dim() == 3: |
| 277 | output.images = convert.to_pil(output.images) |
| 278 | elif output.images.dim() == 4: |
| 279 | output.images = [convert.to_pil(output.images[i]) for i in range(output.images.shape[0])] |
| 280 | |
| 281 | strength = p.hr_denoising_strength if p.hr_denoising_strength > 0 else p.denoising_strength |
| 282 | if (p.hr_upscaler is not None) and (p.hr_upscaler.lower().startswith('latent') or p.hr_force) and strength > 0: |
| 283 | p.ops.append('hires') |
| 284 | sd_models_compile.openvino_recompile_model(p, hires=True, refiner=False) |
| 285 | if shared.sd_model.__class__.__name__ == "OnnxRawPipeline": |
| 286 | shared.sd_model = preprocess_onnx_pipeline(p) |
| 287 | p.hr_force = True |
| 288 | |
| 289 | # hires |
| 290 | if p.hr_force and strength == 0: |
| 291 | log.warning('Hires skip: denoising=0') |
| 292 | p.hr_force = False |
| 293 | if p.hr_force: |
| 294 | shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.IMAGE_2_IMAGE) |
| 295 | if 'Upscale' in shared.sd_model.__class__.__name__ or 'Flux' in shared.sd_model.__class__.__name__ or 'Kandinsky' in shared.sd_model.__class__.__name__: |
| 296 | output.images = processing_vae.vae_decode(latents=output.images, model=shared.sd_model, vae_type=p.vae_type, output_type='pil', width=p.width, height=p.height) |
| 297 | if p.is_control and hasattr(p, 'task_args') and p.task_args.get('image', None) is not None: |
| 298 | if hasattr(shared.sd_model, "vae") and output.images is not None and len(output.images) > 0: |
| 299 | output.images = processing_vae.vae_decode(latents=output.images, model=shared.sd_model, vae_type=p.vae_type, output_type='pil', width=p.hr_upscale_to_x, height=p.hr_upscale_to_y) # controlnet cannot deal with latent input |
no test coverage detected