当前位置: 首页>>代码示例>>Python>>正文


Python transforms.random_flip方法代码示例

本文整理汇总了Python中chainercv.transforms.random_flip方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.random_flip方法的具体用法?Python transforms.random_flip怎么用?Python transforms.random_flip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainercv.transforms的用法示例。


在下文中一共展示了transforms.random_flip方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_example

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def get_example(self, i):
        with Image.open(str(self.filepaths[i])) as f:
            target = img_to_chw_array(f)

        target = random_crop(target, (self.fine_size, self.fine_size))
        target = random_flip(target, x_random=True)
        if self.random_nn:
            source = resize(
                downscale_random_nearest_neighbor(target.copy()),
                (self.fine_size, self.fine_size), Image.NEAREST,
            )
        else:
            source = resize(
                resize(
                    target,
                    (self.fine_size // 2, self.fine_size // 2), Image.NEAREST,
                ),
                (self.fine_size, self.fine_size), Image.NEAREST,
            )
        return source, target 
开发者ID:mitaki28,项目名称:pixcaler,代码行数:22,代码来源:dataset.py

示例2: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, in_data):
        img, label = in_data
        img = random_sized_crop(img)
        img = resize(img, (224, 224))
        img = random_flip(img, x_random=True)
        img -= self.mean
        return img, label 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:9,代码来源:train_imagenet_multi.py

示例3: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, img):
        img = random_crop(img=img, size=self.resize_value)
        img = random_flip(img=img, x_random=True)
        img -= self.mean
        img /= self.std
        return img 
开发者ID:osmr,项目名称:imgclsmob,代码行数:8,代码来源:cifar10_cls_dataset.py

示例4: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, img):
        img = random_crop(img=img, size=self.resize_value)
        img = random_flip(img=img, x_random=True)
        img = pca_lighting(img=img, sigma=25.5)
        img = scale(img=img, size=self.resize_value, interpolation=self.interpolation)
        img = center_crop(img, self.input_image_size)
        img /= 255.0
        img -= self.mean
        img /= self.std
        return img 
开发者ID:osmr,项目名称:imgclsmob,代码行数:12,代码来源:imagenet1k_cls_dataset.py

示例5: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, in_data):
        img, mask, label = in_data
        bbox = mask_to_bbox(mask)
        _, orig_H, orig_W = img.shape
        img = self.fcis.prepare(img)
        _, H, W = img.shape
        scale = H / orig_H
        mask = transforms.resize(mask.astype(np.float32), (H, W))
        bbox = transforms.resize_bbox(bbox, (orig_H, orig_W), (H, W))

        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        mask = transforms.flip(mask, x_flip=params['x_flip'])
        bbox = transforms.flip_bbox(bbox, (H, W), x_flip=params['x_flip'])
        return img, mask, label, bbox, scale 
开发者ID:chainer,项目名称:chainercv,代码行数:17,代码来源:train_sbd.py

示例6: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, in_data):
        img, bbox, label = in_data
        _, H, W = img.shape
        img = self.light_head_rcnn.prepare(img)
        _, o_H, o_W = img.shape
        scale = o_H / H
        bbox = transforms.resize_bbox(bbox, (H, W), (o_H, o_W))

        # horizontally flip
        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        bbox = transforms.flip_bbox(
            bbox, (o_H, o_W), x_flip=params['x_flip'])

        return img, bbox, label, scale 
开发者ID:chainer,项目名称:chainercv,代码行数:17,代码来源:train_coco_multi.py

示例7: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, in_data):
        img, bbox, label = in_data
        _, H, W = img.shape
        img = self.faster_rcnn.prepare(img)
        _, o_H, o_W = img.shape
        scale = o_H / H
        bbox = transforms.resize_bbox(bbox, (H, W), (o_H, o_W))

        # horizontally flip
        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        bbox = transforms.flip_bbox(
            bbox, (o_H, o_W), x_flip=params['x_flip'])

        return img, bbox, label, scale 
开发者ID:chainer,项目名称:chainercv,代码行数:17,代码来源:train.py

示例8: test_random_flip

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def test_random_flip(self):
        img = np.random.uniform(size=(3, 24, 24))

        out, param = random_flip(
            img, y_random=True, x_random=True, return_param=True)
        y_flip = param['y_flip']
        x_flip = param['x_flip']

        expected = img
        if y_flip:
            expected = expected[:, ::-1, :]
        if x_flip:
            expected = expected[:, :, ::-1]
        np.testing.assert_equal(out, expected) 
开发者ID:chainer,项目名称:chainercv,代码行数:16,代码来源:test_random_flip.py

示例9: _data_augumentation

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def _data_augumentation(self, image):
        image = random_distort(image)
        image = random_flip(image, x_random=True)
        return image 
开发者ID:IshitaTakeshi,项目名称:RoadDamageDetector,代码行数:6,代码来源:road_damage_dataset.py

示例10: argument_image

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def argument_image(self, img, c_source, is_crop_random=True, is_flip_random=True):
        cW, cH = self.char_size
        fW, fH = self.fine_size
        pW, pH = ((fW - cW), (fH - cH))
        if is_crop_random:
            assert pW >= 0 and pW % 2 == 0 and pH >= 0 and pH % 2 == 0
            img = resize_contain(img, (fH + pH, fW + pW), img[:,0,0])
            img = random_crop_by_2(img, c_source, pH, pW, fH, fW)
        else:
            img = resize_contain(img, (fH, fW), img[:,0,0])
        if is_flip_random:
            img = random_flip(img, x_random=True)
        return img

    # return (source, img) 
