From fa548dfd7bbf18a0c5f2244183fdeaa60a527e08 Mon Sep 17 00:00:00 2001 From: henrytsui000 Date: Sat, 4 Jan 2025 02:54:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9A=20[Pass]=20format=20check=20and=20?= =?UTF-8?q?refactor=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yolo/tools/data_augmentation.py | 2 +- yolo/tools/solver.py | 5 +++-- yolo/utils/dataset_utils.py | 9 ++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/yolo/tools/data_augmentation.py b/yolo/tools/data_augmentation.py index 358c329..915534c 100644 --- a/yolo/tools/data_augmentation.py +++ b/yolo/tools/data_augmentation.py @@ -67,7 +67,7 @@ def __call__(self, image: Image, boxes): scale = min(self.target_width / img_width, self.target_height / img_height) new_width, new_height = int(img_width * scale), int(img_height * scale) - resized_image = image.resize((new_width, new_height), Image.LANCZOS) + resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS) pad_left = (self.target_width - new_width) // 2 pad_top = (self.target_height - new_height) // 2 diff --git a/yolo/tools/solver.py b/yolo/tools/solver.py index 61fc871..8246a66 100644 --- a/yolo/tools/solver.py +++ b/yolo/tools/solver.py @@ -48,8 +48,9 @@ def validation_step(self, batch, batch_idx): batch_size, images, targets, rev_tensor, img_paths = batch H, W = images.shape[2:] predicts = self.post_process(self.ema(images), image_size=[W, H]) - self.metric.update([to_metrics_format(predict) for predict in predicts], - [to_metrics_format(target) for target in targets]) + self.metric.update( + [to_metrics_format(predict) for predict in predicts], [to_metrics_format(target) for target in targets] + ) return predicts def on_validation_epoch_end(self): diff --git a/yolo/utils/dataset_utils.py b/yolo/utils/dataset_utils.py index 252b349..dd9a66a 100644 --- a/yolo/utils/dataset_utils.py +++ b/yolo/utils/dataset_utils.py @@ -104,13 +104,8 @@ def scale_segmentation( if "segmentation" in anno: seg_list = [item for sublist in anno["segmentation"] for item in sublist] elif "bbox" in anno: - x,y,width,height = anno["bbox"] - seg_list = [ - x, y, # Top-left corner - x + width, y, # Top-right corner - x + width, y + height, # Bottom-right corner - x, y + height # Bottom-left corner - ] + x, y, width, height = anno["bbox"] + seg_list = [x, y, x + width, y, x + width, y + height, x, y + height] scaled_seg_data = ( np.array(seg_list).reshape(-1, 2) / [w, h]