Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: use latest ruff #476

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions imaginairy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pythonic AI generation of images and videos"""

import os

# tells pytorch to allow MPS usage (for Mac M1 compatibility)
Expand Down
6 changes: 3 additions & 3 deletions imaginairy/api/generate_refiners.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ def latent_logger(latents):
fit_width=prompt.width,
fit_height=prompt.height,
)
result_images[
f"control-{control_input.mode}"
] = control_image_disp
result_images[f"control-{control_input.mode}"] = (
control_image_disp
)
controlnets.append((controlnet, control_image_t))

for controlnet, control_image_t in controlnets:
Expand Down
1 change: 1 addition & 0 deletions imaginairy/cli/unslow_the_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pkg_resources.require() which is called by setuptools to ensure the
"correct" version of the package is installed.
"""

import os


Expand Down
1 change: 1 addition & 0 deletions imaginairy/enhancers/bool_masker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
fruit{-0.1} OR bowl

"""

import operator
from abc import ABC
from typing import ClassVar
Expand Down
8 changes: 2 additions & 6 deletions imaginairy/enhancers/video_interpolation/rife/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def transfer_audio(sourceVideo, targetVideo):
f'ffmpeg -y -i "{sourceVideo}" -c:a aac -b:a 160k -vn {tempAudioFileName}'
)
os.system(
'ffmpeg -y -i "{}" -i {} -c copy "{}"'.format(
targetNoAudio, tempAudioFileName, targetVideo
)
f'ffmpeg -y -i "{targetNoAudio}" -i {tempAudioFileName} -c copy "{targetVideo}"'
)
if (
os.path.getsize(targetVideo) == 0
Expand Down Expand Up @@ -159,9 +157,7 @@ def interpolate_video_file(
fourcc = cv2.VideoWriter_fourcc("m", "p", "4", "v") # type: ignore
video_path_wo_ext, ext = os.path.splitext(video_path)
print(
"{}.{}, {} frames in total, {}FPS to {}FPS".format(
video_path_wo_ext, output_extension, tot_frame, fps, target_fps
)
f"{video_path_wo_ext}.{output_extension}, {tot_frame} frames in total, {fps}FPS to {target_fps}FPS"
)
if png_out is False and fpsNotAssigned is True:
print("The audio will be merged after interpolation process")
Expand Down
1 change: 1 addition & 0 deletions imaginairy/img_processors/control_modes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to create hint images for controlnet."""

from typing import TYPE_CHECKING, Callable, Dict, Union

if TYPE_CHECKING:
Expand Down
13 changes: 7 additions & 6 deletions imaginairy/modules/diffusion/ddpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://github.com/CompVis/taming-transformers
-- merci.
"""

import itertools
import logging
from contextlib import contextmanager, nullcontext
Expand Down Expand Up @@ -1602,9 +1603,9 @@ def log_images(
unconditional_conditioning=uc,
)
x_samples_cfg = self.decode_first_stage(samples_cfg)
log[
f"samples_cfg_scale_{unconditional_guidance_scale:.2f}"
] = x_samples_cfg
log[f"samples_cfg_scale_{unconditional_guidance_scale:.2f}"] = (
x_samples_cfg
)

if inpaint:
# make a simple center square
Expand Down Expand Up @@ -1921,9 +1922,9 @@ def log_images(
unconditional_conditioning=uc_full,
)
x_samples_cfg = self.decode_first_stage(samples_cfg)
log[
f"samples_cfg_scale_{unconditional_guidance_scale:.2f}"
] = x_samples_cfg
log[f"samples_cfg_scale_{unconditional_guidance_scale:.2f}"] = (
x_samples_cfg
)

return log

Expand Down
1 change: 0 additions & 1 deletion imaginairy/modules/diffusion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#
# thanks!


import logging
import math

Expand Down
4 changes: 1 addition & 3 deletions imaginairy/modules/midas/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ def load_model(

if "openvino" not in model_type:
print(
"Model loaded, number of parameters = {:.0f}M".format(
sum(p.numel() for p in model.parameters()) / 1e6
)
f"Model loaded, number of parameters = {sum(p.numel() for p in model.parameters()) / 1e6:.0f}M"
)
else:
print("Model loaded, optimized with OpenVINO")
Expand Down
12 changes: 3 additions & 9 deletions imaginairy/modules/midas/midas/dpt_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,9 @@ def forward(self, x):

class DPTDepthModel(DPT):
def __init__(self, path=None, non_negative=True, **kwargs):
features = kwargs["features"] if "features" in kwargs else 256
head_features_1 = (
kwargs["head_features_1"] if "head_features_1" in kwargs else features
)
head_features_2 = (
kwargs["head_features_2"] if "head_features_2" in kwargs else 32
)
kwargs.pop("head_features_1", None)
kwargs.pop("head_features_2", None)
features = kwargs.pop("features", 256)
head_features_1 = kwargs.pop("head_features_1", features)
head_features_2 = kwargs.pop("head_features_2", 32)

head = nn.Sequential(
nn.Conv2d(
Expand Down
1 change: 1 addition & 0 deletions imaginairy/modules/midas/midas/midas_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This file contains code that is adapted from
https://github.com/thomasjpfan/pytorch_refinenet/blob/master/pytorch_refinenet/refinenet/refinenet_4cascade.py.
"""

