(name)
| 186 | |
| 187 | |
| 188 | def 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 | |
| 237 | def view_data(): |
no test coverage detected