开发者ID:mitaki28,项目名称:pixcaler,代码行数:17,代码来源:dataset.py

示例11: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, in_data):
        # There are five data augmentation steps
        # 1. Color augmentation
        # 2. Random expansion
        # 3. Random cropping
        # 4. Resizing with random interpolation
        # 5. Random horizontal flipping

        img, bbox, label = in_data

        # 1. Color augmentation
        img = random_distort(img)

        # 2. Random expansion
        if np.random.randint(2):
            img, param = transforms.random_expand(
                img, fill=self.mean, return_param=True)
            bbox = transforms.translate_bbox(
                bbox, y_offset=param['y_offset'], x_offset=param['x_offset'])

        # 3. Random cropping
        img, param = random_crop_with_bbox_constraints(
            img, bbox, return_param=True)
        bbox, param = transforms.crop_bbox(
            bbox, y_slice=param['y_slice'], x_slice=param['x_slice'],
            allow_outside_center=False, return_param=True)
        label = label[param['index']]

        # 4. Resizing with random interpolatation
        _, H, W = img.shape
        img = resize_with_random_interpolation(img, (self.size, self.size))
        bbox = transforms.resize_bbox(bbox, (H, W), (self.size, self.size))

        # 5. Random horizontal flipping
        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        bbox = transforms.flip_bbox(
            bbox, (self.size, self.size), x_flip=params['x_flip'])

        # Preparation for SSD network
        img -= self.mean
        mb_loc, mb_label = self.coder.encode(bbox, label)

        return img, mb_loc, mb_label 
开发者ID:chainer,项目名称:chainercv,代码行数:46,代码来源:train.py

示例12: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, in_data):
        if len(in_data) == 6:
            img, bbox, label, mask, crowd, area = in_data
        elif len(in_data) == 4:
            img, bbox, label, mask = in_data
        else:
            raise ValueError

        img = img.transpose(2, 0, 1)  # H, W, C -> C, H, W

        if not self.train:
            if len(in_data) == 6:
                return img, bbox, label, mask, crowd, area
            elif len(in_data) == 4:
                return img, bbox, label, mask
            else:
                raise ValueError

        imgs, sizes, scales = self.mask_rcnn.prepare([img])
        img = imgs[0]
        H, W = sizes[0]
        scale = scales[0]
        _, o_H, o_W = img.shape

        if len(bbox) > 0:
            bbox = transforms.resize_bbox(bbox, (H, W), (o_H, o_W))
        if len(mask) > 0:
            mask = transforms.resize(
                mask, size=(o_H, o_W), interpolation=0)

        # horizontally flip
        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        bbox = transforms.flip_bbox(
            bbox, (o_H, o_W), x_flip=params['x_flip'])
        if mask.ndim == 2:
            mask = transforms.flip(
                mask[None, :, :], x_flip=params['x_flip'])[0]
        else:
            mask = transforms.flip(mask, x_flip=params['x_flip'])

        return img, bbox, label, mask, scale 
开发者ID:wkentaro,项目名称:chainer-mask-rcnn,代码行数:44,代码来源:transforms.py

示例13: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import random_flip [as 别名]
def __call__(self, in_data):
        # There are five data augmentation steps
        # 1. Color augmentation
        # 2. Random expansion
        # 3. Random cropping
        # 4. Resizing with random interpolation
        # 5. Random horizontal flipping

        img, bbox, label = in_data

        bbox = np.array(bbox).astype(np.float32)

        if len(bbox) == 0:
            warnings.warn("No bounding box detected", RuntimeWarning)
            img = resize_with_random_interpolation(img, (self.size, self.size))
            mb_loc, mb_label = self.coder.encode(bbox, label)
            return img, mb_loc, mb_label

        # 1. Color augmentation
        img = random_distort(img)

        # 2. Random expansion
        if np.random.randint(2):
            img, param = transforms.random_expand(
                img, fill=self.mean, return_param=True)
            bbox = transforms.translate_bbox(
                bbox, y_offset=param['y_offset'], x_offset=param['x_offset'])

        # 3. Random cropping
        img, param = random_crop_with_bbox_constraints(
            img, bbox, return_param=True)
        bbox, param = transforms.crop_bbox(
            bbox, y_slice=param['y_slice'], x_slice=param['x_slice'],
            allow_outside_center=False, return_param=True)
        label = label[param['index']]

        # 4. Resizing with random interpolatation
        _, H, W = img.shape
        img = resize_with_random_interpolation(img, (self.size, self.size))
        bbox = transforms.resize_bbox(bbox, (H, W), (self.size, self.size))

        # 5. Random horizontal flipping
        img, params = transforms.random_flip(
            img, x_random=True, return_param=True)
        bbox = transforms.flip_bbox(
            bbox, (self.size, self.size), x_flip=params['x_flip'])

        mb_loc, mb_label = self.coder.encode(bbox, label)
        return img, mb_loc, mb_label 
开发者ID:IshitaTakeshi,项目名称:RoadDamageDetector,代码行数:51,代码来源:train_detector.py


注:本文中的chainercv.transforms.random_flip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。