Skip to content
Permalink
Browse files

feat(image preprocessor): calculate offsetnd for each chunk

  • Loading branch information...
jemmyshin committed Jul 24, 2019
1 parent 9b42227 commit 04c9c74556be8dd343de1cdb6375dc744d4da531
@@ -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]]
@@ -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
@@ -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])

0 comments on commit 04c9c74

Please sign in to comment.
You can’t perform that action at this time.