MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / CustomResize

Class CustomResize

examples/FasterRCNN/common.py:29–62  ·  view source on GitHub ↗

Try resizing the shortest edge to a certain number while avoiding the longest edge to exceed max_size.

Source from the content-addressed store, hash-verified

27
28
29class CustomResize(ImageAugmentor):
30 """
31 Try resizing the shortest edge to a certain number
32 while avoiding the longest edge to exceed max_size.
33 """
34
35 def __init__(self, short_edge_length, max_size, interp=cv2.INTER_LINEAR):
36 """
37 Args:
38 short_edge_length ([int, int]): a [min, max] interval from which to sample the
39 shortest edge length.
40 max_size (int): maximum allowed longest edge length.
41 """
42 super(CustomResize, self).__init__()
43 if isinstance(short_edge_length, int):
44 short_edge_length = (short_edge_length, short_edge_length)
45 self._init(locals())
46
47 def get_transform(self, img):
48 h, w = img.shape[:2]
49 size = self.rng.randint(
50 self.short_edge_length[0], self.short_edge_length[1] + 1)
51 scale = size * 1.0 / min(h, w)
52 if h < w:
53 newh, neww = size, scale * w
54 else:
55 newh, neww = scale * h, size
56 if max(newh, neww) > self.max_size:
57 scale = self.max_size * 1.0 / max(newh, neww)
58 newh = newh * scale
59 neww = neww * scale
60 neww = int(neww + 0.5)
61 newh = int(newh + 0.5)
62 return ResizeTransform(h, w, newh, neww, self.interp)
63
64
65def box_to_point4(boxes):

Callers 2

predict_imageFunction · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected