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

Function get_data

examples/HED/hed.py:188–234  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

186
187
188def get_data(name):
189 isTrain = name == 'train'
190 ds = dataset.BSDS500(name, shuffle=True)
191
192 class CropMultiple16(imgaug.ImageAugmentor):
193 def get_transform(self, img):
194 newh = img.shape[0] // 16 * 16
195 neww = img.shape[1] // 16 * 16
196 assert newh > 0 and neww > 0
197 diffh = img.shape[0] - newh
198 h0 = 0 if diffh == 0 else self.rng.randint(diffh)
199 diffw = img.shape[1] - neww
200 w0 = 0 if diffw == 0 else self.rng.randint(diffw)
201 return imgaug.CropTransform(h0, w0, newh, neww)
202
203 if isTrain:
204 shape_aug = [
205 imgaug.RandomResize(xrange=(0.7, 1.5), yrange=(0.7, 1.5),
206 aspect_ratio_thres=0.15),
207 imgaug.RotationAndCropValid(90),
208 CropMultiple16(),
209 imgaug.Flip(horiz=True),
210 imgaug.Flip(vert=True)
211 ]
212 else:
213 # the original image shape (321x481) in BSDS is not a multiple of 16
214 IMAGE_SHAPE = (320, 480)
215 shape_aug = [imgaug.CenterCrop(IMAGE_SHAPE)]
216 ds = AugmentImageComponents(ds, shape_aug, (0, 1), copy=False)
217
218 def f(m): # thresholding
219 m[m >= 0.50] = 1
220 m[m < 0.50] = 0
221 return m
222 ds = MapDataComponent(ds, f, 1)
223
224 if isTrain:
225 augmentors = [
226 imgaug.Brightness(63, clip=False),
227 imgaug.Contrast((0.4, 1.5)),
228 ]
229 ds = AugmentImageComponent(ds, augmentors, copy=False)
230 ds = BatchDataByShape(ds, 8, idx=0)
231 ds = MultiProcessRunnerZMQ(ds, 1)
232 else:
233 ds = BatchData(ds, 1)
234 return ds
235
236
237def view_data():

Callers 2

view_dataFunction · 0.70
get_configFunction · 0.70

Calls 7

CropMultiple16Class · 0.85
MapDataComponentClass · 0.85
BatchDataByShapeClass · 0.85
BatchDataClass · 0.85

Tested by

no test coverage detected