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