本文整理汇总了Python中mxnet.image.random_crop方法的典型用法代码示例。如果您正苦于以下问题:Python image.random_crop方法的具体用法?Python image.random_crop怎么用?Python image.random_crop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mxnet.image
的用法示例。
在下文中一共展示了image.random_crop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward
# 需要导入模块: from mxnet import image [as 别名]
# 或者: from mxnet.image import random_crop [as 别名]
def forward(self, x):
if self.pad:
x_pad = np.pad(x.asnumpy(), self.pad,
mode='constant', constant_values=0)
return image.random_crop(nd.array(x_pad), *self._args)[0]
示例2: __call__
# 需要导入模块: from mxnet import image [as 别名]
# 或者: from mxnet.image import random_crop [as 别名]
def __call__(self, img: np.ndarray):
"""
对图片进行处理,先按照高度进行resize,resize之后如果宽度不足指定宽度,就补黑色像素,否则就强行缩放到指定宽度
:param img_path: 图片地址
:return:
"""
data_augment = False
if self.phase == 'train' and np.random.rand() > 0.5:
data_augment = True
if data_augment:
img_h = 40
img_w = 340
else:
img_h = self.img_h
img_w = self.img_w
h, w = img.shape[:2]
ratio_h = float(img_h) / h
new_w = int(w * ratio_h)
if new_w < img_w and self.pad:
img = cv2.resize(img, (new_w, img_h))
if len(img.shape) == 2:
img = np.expand_dims(img, 3)
step = np.zeros((img_h, img_w - new_w, img.shape[-1]), dtype=img.dtype)
img = np.column_stack((img, step))
else:
img = cv2.resize(img, (img_w, img_h))
if data_augment:
img = nd.array(img)
img, _ = image.random_crop(img, (self.img_w, self.img_h))
img = img.asnumpy()
return img
示例3: pre_processing
# 需要导入模块: from mxnet import image [as 别名]
# 或者: from mxnet.image import random_crop [as 别名]
def pre_processing(self, img):
"""
对图片进行处理
:param img_path: 图片
:return:
"""
data_augment = False
if self.phase == 'train' and np.random.rand() > 0.5:
data_augment = True
if data_augment:
img_h = 40
img_w = 340
else:
img_h = self.img_h
img_w = self.img_w
img = image.imdecode(img, 1 if self.img_channel == 3 else 0)
h, w = img.shape[:2]
ratio_h = float(img_h) / h
new_w = int(w * ratio_h)
if new_w < img_w:
img = image.imresize(img, w=new_w, h=img_h)
step = nd.zeros((img_h, img_w - new_w, self.img_channel), dtype=img.dtype)
img = nd.concat(img, step, dim=1)
else:
img = image.imresize(img, w=img_w, h=img_h)
if data_augment:
img, _ = image.random_crop(img, (self.img_w, self.img_h))
return img
示例4: voc_rand_crop
# 需要导入模块: from mxnet import image [as 别名]
# 或者: from mxnet.image import random_crop [as 别名]
def voc_rand_crop(feature, label, height, width):
"""Random cropping for images of the Pascal VOC2012 Dataset."""
feature, rect = image.random_crop(feature, (width, height))
label = image.fixed_crop(label, *rect)
return feature, label