Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(image preprocessor): calculate offsetnd for each chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
jemmyshin committed Jul 24, 2019
1 parent 9b42227 commit 04c9c74
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions gnes/preprocessor/image/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
6 changes: 2 additions & 4 deletions gnes/preprocessor/image/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions gnes/preprocessor/image/sliding_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 04c9c74

Please sign in to comment.