Update pipeline_stable_diffusion_inpaint_legacy.py (#2903) · gtrevg/diffusers@3becd36 · GitHub
Skip to content

Commit 3becd36

Browse files
Update pipeline_stable_diffusion_inpaint_legacy.py (huggingface#2903)
* Update pipeline_stable_diffusion_inpaint_legacy.py * fix preprocessing of Pil images with adequate batch size * revert map * add tests * reformat * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py * next try to fix the style * wth is this * Update testing_utils.py * Update testing_utils.py * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py * Update test_stable_diffusion_inpaint_legacy.py --------- Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
1 parent c8fdfe4 commit 3becd36

3 files changed

Lines changed: 108 additions & 15 deletions

File tree

‎src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py‎

Lines changed: 10 additions & 10 deletions

‎src/diffusers/utils/testing_utils.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
279279
return image
280280

281281

282+
def preprocess_image(image: PIL.Image, batch_size: int):
283+
w, h = image.size
284+
w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8
285+
image = image.resize((w, h), resample=PIL.Image.LANCZOS)
286+
image = np.array(image).astype(np.float32) / 255.0
287+
image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size)
288+
image = torch.from_numpy(image)
289+
return 2.0 * image - 1.0
290+
291+
282292
def export_to_video(video_frames: List[np.ndarray], output_video_path: str = None) -> str:
283293
if is_opencv_available():
284294
import cv2

‎tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint_legacy.py‎

Lines changed: 88 additions & 5 deletions

0 commit comments

Comments
 (0)