當前位置: 首頁>>代碼示例>>Python>>正文


Python transforms.scale方法代碼示例

本文整理匯總了Python中chainercv.transforms.scale方法的典型用法代碼示例。如果您正苦於以下問題:Python transforms.scale方法的具體用法?Python transforms.scale怎麽用?Python transforms.scale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chainercv.transforms的用法示例。


在下文中一共展示了transforms.scale方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: export_onnx

# 需要導入模塊: from chainercv import transforms [as 別名]
# 或者: from chainercv.transforms import scale [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 scale [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 scale [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 scale [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 scale [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_scale

# 需要導入模塊: from chainercv import transforms [as 別名]
# 或者: from chainercv.transforms import scale [as 別名]
def test_scale(self):
        img = np.random.uniform(size=self.in_shape)

        out = scale(img, self.size, fit_short=self.fit_short,
                    interpolation=self.interpolation)
        self.assertEqual(out.shape, self.out_shape) 
開發者ID:chainer,項目名稱:chainercv,代碼行數:8,代碼來源:test_scale.py

示例7: test_scale_no_resize

# 需要導入模塊: from chainercv import transforms [as 別名]
# 或者: from chainercv.transforms import scale [as 別名]
def test_scale_no_resize(self):
        img = np.random.uniform(size=self.in_shape)

        out = scale(img, self.size, fit_short=self.fit_short,
                    interpolation=self.interpolation)
        self.assertIs(img, out) 
開發者ID:chainer,項目名稱:chainercv,代碼行數:8,代碼來源:test_scale.py


注:本文中的chainercv.transforms.scale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。