Skip to content

Commit 7421d99

Browse files
committed
lint: fix formatting
1 parent 6a6419f commit 7421d99

File tree

8 files changed

+38
-15
lines changed

8 files changed

+38
-15
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static-analysis: check-ruff-format check-ruff-organize-imports check-ruff-lint #
4747

4848
style: ## Apply style formating
4949
@echo "--> Running ruff format"
50-
@ruff format $(src_dirs)
50+
@ruff format $(src_dirs)
5151
@echo "--> Running ruff check --ignore ALL --select I"
52-
@ruff check --ignore ALL --select I $(src_dirs)
52+
@ruff check --ignore ALL --select I $(src_dirs) --fix
5353

compressai_vision/evaluators/evaluators.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,9 @@ def __init__(
917917
from pycocotools.coco import COCO
918918
from yolox.data.datasets.coco import remove_useless_info
919919
from yolox.evaluators import COCOEvaluator as YOLOX_COCOEvaluator
920+
from yolox.utils import xyxy2xywh
921+
922+
self.xyxy2xywh = xyxy2xywh
920923

921924
self.set_annotation_info(dataset)
922925

@@ -991,6 +994,8 @@ def results(self, save_path: str = None):
991994

992995
def _convert_to_coco_format(self, outputs, info_imgs, ids):
993996
# reference : yolox > evaluators > coco_evaluator > convert_to_coco_format
997+
from yolox.utils import xyxy2xywh
998+
994999
data_list = []
9951000
image_wise_data = defaultdict(dict)
9961001
for output, img_h, img_w, img_id in zip(
@@ -1023,7 +1028,7 @@ def _convert_to_coco_format(self, outputs, info_imgs, ids):
10231028
}
10241029
)
10251030

1026-
bboxes = xyxy2xywh(bboxes)
1031+
bboxes = self.xyxy2xywh(bboxes)
10271032

10281033
for ind in range(bboxes.shape[0]):
10291034
label = self._class_ids[int(cls[ind])]

compressai_vision/model_wrappers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2828
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
from .base_wrapper import BaseWrapper
3130
from . import detectron2, jde, rtmo, sam, yolox
31+
from .base_wrapper import BaseWrapper
3232

3333
__all__ = ["BaseWrapper"]

compressai_vision/model_wrappers/detectron2.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import torch
3636

37-
3837
from compressai_vision.registry import register_vision_model
3938

4039
from .base_wrapper import BaseWrapper
@@ -172,7 +171,9 @@ def __init__(self, device: str, **kwargs):
172171
self.replace_conv2d_modules(self.model)
173172
self.model = self.model.to(device).eval()
174173

175-
self.DetectionCheckpointer(self.model).load(f"{_path_prefix}/{kwargs['weights']}")
174+
self.DetectionCheckpointer(self.model).load(
175+
f"{_path_prefix}/{kwargs['weights']}"
176+
)
176177

177178
for param in self.model.parameters():
178179
param.requires_grad = False
@@ -600,7 +601,9 @@ def __init__(self, img_size: list):
600601
):
601602
height = input_per_image["height"]
602603
width = input_per_image["width"]
603-
sem_seg_r = self.sem_seg_postprocess(sem_seg_result, image_size, height, width)
604+
sem_seg_r = self.sem_seg_postprocess(
605+
sem_seg_result, image_size, height, width
606+
)
604607
detector_r = self.detector_postprocess(detector_result, height, width)
605608

606609
processed_results.append({"sem_seg": sem_seg_r, "instances": detector_r})

compressai_vision/model_wrappers/jde.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
class jde_1088x608(BaseWrapper):
5151
def __init__(self, device: str, **kwargs):
5252
import jde
53+
5354
from jde.models import Darknet
5455
from jde.utils.kalman_filter import KalmanFilter
5556

