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


Python transforms.center_crop方法代码示例

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


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

示例1: export_onnx

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import center_crop [as 别名]
def export_onnx(input_image_path, output_path, gpu, only_output=True):
    """Export ResNet50 model to ONNX graph

    'model.onnx' file will be exported under ``output_path``.
    """
    model = C.ResNet50(pretrained_model='imagenet', arch='fb')

    input_image = read_image(input_image_path)
    input_image = scale(input_image, 256)
    input_image = center_crop(input_image, (224, 224))
    input_image -= model.mean
    input_image = input_image[None, :]

    if gpu >= 0:
        model.to_gpu()
        input_image = chainer.cuda.to_gpu(input_image)

    if only_output:
        os.makedirs(output_path, exist_ok=True)
        name = os.path.join(output_path, 'model.onnx')
        export(model, input_image, filename=name)
    else:
        # an input and output given by Chainer will be also emitted
        # for using as test dataset
        export_testcase(model, input_image, output_path) 
开发者ID:chainer,项目名称:chainer,代码行数:27,代码来源:export.py

示例2: __call__

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

示例3: _preprocess

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import center_crop [as 别名]
def _preprocess(self, img):
        img = scale(img=img, size=self.scale_size)
        img = center_crop(img, self.crop_size)
        img /= 255.0
        img -= self.mean
        img /= self.std
        return img 
开发者ID:osmr,项目名称:imgclsmob,代码行数:9,代码来源:imagenet1k1.py

示例4: __call__

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import center_crop [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: _prepare

# 需要导入模块: from chainercv import transforms [as 别名]
# 或者: from chainercv.transforms import center_crop [as 别名]
def _prepare(self, img):
        """Prepare an image for feeding it to a model.

        This is a standard preprocessing scheme used by feature extraction
        models.
        First, the image is scaled or resized according to :math:`scale_size`.
        Note that this step is optional.
        Next, the image is cropped to :math:`crop_size`.
        Last, the image is mean subtracted by an array :obj:`mean`.

        Args:
            img (~numpy.ndarray): An image. This is in CHW format.
                The range of its value is :math:`[0, 255]`.

        Returns:
            ~numpy.ndarray:
            A preprocessed image. This is 4D array whose batch size is
            the number of crops.

        """
        if self.scale_size is not None:
            if isinstance(self.scale_size, int):
                img = scale(img, size=self.scale_size)
            else:
                img = resize(img, size=self.scale_size)
        else:
            img = img.copy()

        if self.crop == '10':
            imgs = ten_crop(img, self.crop_size)
        elif self.crop == 'center':
            imgs = center_crop(img, self.crop_size)[np.newaxis]

        imgs -= self.mean[np.newaxis]

        return imgs 
开发者ID:chainer,项目名称:chainercv,代码行数:38,代码来源:feature_predictor.py

示例6: test_center_crop

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

        out, param = center_crop(img, (24, 16), return_param=True)
        y_slice = param['y_slice']
        x_slice = param['x_slice']

        np.testing.assert_equal(out, img[:, y_slice, x_slice])
        self.assertEqual(y_slice, slice(12, 36))
        self.assertEqual(x_slice, slice(8, 24)) 
开发者ID:chainer,项目名称:chainercv,代码行数:12,代码来源:test_center_crop.py


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