From 04c9c74556be8dd343de1cdb6375dc744d4da531 Mon Sep 17 00:00:00 2001 From: Jem Date: Wed, 24 Jul 2019 11:00:40 +0800 Subject: [PATCH] feat(image preprocessor): calculate offsetnd for each chunk --- gnes/preprocessor/image/base.py | 8 ++++---- gnes/preprocessor/image/segmentation.py | 6 ++---- gnes/preprocessor/image/sliding_window.py | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/gnes/preprocessor/image/base.py b/gnes/preprocessor/image/base.py index d1e86f94..a557cbe9 100644 --- a/gnes/preprocessor/image/base.py +++ b/gnes/preprocessor/image/base.py @@ -32,14 +32,14 @@ def __init__(self, def _get_all_chunks_weight(self, image_set: List['np.ndarray']) -> List[float]: pass - @classmethod - def _torch_transform(cls, image): + @staticmethod + def _torch_transform(image): import torchvision.transforms as transforms return transforms.Compose([transforms.ToTensor(), transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))])(image) - @classmethod - def _get_all_subarea(cls, image): + @staticmethod + def _get_all_subarea(image): from itertools import product x_list = [0, image.size[0] / 3, 2 * image.size[0] / 3, image.size[0]] y_list = [0, image.size[1] / 3, 2 * image.size[1] / 3, image.size[1]] diff --git a/gnes/preprocessor/image/segmentation.py b/gnes/preprocessor/image/segmentation.py index f6c2bf05..b5a6392f 100644 --- a/gnes/preprocessor/image/segmentation.py +++ b/gnes/preprocessor/image/segmentation.py @@ -91,8 +91,8 @@ def _get_seg_offset_nd(self, all_subareas: List[List[int]], index: List[List[int iou_list = [self._cal_iou(area, chunk) for area in all_subareas] return index[int(np.argmax(iou_list))][:2] - @classmethod - def _cal_area(cls, coordinate: List[int]): + @staticmethod + def _cal_area(coordinate: List[int]): return (coordinate[2] - coordinate[0]) * (coordinate[3] - coordinate[1]) def _cal_iou(self, image: List[int], chunk: List[int]) -> float: @@ -105,7 +105,5 @@ def _cal_iou(self, image: List[int], chunk: List[int]) -> float: y2 = min(chunk[3], image[3]) overlap_area = max(0, x2 - x1) * max(0, y2 - y1) - iou = overlap_area / (chunk_area + image_area - overlap_area) - return iou diff --git a/gnes/preprocessor/image/sliding_window.py b/gnes/preprocessor/image/sliding_window.py index ff181893..bef92f53 100644 --- a/gnes/preprocessor/image/sliding_window.py +++ b/gnes/preprocessor/image/sliding_window.py @@ -97,8 +97,8 @@ def _get_slid_offset_nd(self, all_subareas: List[List[int]], index: List[List[in location = [i for i in range(len(location_list)) if location_list[i] is True][0] return index[location][:2] - @classmethod - def _get_location(cls, all_subareas: List[List[int]], center_point: List[float]) -> List[bool]: + @staticmethod + def _get_location(all_subareas: List[List[int]], center_point: List[float]) -> List[bool]: location_list = [] x_boundary = max([x[1] for x in all_subareas]) y_boundary = max([y[3] for y in all_subareas])