Skip to content

Commit e8e29ac

Browse files
committed
code quality updates
1 parent 4f3bd13 commit e8e29ac

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

src/diffusers/image_processor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ def resize(
499499
raise ValueError(f"Only PIL image input is supported for resize_mode {resize_mode}")
500500
if isinstance(image, PIL.Image.Image):
501501
if resize_mode == "default":
502-
image = image.resize((width, height), resample=PIL_INTERPOLATION[self.config.resample], reducing_gap=self.config.reducing_gap)
502+
image = image.resize(
503+
(width, height),
504+
resample=PIL_INTERPOLATION[self.config.resample],
505+
reducing_gap=self.config.reducing_gap,
506+
)
503507
elif resize_mode == "fill":
504508
image = self._resize_and_fill(image, width, height)
505509
elif resize_mode == "crop":

src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
from typing import Callable, List, Optional, Union
1616

17-
import numpy as np
1817
import PIL.Image
1918
import torch
20-
from PIL import Image
2119

20+
from ...image_processor import VaeImageProcessor
2221
from ...models import UNet2DConditionModel, VQModel
2322
from ...schedulers import DDPMScheduler
2423
from ...utils import (
@@ -27,7 +26,7 @@
2726
)
2827
from ...utils.torch_utils import randn_tensor
2928
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
30-
from ...image_processor import VaeImageProcessor
29+
3130

3231
if is_torch_xla_available():
3332
import torch_xla.core.xla_model as xm
@@ -136,12 +135,12 @@ def __init__(
136135
scheduler=scheduler,
137136
movq=movq,
138137
)
139-
movq_scale_factor = 2 ** (len(self.movq.config.block_out_channels) - 1)
138+
movq_scale_factor = 2 ** (len(self.movq.config.block_out_channels) - 1)
140139
self.image_processor = VaeImageProcessor(
141-
vae_scale_factor = movq_scale_factor,
142-
vae_latent_channels = self.movq.config.latent_channels,
143-
resample = "bicubic",
144-
reducing_gap = 1,
140+
vae_scale_factor=movq_scale_factor,
141+
vae_latent_channels=self.movq.config.latent_channels,
142+
resample="bicubic",
143+
reducing_gap=1,
145144
)
146145

147146
# Copied from diffusers.pipelines.kandinsky.pipeline_kandinsky_img2img.KandinskyImg2ImgPipeline.get_timesteps

src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414

1515
from typing import Callable, Dict, List, Optional, Union
1616

17-
import numpy as np
1817
import PIL.Image
1918
import torch
20-
from PIL import Image
2119

20+
from ...image_processor import VaeImageProcessor
2221
from ...models import UNet2DConditionModel, VQModel
2322
from ...schedulers import DDPMScheduler
2423
from ...utils import deprecate, is_torch_xla_available, logging
2524
from ...utils.torch_utils import randn_tensor
2625
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
27-
from ...image_processor import VaeImageProcessor
26+
2827

2928
if is_torch_xla_available():
3029
import torch_xla.core.xla_model as xm
@@ -108,12 +107,12 @@ def __init__(
108107
scheduler=scheduler,
109108
movq=movq,
110109
)
111-
movq_scale_factor = 2 ** (len(self.movq.config.block_out_channels) - 1)
110+
movq_scale_factor = 2 ** (len(self.movq.config.block_out_channels) - 1)
112111
self.image_processor = VaeImageProcessor(
113-
vae_scale_factor = movq_scale_factor,
114-
vae_latent_channels = self.movq.config.latent_channels,
115-
resample = "bicubic",
116-
reducing_gap = 1,
112+
vae_scale_factor=movq_scale_factor,
113+
vae_latent_channels=self.movq.config.latent_channels,
114+
resample="bicubic",
115+
reducing_gap=1,
117116
)
118117

119118
# Copied from diffusers.pipelines.kandinsky.pipeline_kandinsky_img2img.KandinskyImg2ImgPipeline.get_timesteps
@@ -372,7 +371,7 @@ def __call__(
372371
else:
373372
image = latents
374373
image = self.image_processor.postprocess(image, output_type=output_type)
375-
374+
376375
# Offload all models
377376
self.maybe_free_model_hooks()
378377

src/diffusers/pipelines/kandinsky3/pipeline_kandinsky3_img2img.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import inspect
22
from typing import Callable, Dict, List, Optional, Union
33

4-
import numpy as np
54
import PIL
65
import PIL.Image
76
import torch
87
from transformers import T5EncoderModel, T5Tokenizer
98

9+
from ...image_processor import VaeImageProcessor
1010
from ...loaders import StableDiffusionLoraLoaderMixin
1111
from ...models import Kandinsky3UNet, VQModel
1212
from ...schedulers import DDPMScheduler
@@ -18,7 +18,7 @@
1818
)
1919
from ...utils.torch_utils import randn_tensor
2020
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
21-
from ...image_processor import VaeImageProcessor
21+
2222

2323
if is_torch_xla_available():
2424
import torch_xla.core.xla_model as xm
@@ -76,12 +76,12 @@ def __init__(
7676
self.register_modules(
7777
tokenizer=tokenizer, text_encoder=text_encoder, unet=unet, scheduler=scheduler, movq=movq
7878
)
79-
movq_scale_factor = 2 ** (len(self.movq.config.block_out_channels) - 1)
79+
movq_scale_factor = 2 ** (len(self.movq.config.block_out_channels) - 1)
8080
self.image_processor = VaeImageProcessor(
81-
vae_scale_factor = movq_scale_factor,
82-
vae_latent_channels = self.movq.config.latent_channels,
83-
resample = "bicubic",
84-
reducing_gap = 1,
81+
vae_scale_factor=movq_scale_factor,
82+
vae_latent_channels=self.movq.config.latent_channels,
83+
resample="bicubic",
84+
reducing_gap=1,
8585
)
8686

8787
def get_timesteps(self, num_inference_steps, strength, device):

0 commit comments

Comments
 (0)