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

Method get_transform

tensorpack/dataflow/imgaug/misc.py:117–152  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

115 logger.warn("aspect_ratio_thres==0, yrange is not used!")
116
117 def get_transform(self, img):
118 cnt = 0
119 h, w = img.shape[:2]
120
121 def get_dest_size():
122 if self._is_scale:
123 sx = self._rand_range(*self.xrange)
124 if self.aspect_ratio_thres == 0:
125 sy = sx
126 else:
127 sy = self._rand_range(*self.yrange)
128 destX = max(sx * w, self.minimum[0])
129 destY = max(sy * h, self.minimum[1])
130 else:
131 sx = self._rand_range(*self.xrange)
132 if self.aspect_ratio_thres == 0:
133 sy = sx * 1.0 / w * h
134 else:
135 sy = self._rand_range(*self.yrange)
136 destX = max(sx, self.minimum[0])
137 destY = max(sy, self.minimum[1])
138 return (int(destX + 0.5), int(destY + 0.5))
139
140 while True:
141 destX, destY = get_dest_size()
142 if self.aspect_ratio_thres > 0: # don't check when thres == 0
143 oldr = w * 1.0 / h
144 newr = destX * 1.0 / destY
145 diff = abs(newr - oldr) / oldr
146 if diff >= self.aspect_ratio_thres + 1e-5:
147 cnt += 1
148 if cnt > 50:
149 logger.warn("RandomResize failed to augment an image")
150 return ResizeTransform(h, w, h, w, self.interp)
151 continue
152 return ResizeTransform(h, w, destY, destX, self.interp)
153
154
155class Transpose(ImageAugmentor):

Callers

nothing calls this directly

Calls 1

ResizeTransformClass · 0.85

Tested by

no test coverage detected