Fix linting warnings and errors using Ruff

main
Uminosachi 2024-05-08 14:22:17 +09:00
parent ed336d45b0
commit 79bb14139b
5 changed files with 8 additions and 7 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ models
ia_config.ini
.eslintrc
.eslintrc.json
pyproject.toml
# Byte-compiled / optimized / DLL files
__pycache__/

View File

@ -56,7 +56,7 @@ class FastSamAutomaticMaskGenerator:
resize_image = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_CUBIC)
backup_nn_dict = {}
for key, value in torch.nn.__dict__.copy().items():
for key, _ in torch.nn.__dict__.copy().items():
if not inspect.isclass(torch.nn.__dict__.get(key)) and "Norm" in key:
backup_nn_dict[key] = torch.nn.__dict__.pop(key)
@ -80,7 +80,7 @@ class FastSamAutomaticMaskGenerator:
annotations = np.array(annotations.cpu())
annotations_list = []
for i, mask in enumerate(annotations):
for mask in annotations:
mask = cv2.morphologyEx(mask.astype(np.uint8), cv2.MORPH_CLOSE, np.ones((3, 3), np.uint8))
mask = cv2.morphologyEx(mask.astype(np.uint8), cv2.MORPH_OPEN, np.ones((7, 7), np.uint8))
mask = cv2.resize(mask, (width, height), interpolation=cv2.INTER_AREA)

View File

@ -27,10 +27,10 @@ defined by the different datasets. Supported colormaps are:
* PASCAL VOC 2012 (http://host.robots.ox.ac.uk/pascal/VOC/).
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import, division, print_function
import numpy as np
# from six.moves import range
# Dataset names.

View File

@ -35,7 +35,7 @@ def pre_offload_model_weights(sem):
if (shared.sd_model is not None and not is_sdxl_lowvram(shared.sd_model) and
getattr(shared.sd_model, "device", devices.cpu) != devices.cpu):
backup_sd_model = shared.sd_model
backup_device = getattr(backup_sd_model, "device")
backup_device = backup_sd_model.device
backup_sd_model.to(devices.cpu)
clear_cache()

View File

@ -86,7 +86,7 @@ def create_mask_image(
canvas_image = np.zeros(mask.shape, dtype=np.uint8)
mask_region = np.zeros(mask.shape, dtype=np.uint8)
for idx, seg_dict in enumerate(sam_masks):
for seg_dict in sam_masks:
seg_mask = np.expand_dims(seg_dict["segmentation"].astype(np.uint8), axis=-1)
canvas_mask = np.logical_not(canvas_image.astype(bool)).astype(np.uint8)
if (seg_mask * canvas_mask * mask).astype(bool).any():