Augmentor used in fb.resnet.torch, for BGR images in range [0,255].
(isTrain)
| 26 | |
| 27 | |
| 28 | def fbresnet_augmentor(isTrain): |
| 29 | """ |
| 30 | Augmentor used in fb.resnet.torch, for BGR images in range [0,255]. |
| 31 | """ |
| 32 | interpolation = cv2.INTER_CUBIC |
| 33 | # linear seems to have more stable performance. |
| 34 | # but we keep cubic for compatibility with old models |
| 35 | if isTrain: |
| 36 | augmentors = [ |
| 37 | imgaug.GoogleNetRandomCropAndResize(interp=interpolation), |
| 38 | imgaug.ToFloat32(), # avoid frequent casting in each color augmentation |
| 39 | # It's OK to remove the following augs if your CPU is not fast enough. |
| 40 | # Removing brightness/contrast/saturation does not have a significant effect on accuracy. |
| 41 | # Removing lighting leads to a tiny drop in accuracy. |
| 42 | imgaug.RandomOrderAug( |
| 43 | [imgaug.BrightnessScale((0.6, 1.4)), |
| 44 | imgaug.Contrast((0.6, 1.4), rgb=False), |
| 45 | imgaug.Saturation(0.4, rgb=False), |
| 46 | # rgb-bgr conversion for the constants copied from fb.resnet.torch |
| 47 | imgaug.Lighting(0.1, |
| 48 | eigval=np.asarray( |
| 49 | [0.2175, 0.0188, 0.0045][::-1]) * 255.0, |
| 50 | eigvec=np.array( |
| 51 | [[-0.5675, 0.7192, 0.4009], |
| 52 | [-0.5808, -0.0045, -0.8140], |
| 53 | [-0.5836, -0.6948, 0.4203]], |
| 54 | dtype='float32')[::-1, ::-1] |
| 55 | )]), |
| 56 | imgaug.ToUint8(), |
| 57 | imgaug.Flip(horiz=True), |
| 58 | ] |
| 59 | else: |
| 60 | augmentors = [ |
| 61 | imgaug.ResizeShortestEdge(256, interp=interpolation), |
| 62 | imgaug.CenterCrop((224, 224)), |
| 63 | ] |
| 64 | return augmentors |
| 65 | |
| 66 | |
| 67 | def get_imagenet_dataflow( |
no outgoing calls
no test coverage detected