| 213 | ) |
| 214 | |
| 215 | def image_to_image( |
| 216 | self, |
| 217 | params: SamplingParams, |
| 218 | image, |
| 219 | prompt: str, |
| 220 | negative_prompt: str = "", |
| 221 | samples: int = 1, |
| 222 | return_latents: bool = False, |
| 223 | ): |
| 224 | sampler = get_sampler_config(params) |
| 225 | |
| 226 | if params.img2img_strength < 1.0: |
| 227 | sampler.discretization = Img2ImgDiscretizationWrapper( |
| 228 | sampler.discretization, |
| 229 | strength=params.img2img_strength, |
| 230 | ) |
| 231 | height, width = image.shape[2], image.shape[3] |
| 232 | value_dict = asdict(params) |
| 233 | value_dict["prompt"] = prompt |
| 234 | value_dict["negative_prompt"] = negative_prompt |
| 235 | value_dict["target_width"] = width |
| 236 | value_dict["target_height"] = height |
| 237 | return do_img2img( |
| 238 | image, |
| 239 | self.model, |
| 240 | sampler, |
| 241 | value_dict, |
| 242 | samples, |
| 243 | force_uc_zero_embeddings=["txt"] if not self.specs.is_legacy else [], |
| 244 | return_latents=return_latents, |
| 245 | filter=None, |
| 246 | ) |
| 247 | |
| 248 | def refiner( |
| 249 | self, |