@@ -221,6 +222,7 @@ def _jde_process(self, pred, org_img_size: tuple, input_img_size: tuple):
221222
sub_stracks,
222223
)
223224
from jde.utils.utils import non_max_suppression, scale_coords
225+
224226
r"""Re-implementation of JDE from Z. Wang, L. Zheng, Y. Liu, and S. Wang:
225227
: `"Towards Real-Time Multi-Object Tracking"`_,
226228
The European Conference on Computer Vision (ECCV), 2020

compressai_vision/model_wrappers/rtmo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def __init__(self, device: str, **kwargs):
8686
default_scope = cfg.get("default_scope", "mmengine")
8787
assert default_scope == "mmpose"
8888

89-
default_scope = self.DefaultScope.get_instance("mmpose", scope_name=default_scope)
89+
default_scope = self.DefaultScope.get_instance(
90+
"mmpose", scope_name=default_scope
91+
)
9092
self.model = self.MODELS.build(model_cfg)
9193
self.test_cfg = model_cfg["test_cfg"]
9294

compressai_vision/model_wrappers/sam.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import numpy as np
1111
import pandas
1212
import torch
13+
1314
from torch.nn import functional as F
1415

1516
from compressai_vision.registry import register_vision_model

compressai_vision/model_wrappers/yolox.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class yolox_darknet53(BaseWrapper):
6060
def __init__(self, device: str, **kwargs):
6161
super().__init__(device)
6262

63+
from yolox.exp import get_exp
64+
from yolox.utils import postprocess
65+
66+
self.postprocess = postprocess
67+
6368
_path_prefix = (
6469
f"{root_path}"
6570
if kwargs["model_path_prefix"] == "default"
@@ -74,8 +79,6 @@ def __init__(self, device: str, **kwargs):
7479
self.conf_thres = kwargs["conf_thres"]
7580
self.nms_thres = kwargs["nms_thres"]
7681

77-
from yolox.exp import get_exp
78-
7982
self.squeeze_at_split_enabled = False
8083

8184
exp = get_exp(exp_file=None, exp_name="yolov3")
@@ -230,6 +233,8 @@ def _feature_at_l13_to_output(
230233
<https://github.com/Megvii-BaseDetection/YOLOX?tab=Apache-2.0-1-ov-file#readme>
231234
232235
"""
236+
from yolox.utils import postprocess
237+
233238
y = x[self.SPLIT_L13]
234239

235240
# Recovery session to expand dimension to original
@@ -258,7 +263,9 @@ def _feature_at_l13_to_output(
258263

259264
outputs = self.head((fp_lvl2, fp_lvl1, fp_lvl0))
260265

261-
pred = postprocess(outputs, self.num_classes, self.conf_thres, self.nms_thres)
266+
pred = self.postprocess(
267+
outputs, self.num_classes, self.conf_thres, self.nms_thres
268+
)
262269

263270
return pred
264271

@@ -278,6 +285,7 @@ def _feature_at_l37_to_output(
278285
<https://github.com/Megvii-BaseDetection/YOLOX?tab=Apache-2.0-1-ov-file#readme>
279286
280287
"""
288+
from yolox.utils import postprocess
281289

282290
fp_lvl2 = x[self.SPLIT_L37]
283291
fp_lvl1 = self.backbone.dark4(fp_lvl2)
@@ -297,7 +305,9 @@ def _feature_at_l37_to_output(
297305

298306
outputs = self.head((fp_lvl2, fp_lvl1, fp_lvl0))
299307

300-
pred = postprocess(outputs, self.num_classes, self.conf_thres, self.nms_thres)
308+
pred = self.postprocess(
309+
outputs, self.num_classes, self.conf_thres, self.nms_thres
310+
)
301311

302312
return pred
303313

@@ -308,11 +318,11 @@ def forward(self, x):
308318
self.model = self.model.to(self.device).eval()
309319
img = x["image"].unsqueeze(0).to(self.device)
310320

311-
from yolox.utils import postprocess
312-
313321
fpn_out = self.yolo_fpn(img)
314322
outputs = self.head(fpn_out)
315323

316-
pred = postprocess(outputs, self.num_classes, self.conf_thres, self.nms_thres)
324+
pred = self.postprocess(
325+
outputs, self.num_classes, self.conf_thres, self.nms_thres
326+
)
317327

318328
return pred

0 commit comments

Comments
 (0)