def generate_x(self, cfg: SampleCfg):
        img = scipy.misc.imread(dataset.image_crop_fn(cfg.fish_classification.video_id, cfg.fish_classification.frame))

        crop = utils.get_image_crop(full_rgb=img, rect=cfg.rect,
                                    scale_rect_x=cfg.scale_rect_x, scale_rect_y=cfg.scale_rect_y,
                                    shift_x_ratio=cfg.shift_x_ratio, shift_y_ratio=cfg.shift_y_ratio,
                                    angle=cfg.angle, out_size=INPUT_ROWS)

        crop = crop.astype('float32')
        if cfg.saturation != 0.5:
            crop = img_augmentation.saturation(crop, variance=0.2, r=cfg.saturation)

        if cfg.contrast != 0.5:
            crop = img_augmentation.contrast(crop, variance=0.25, r=cfg.contrast)

        if cfg.brightness != 0.5:
            crop = img_augmentation.brightness(crop, variance=0.3, r=cfg.brightness)

        if cfg.hflip:
            crop = img_augmentation.horizontal_flip(crop)

        if cfg.vflip:
            crop = img_augmentation.vertical_flip(crop)

        if cfg.blurred_by_downscaling != 1:
            crop = img_augmentation.blurred_by_downscaling(crop, 1.0 / cfg.blurred_by_downscaling)
        return crop * 255.0
示例#2
0
    def generate_xy(self, cfg: SampleCfg):
        img = scipy.misc.imread(dataset.image_fn(cfg.detection.video_id, cfg.detection.frame, is_test=self.is_test))
        crop = skimage.transform.warp(img, cfg.transformation, mode='edge', order=3, output_shape=(INPUT_ROWS, INPUT_COLS))

        detection = cfg.detection

        if detection.class_id > 0:
            coords = np.array([[detection.x1, detection.y1], [detection.x2, detection.y2]])
            coords_in_crop = cfg.transformation.inverse(coords)
            aspect_ratio = dataset.ASPECT_RATIO_TABLE[dataset.CLASSES[detection.class_id]]
            coords_box0, coords_box1 = utils.bbox_for_line(coords_in_crop[0, :], coords_in_crop[1, :], aspect_ratio)
            coords_box0 /= np.array([INPUT_COLS, INPUT_ROWS])
            coords_box1 /= np.array([INPUT_COLS, INPUT_ROWS])
            targets = [coords_box0[0], coords_box0[1], coords_box1[0], coords_box1[1]]

            # print(detection.class_id, dataset.CLASSES[detection.class_id], aspect_ratio, coords_box0, coords_box1)

            cls = [0] * (NUM_CLASSES - 1)
            cls[detection.class_id-1] = 1
            targets = np.array([targets+cls])
        else:
            targets = np.array([])

        crop = crop.astype('float32')
        if cfg.saturation != 0.5:
            crop = img_augmentation.saturation(crop, variance=0.25, r=cfg.saturation)

        if cfg.contrast != 0.5:
            crop = img_augmentation.contrast(crop, variance=0.25, r=cfg.contrast)

        if cfg.brightness != 0.5:
            crop = img_augmentation.brightness(crop, variance=0.3, r=cfg.brightness)

        if cfg.hflip:
            crop, targets = self.horizontal_flip(crop, targets)

        if cfg.vflip:
            crop, targets = self.vertical_flip(crop, targets)

        crop = img_augmentation.blurred_by_downscaling(crop, 1.0/cfg.blurred_by_downscaling)

        return crop*255.0, targets
示例#3
0
    def prepare_x(self, cfg: SampleCfg):
        img = self.images[cfg.img_idx]
        crop = utils.get_image_crop(full_rgb=img,
                                    rect=Rect(0, 0, IMG_WITH, IMG_HEIGHT),
                                    scale_rect_x=cfg.scale_rect_x,
                                    scale_rect_y=cfg.scale_rect_y,
                                    shift_x_ratio=cfg.shift_x_ratio,
                                    shift_y_ratio=cfg.shift_y_ratio,
                                    angle=cfg.angle,
                                    out_size=IMG_WITH)

        crop = crop.astype('float32')
        if cfg.saturation != 0.5:
            crop = img_augmentation.saturation(crop,
                                               variance=0.2,
                                               r=cfg.saturation)

        if cfg.contrast != 0.5:
            crop = img_augmentation.contrast(crop,
                                             variance=0.25,
                                             r=cfg.contrast)

        if cfg.brightness != 0.5:
            crop = img_augmentation.brightness(crop,
                                               variance=0.3,
                                               r=cfg.brightness)

        if cfg.hflip:
            crop = img_augmentation.horizontal_flip(crop)

        if cfg.vflip:
            crop = img_augmentation.vertical_flip(crop)

        if cfg.blurred_by_downscaling != 1:
            crop = img_augmentation.blurred_by_downscaling(
                crop, 1.0 / cfg.blurred_by_downscaling)

        return preprocess_input(crop * 255.0)
示例#4
0
    def gen_x(self, cfg: SampleCfg):
        if cfg.scale == 1.0:
            crop = self.gen_img_crop(img=cfg.img, row=cfg.row,
                                     col=cfg.col).astype(np.float32)
        else:
            crop = utils.crop_zero_pad(cfg.img,
                                       x=cfg.col,
                                       y=cfg.row,
                                       w=int(self.crop_size * cfg.scale),
                                       h=int(self.crop_size * cfg.scale))
            # print(crop.shape, crop.dtype)
            crop = imresize(crop, [self.crop_size, self.crop_size],
                            interp='bicubic')

        crop = crop / 255.0
        if cfg.saturation != 0.5:
            crop = img_augmentation.saturation(crop,
                                               variance=0.25,
                                               r=cfg.saturation)

        if cfg.contrast != 0.5:
            crop = img_augmentation.contrast(crop,
                                             variance=0.5,
                                             r=cfg.contrast)

        if cfg.brightness != 0.5:
            crop = img_augmentation.brightness(crop,
                                               variance=0.7,
                                               r=cfg.brightness)

        if cfg.hflip:
            crop = img_augmentation.horizontal_flip(crop)

        if cfg.vflip:
            crop = img_augmentation.vertical_flip(crop)

        return crop * 255.0