Skip to content

Commit a12fbc7

Browse files
chore: black fix
1 parent ba2048d commit a12fbc7

File tree

8 files changed

+59
-56
lines changed

8 files changed

+59
-56
lines changed

invokeai/backend/stable_diffusion/diffusion/cross_attention_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def einsum_op_mps_v1(self, q, k, v):
265265
if q.shape[1] <= 4096: # (512x512) max q.shape[1]: 4096
266266
return self.einsum_lowest_level(q, k, v, None, None, None)
267267
else:
268-
slice_size = math.floor(2 ** 30 / (q.shape[0] * q.shape[1]))
268+
slice_size = math.floor(2**30 / (q.shape[0] * q.shape[1]))
269269
return self.einsum_op_slice_dim1(q, k, v, slice_size)
270270

271271
def einsum_op_mps_v2(self, q, k, v):

invokeai/backend/stable_diffusion/diffusion/shared_invokeai_diffusion.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ def do_controlnet_step(
215215
dim=0,
216216
),
217217
}
218-
(encoder_hidden_states, encoder_attention_mask,) = self._concat_conditionings_for_batch(
218+
(
219+
encoder_hidden_states,
220+
encoder_attention_mask,
221+
) = self._concat_conditionings_for_batch(
219222
conditioning_data.unconditioned_embeddings.embeds,
220223
conditioning_data.text_embeddings.embeds,
221224
)
@@ -277,23 +280,32 @@ def do_unet_step(
277280
wants_cross_attention_control = len(cross_attention_control_types_to_do) > 0
278281

279282
if wants_cross_attention_control:
280-
(unconditioned_next_x, conditioned_next_x,) = self._apply_cross_attention_controlled_conditioning(
283+
(
284+
unconditioned_next_x,
285+
conditioned_next_x,
286+
) = self._apply_cross_attention_controlled_conditioning(
281287
sample,
282288
timestep,
283289
conditioning_data,
284290
cross_attention_control_types_to_do,
285291
**kwargs,
286292
)
287293
elif self.sequential_guidance:
288-
(unconditioned_next_x, conditioned_next_x,) = self._apply_standard_conditioning_sequentially(
294+
(
295+
unconditioned_next_x,
296+
conditioned_next_x,
297+
) = self._apply_standard_conditioning_sequentially(
289298
sample,
290299
timestep,
291300
conditioning_data,
292301
**kwargs,
293302
)
294303

295304
else:
296-
(unconditioned_next_x, conditioned_next_x,) = self._apply_standard_conditioning(
305+
(
306+
unconditioned_next_x,
307+
conditioned_next_x,
308+
) = self._apply_standard_conditioning(
297309
sample,
298310
timestep,
299311
conditioning_data,

invokeai/backend/stable_diffusion/image_degradation/bsrgan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def add_Gaussian_noise(img, noise_level1=2, noise_level2=25):
395395
D = np.diag(np.random.rand(3))
396396
U = orth(np.random.rand(3, 3))
397397
conv = np.dot(np.dot(np.transpose(U), D), U)
398-
img = img + np.random.multivariate_normal([0, 0, 0], np.abs(L ** 2 * conv), img.shape[:2]).astype(np.float32)
398+
img = img + np.random.multivariate_normal([0, 0, 0], np.abs(L**2 * conv), img.shape[:2]).astype(np.float32)
399399
img = np.clip(img, 0.0, 1.0)
400400
return img
401401

@@ -413,7 +413,7 @@ def add_speckle_noise(img, noise_level1=2, noise_level2=25):
413413
D = np.diag(np.random.rand(3))
414414
U = orth(np.random.rand(3, 3))
415415
conv = np.dot(np.dot(np.transpose(U), D), U)
416-
img += img * np.random.multivariate_normal([0, 0, 0], np.abs(L ** 2 * conv), img.shape[:2]).astype(np.float32)
416+
img += img * np.random.multivariate_normal([0, 0, 0], np.abs(L**2 * conv), img.shape[:2]).astype(np.float32)
417417
img = np.clip(img, 0.0, 1.0)
418418
return img
419419

invokeai/backend/stable_diffusion/image_degradation/bsrgan_light.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def add_Gaussian_noise(img, noise_level1=2, noise_level2=25):
399399
D = np.diag(np.random.rand(3))
400400
U = orth(np.random.rand(3, 3))
401401
conv = np.dot(np.dot(np.transpose(U), D), U)
402-
img = img + np.random.multivariate_normal([0, 0, 0], np.abs(L ** 2 * conv), img.shape[:2]).astype(np.float32)
402+
img = img + np.random.multivariate_normal([0, 0, 0], np.abs(L**2 * conv), img.shape[:2]).astype(np.float32)
403403
img = np.clip(img, 0.0, 1.0)
404404
return img
405405

@@ -417,7 +417,7 @@ def add_speckle_noise(img, noise_level1=2, noise_level2=25):
417417
D = np.diag(np.random.rand(3))
418418
U = orth(np.random.rand(3, 3))
419419
conv = np.dot(np.dot(np.transpose(U), D), U)
420-
img += img * np.random.multivariate_normal([0, 0, 0], np.abs(L ** 2 * conv), img.shape[:2]).astype(np.float32)
420+
img += img * np.random.multivariate_normal([0, 0, 0], np.abs(L**2 * conv), img.shape[:2]).astype(np.float32)
421421
img = np.clip(img, 0.0, 1.0)
422422
return img
423423

invokeai/backend/stable_diffusion/image_degradation/utils_image.py

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -562,18 +562,14 @@ def rgb2ycbcr(img, only_y=True):
562562
if only_y:
563563
rlt = np.dot(img, [65.481, 128.553, 24.966]) / 255.0 + 16.0
564564
else:
565-
rlt = (
566-
np.matmul(
567-
img,
568-
[
569-
[65.481, -37.797, 112.0],
570-
[128.553, -74.203, -93.786],
571-
[24.966, 112.0, -18.214],
572-
],
573-
)
574-
/ 255.0
575-
+ [16, 128, 128]
576-
)
565+
rlt = np.matmul(
566+
img,
567+
[
568+
[65.481, -37.797, 112.0],
569+
[128.553, -74.203, -93.786],
570+
[24.966, 112.0, -18.214],
571+
],
572+
) / 255.0 + [16, 128, 128]
577573
if in_img_type == np.uint8:
578574
rlt = rlt.round()
579575
else:
@@ -592,18 +588,14 @@ def ycbcr2rgb(img):
592588
if in_img_type != np.uint8:
593589
img *= 255.0
594590
# convert
595-
rlt = (
596-
np.matmul(
597-
img,
598-
[
599-
[0.00456621, 0.00456621, 0.00456621],
600-
[0, -0.00153632, 0.00791071],
601-
[0.00625893, -0.00318811, 0],
602-
],
603-
)
604-
* 255.0
605-
+ [-222.921, 135.576, -276.836]
606-
)
591+
rlt = np.matmul(
592+
img,
593+
[
594+
[0.00456621, 0.00456621, 0.00456621],
595+
[0, -0.00153632, 0.00791071],
596+
[0.00625893, -0.00318811, 0],
597+
],
598+
) * 255.0 + [-222.921, 135.576, -276.836]
607599
if in_img_type == np.uint8:
608600
rlt = rlt.round()
609601
else:
@@ -626,18 +618,14 @@ def bgr2ycbcr(img, only_y=True):
626618
if only_y:
627619
rlt = np.dot(img, [24.966, 128.553, 65.481]) / 255.0 + 16.0
628620
else:
629-
rlt = (
630-
np.matmul(
631-
img,
632-
[
633-
[24.966, 112.0, -18.214],
634-
[128.553, -74.203, -93.786],
635-
[65.481, -37.797, 112.0],
636-
],
637-
)
638-
/ 255.0
639-
+ [16, 128, 128]
640-
)
621+
rlt = np.matmul(
622+
img,
623+
[
624+
[24.966, 112.0, -18.214],
625+
[128.553, -74.203, -93.786],
626+
[65.481, -37.797, 112.0],
627+
],
628+
) / 255.0 + [16, 128, 128]
641629
if in_img_type == np.uint8:
642630
rlt = rlt.round()
643631
else:
@@ -728,11 +716,11 @@ def ssim(img1, img2):
728716

729717
mu1 = cv2.filter2D(img1, -1, window)[5:-5, 5:-5] # valid
730718
mu2 = cv2.filter2D(img2, -1, window)[5:-5, 5:-5]
731-
mu1_sq = mu1 ** 2
732-
mu2_sq = mu2 ** 2
719+
mu1_sq = mu1**2
720+
mu2_sq = mu2**2
733721
mu1_mu2 = mu1 * mu2
734-
sigma1_sq = cv2.filter2D(img1 ** 2, -1, window)[5:-5, 5:-5] - mu1_sq
735-
sigma2_sq = cv2.filter2D(img2 ** 2, -1, window)[5:-5, 5:-5] - mu2_sq
722+
sigma1_sq = cv2.filter2D(img1**2, -1, window)[5:-5, 5:-5] - mu1_sq
723+
sigma2_sq = cv2.filter2D(img2**2, -1, window)[5:-5, 5:-5] - mu2_sq
736724
sigma12 = cv2.filter2D(img1 * img2, -1, window)[5:-5, 5:-5] - mu1_mu2
737725

738726
ssim_map = ((2 * mu1_mu2 + C1) * (2 * sigma12 + C2)) / ((mu1_sq + mu2_sq + C1) * (sigma1_sq + sigma2_sq + C2))
@@ -749,8 +737,8 @@ def ssim(img1, img2):
749737
# matlab 'imresize' function, now only support 'bicubic'
750738
def cubic(x):
751739
absx = torch.abs(x)
752-
absx2 = absx ** 2
753-
absx3 = absx ** 3
740+
absx2 = absx**2
741+
absx3 = absx**3
754742
return (1.5 * absx3 - 2.5 * absx2 + 1) * ((absx <= 1).type_as(absx)) + (
755743
-0.5 * absx3 + 2.5 * absx2 - 4 * absx + 2
756744
) * (((absx > 1) * (absx <= 2)).type_as(absx))

invokeai/backend/training/textual_inversion_training.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,10 @@ def __getitem__(self, i):
475475

476476
if self.center_crop:
477477
crop = min(img.shape[0], img.shape[1])
478-
(h, w,) = (
478+
(
479+
h,
480+
w,
481+
) = (
479482
img.shape[0],
480483
img.shape[1],
481484
)

invokeai/backend/util/mps_fixes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
2-
import torch
3-
import diffusers
42

3+
import diffusers
4+
import torch
55

66
if torch.backends.mps.is_available():
77
torch.empty = torch.zeros
@@ -203,7 +203,7 @@ def get_attention_scores_chunked(self, attn, query, key, attention_mask, hidden_
203203
if attn.upcast_attention:
204204
out_item_size = 4
205205

206-
chunk_size = 2 ** 29
206+
chunk_size = 2**29
207207

208208
out_size = query.shape[1] * key.shape[1] * out_item_size
209209
chunks_count = min(query.shape[1], math.ceil((out_size - 1) / chunk_size))

invokeai/backend/util/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def parallel_data_prefetch(
207207
return gather_res
208208

209209

210-
def rand_perlin_2d(shape, res, device, fade=lambda t: 6 * t ** 5 - 15 * t ** 4 + 10 * t ** 3):
210+
def rand_perlin_2d(shape, res, device, fade=lambda t: 6 * t**5 - 15 * t**4 + 10 * t**3):
211211
delta = (res[0] / shape[0], res[1] / shape[1])
212212
d = (shape[0] // res[0], shape[1] // res[1])
213213

0 commit comments

Comments
 (0)