import torch
from torch import nn

Expand Down
1 change: 1 addition & 0 deletions imaginairy/modules/midas/midas/midas_net_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This file contains code that is adapted from
https://github.com/thomasjpfan/pytorch_refinenet/blob/master/pytorch_refinenet/refinenet/refinenet_4cascade.py.
"""

import torch
from torch import nn

Expand Down
1 change: 1 addition & 0 deletions imaginairy/modules/midas/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utils for monoDepth."""

import re
import sys

Expand Down
3 changes: 1 addition & 2 deletions imaginairy/modules/sgm/diffusionmodules/sampling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Partially ported from https://github.com/crowsonkb/k-diffusion/blob/master/k_diffusion/sampling.py
Partially ported from https://github.com/crowsonkb/k-diffusion/blob/master/k_diffusion/sampling.py
"""


from typing import Dict, Union

import torch
Expand Down
4 changes: 2 additions & 2 deletions imaginairy/modules/sgm/diffusionmodules/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def forward(
return self.diffusion_model(
x,
timesteps=t,
context=c.get("crossattn", None),
y=c.get("vector", None),
context=c.get("crossattn"),
y=c.get("vector"),
**kwargs,
)
1 change: 1 addition & 0 deletions imaginairy/samplers/editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

modified from https://github.com/timothybrooks/instruct-pix2pix/blob/main/edit_cli.py
"""

import torch
from einops import einops
from torch import nn
Expand Down
1 change: 1 addition & 0 deletions imaginairy/utils/animations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for creating animations from images."""

import logging
import os.path
from typing import TYPE_CHECKING, List, Sequence
Expand Down
2 changes: 1 addition & 1 deletion imaginairy/utils/feather_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def add_tiles(tiles, base_img, tile_coords, tile_size, overlap):
t += 1
column += 1

row += 1
row += 1 # noqa
# if row >= 2:
# exit()
column = 0
Expand Down
1 change: 1 addition & 0 deletions imaginairy/utils/img_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Torch (B), C, H, W R, G, B -1.0-1.0 torch.Tensor

"""

from typing import Sequence

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions imaginairy/utils/paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Code for defining package root path"""

import os

PKG_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
6 changes: 3 additions & 3 deletions imaginairy/weight_management/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def translate_weights(
new_key = f"Parallel.CLIPTextEncoderL.{k}"
new_sd[new_key] = text_encoder_l_weights.pop(k)

new_sd[
"Parallel.TextEncoderWithPooling.Parallel.Chain.Linear.weight"
] = text_encoder_g_weights.pop("Linear.weight")
new_sd["Parallel.TextEncoderWithPooling.Parallel.Chain.Linear.weight"] = (
text_encoder_g_weights.pop("Linear.weight")
)
for k in list(text_encoder_g_weights.keys()):
if k.startswith("TransformerLayer_32"):
new_key = f"Parallel.TextEncoderWithPooling.Parallel.Chain.CLIPTextEncoderG.TransformerLayer{k[19:]}"
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mkdocs-click
mkdocstrings[python]
mypy
ruff
pip-tools
pytest
pytest-asyncio
pytest-randomly
Expand Down
Loading
Loading