in lib/datasets/data_input_helper.py [0:0]
def images_and_boxes_preprocessing(
imgs, split, crop_size, spatial_shift_pos, boxes=None):
height, width, _ = imgs[0].shape
if boxes is not None:
boxes[:, [0, 2]] *= width
boxes[:, [1, 3]] *= height
boxes = imgproc.clip_boxes_to_image(boxes, height, width)
# Now the image is in HWC, BGR format
if split == 1: # "train"
imgs, boxes = imgproc.random_short_side_scale_jitter_list(
imgs,
min_size=cfg.TRAIN.JITTER_SCALES[0],
max_size=cfg.TRAIN.JITTER_SCALES[1],
boxes=boxes,
)
imgs, boxes = imgproc.random_crop_list(
imgs, crop_size, order='HWC', boxes=boxes)
# random flip
imgs, boxes = imgproc.horizontal_flip_list(
0.5, imgs, order='HWC', boxes=boxes)
else:
# Short side to cfg.TEST_SCALE. Non-local and STRG uses 256.
imgs = [imgproc.scale(cfg.TEST.SCALE, img) for img in imgs]
if boxes is not None:
boxes = imgproc.scale_boxes(cfg.TEST.SCALE, boxes, height, width)
if cfg.AVA.FORCE_TEST_FLIP and cfg.DATASET == 'ava':
imgs, boxes = imgproc.horizontal_flip_list(
0.5, imgs, order='HWC', boxes=boxes,
force_flip=True)
# For the short side we do center crop.
imgs, boxes = imgproc.spatial_shift_crop_list(
crop_size, imgs, spatial_shift_pos, boxes=boxes)
# Convert image to CHW keeping BGR order
imgs = [imgproc.HWC2CHW(img) for img in imgs]
# image [0, 255] -> [0, 1]
imgs = [img / 255.0 for img in imgs]
imgs = [np.ascontiguousarray(
img.reshape((3, crop_size, crop_size))).astype(np.float32)
for img in imgs]
# do color augmentation (after divided by 255.0)
if cfg.TRAIN.USE_COLOR_AUGMENTATION and split == 1:
imgs = color_augmentation_list(imgs)
# now, normalize by mean and std
imgs = [imgproc.color_normalization(img, DATA_MEAN, DATA_STD)
for img in imgs]
# 3, 224, 224 -> 3, 32, 224, 224
imgs = np.concatenate(
[np.expand_dims(img, axis=1) for img in imgs], axis=1)
# Kinetics pre-training uses RGB!!
if not cfg.MODEL.USE_BGR:
# BGR to RGB.
imgs = imgs[::-1, ...]
if boxes is not None:
boxes = imgproc.clip_boxes_to_image(boxes, crop_size, crop_size)
return imgs, boxes