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 prepare_y(self, cfg: SampleCfg):
        img = self.masks[cfg.img_idx].astype(np.float32) / 255.0

        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,
                                    order=1)

        crop = crop.astype('float32')

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

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

        return np.expand_dims(crop, axis=3)
示例#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