本文整理汇总了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)
示例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
示例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
示例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
示例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
示例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)
示例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)