Skip to content

Commit

Permalink
Fix other Ruff complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Nov 22, 2023
1 parent be68b62 commit ef81f09
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def init_wandb(save_dir, opt, config, group_name, name_str):
# TODO change once leaving "swiffer" config directory
try:
group_name = nowname.split(now)[-1].split("-")[1]
except:
except Exception:
group_name = nowname
default_logger_cfg["params"]["group"] = group_name
init_wandb(
Expand Down Expand Up @@ -839,7 +839,7 @@ def init_wandb(save_dir, opt, config, group_name, name_str):
print(
f"{k}, {data.datasets[k].__class__.__name__}, {len(data.datasets[k])}"
)
except:
except Exception:
print("datasets not yet initialized.")

# configure learning rate
Expand Down
2 changes: 1 addition & 1 deletion scripts/demo/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def decode(self, cv2Image, method="dwtDct", **configs):
bits = embed.decode(cv2Image)
return self.reconstruct(bits)

except:
except Exception:
raise e


Expand Down
2 changes: 1 addition & 1 deletion sgm/inference/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def do_sample(
if isinstance(batch[key], torch.Tensor):
print(key, batch[key].shape)
elif isinstance(batch[key], list):
print(key, [len(l) for l in batch[key]])
print(key, [len(lst) for lst in batch[key]])
else:
print(key, batch[key])
c, uc = model.conditioner.get_unconditional_conditioning(
Expand Down
5 changes: 2 additions & 3 deletions sgm/modules/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from torch import nn
from torch.utils.checkpoint import checkpoint


logpy = logging.getLogger(__name__)

if version.parse(torch.__version__) >= version.parse("2.0.0"):
Expand Down Expand Up @@ -51,12 +52,10 @@
import xformers.ops

XFORMERS_IS_AVAILABLE = True
except:
except Exception:
XFORMERS_IS_AVAILABLE = False
logpy.warn("no module 'xformers'. Processing without...")

# from .diffusionmodules.util import mixed_checkpoint as checkpoint


def exists(val):
return val is not None
Expand Down
2 changes: 1 addition & 1 deletion sgm/modules/autoencoding/lpips/loss/lpips.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def forward(self, input, target):
for kk in range(len(self.chns))
]
val = res[0]
for l in range(1, len(self.chns)):
for l in range(1, len(self.chns)): # noqa: E741
val += res[l]
return val

Expand Down
6 changes: 3 additions & 3 deletions sgm/modules/diffusionmodules/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
from einops import rearrange
from packaging import version

from ...modules.attention import LinearAttention, MemoryEfficientCrossAttention

logpy = logging.getLogger(__name__)

try:
import xformers
import xformers.ops

XFORMERS_IS_AVAILABLE = True
except:
except Exception:
XFORMERS_IS_AVAILABLE = False
logpy.warning("no module 'xformers'. Processing without...")

from ...modules.attention import LinearAttention, MemoryEfficientCrossAttention


def get_timestep_embedding(timesteps, embedding_dim):
"""
Expand Down
2 changes: 1 addition & 1 deletion sgm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_string_from_tuple(s):
return t[0]
else:
pass
except:
except Exception:
pass
return s

Expand Down

0 comments on commit ef81f09

Please sign in to comment.