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