本文整理匯總了Python中torchvision.transforms.transforms.RandomCrop方法的典型用法代碼示例。如果您正苦於以下問題:Python transforms.RandomCrop方法的具體用法?Python transforms.RandomCrop怎麽用?Python transforms.RandomCrop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchvision.transforms.transforms
的用法示例。
在下文中一共展示了transforms.RandomCrop方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_transforms
# 需要導入模塊: from torchvision.transforms import transforms [as 別名]
# 或者: from torchvision.transforms.transforms import RandomCrop [as 別名]
def get_transforms(eval=False, aug=None):
trans = []
if aug["randcrop"] and not eval:
trans.append(transforms.RandomCrop(aug["randcrop"]))
if aug["randcrop"] and eval:
trans.append(transforms.CenterCrop(aug["randcrop"]))
if aug["flip"] and not eval:
trans.append(transforms.RandomHorizontalFlip())
if aug["grayscale"]:
trans.append(transforms.Grayscale())
trans.append(transforms.ToTensor())
trans.append(transforms.Normalize(mean=aug["bw_mean"], std=aug["bw_std"]))
elif aug["mean"]:
trans.append(transforms.ToTensor())
trans.append(transforms.Normalize(mean=aug["mean"], std=aug["std"]))
else:
trans.append(transforms.ToTensor())
trans = transforms.Compose(trans)
return trans