當前位置: 首頁>>代碼示例>>Python>>正文


Python transforms.Compose方法代碼示例

本文整理匯總了Python中transforms.Compose方法的典型用法代碼示例。如果您正苦於以下問題:Python transforms.Compose方法的具體用法?Python transforms.Compose怎麽用?Python transforms.Compose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在transforms的用法示例。


在下文中一共展示了transforms.Compose方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SSDTransform

# 需要導入模塊: import transforms [as 別名]
# 或者: from transforms import Compose [as 別名]
def SSDTransform(size, color_jitter=True, scale=(0.1, 1), expand=(1, 4), min_area_frac=0.25):
    transforms = []
    if color_jitter:
        transforms.append(
            InputTransform(
                ColorJitter(
                    brightness=0.1, contrast=0.5,
                    saturation=0.5, hue=0.05,
                )
            )
        )
    transforms += [
        RandomApply([
            RandomExpand(expand),
        ]),
        RandomChoice([
            UseOriginal(),
            RandomSampleCrop(),
            RandomResizedCrop(size, scale=scale, ratio=(1/2, 2/1), min_area_frac=min_area_frac),
        ]),
        RandomHorizontalFlip(),
        Resize(size)
    ]
    return Compose(transforms) 
開發者ID:qixuxiang,項目名稱:Pytorch_Lightweight_Network,代碼行數:26,代碼來源:__init__.py

示例2: read_image

# 需要導入模塊: import transforms [as 別名]
# 或者: from transforms import Compose [as 別名]
def read_image(img_path):
    """Keep reading image until succeed.
    This can avoid IOError incurred by heavy IO process."""
    got_img = False
    if not osp.exists(img_path):
        raise IOError("{} does not exist".format(img_path))
    while not got_img:
        try:
            img = Image.open(img_path).convert('RGB')
            got_img = True
        except IOError:
            print("IOError incurred when reading '{}'. Will redo. Don't worry. Just chill.".format(img_path))
            pass

    transform_test = T.Compose([
        T.Resize((args.height, args.width)),
        T.ToTensor(),
        T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ])
    img = transform_test(img)
    return img 
開發者ID:SamvitJ,項目名稱:ReXCam,代碼行數:23,代碼來源:train_img_model_xent.py

示例3: get_coco

# 需要導入模塊: import transforms [as 別名]
# 或者: from transforms import Compose [as 別名]
def get_coco(root, image_set, transforms):
    PATHS = {
        "train": ("train2017", os.path.join("annotations", "instances_train2017.json")),
        "val": ("val2017", os.path.join("annotations", "instances_val2017.json")),
        # "train": ("val2017", os.path.join("annotations", "instances_val2017.json"))
    }
    CAT_LIST = [0, 5, 2, 16, 9, 44, 6, 3, 17, 62, 21, 67, 18, 19, 4,
                1, 64, 20, 63, 7, 72]

    transforms = Compose([
        FilterAndRemapCocoCategories(CAT_LIST, remap=True),
        ConvertCocoPolysToMask(),
        transforms
    ])

    img_folder, ann_file = PATHS[image_set]
    img_folder = os.path.join(root, img_folder)
    ann_file = os.path.join(root, ann_file)

    dataset = torchvision.datasets.CocoDetection(img_folder, ann_file, transforms=transforms)

    if image_set == "train":
        dataset = _coco_remove_images_without_annotations(dataset, CAT_LIST)

    return dataset 
開發者ID:yechengxi,項目名稱:deconvolution,代碼行數:27,代碼來源:coco_utils.py

示例4: get_transform

# 需要導入模塊: import transforms [as 別名]
# 或者: from transforms import Compose [as 別名]
def get_transform(mode,base_size):
    #base_size = 520
    #crop_size = 480
    crop_size=int(480*base_size/520)

    min_size = int((0.5 if mode=='train' else 1.0) * base_size)
    max_size = int((2.0 if mode=='train' else 1.0) * base_size)
    transforms = []
    transforms.append(T.RandomResize(min_size, max_size))
    if mode=='train':
        transforms.append(T.RandomHorizontalFlip(0.5))
        transforms.append(T.RandomCrop(crop_size))
    transforms.append(T.ToTensor())
    transforms.append(T.Normalize(mean=[0.485, 0.456, 0.406],
                                std=[0.229, 0.224, 0.225]))

    return T.Compose(transforms) 
開發者ID:yechengxi,項目名稱:deconvolution,代碼行數:19,代碼來源:train.py

示例5: __init__

# 需要導入模塊: import transforms [as 別名]
# 或者: from transforms import Compose [as 別名]
def __init__(self, batch_size, use_gpu, num_workers):
        transform = transforms.Compose([
            transforms.ToTensor(),
            transforms.Normalize((0.1307,), (0.3081,))
        ])

        pin_memory = True if use_gpu else False

        trainset = torchvision.datasets.MNIST(root='./data/mnist', train=True, download=True, transform=transform)
        
        trainloader = torch.utils.data.DataLoader(
            trainset, batch_size=batch_size, shuffle=True,
            num_workers=num_workers, pin_memory=pin_memory,
        )
        
        testset = torchvision.datasets.MNIST(root='./data/mnist', train=False, download=True, transform=transform)
        
        testloader = torch.utils.data.DataLoader(
            testset, batch_size=batch_size, shuffle=False,
            num_workers=num_workers, pin_memory=pin_memory,
        )

        self.trainloader = trainloader
        self.testloader = testloader
        self.num_classes = 10 
開發者ID:KaiyangZhou,項目名稱:pytorch-center-loss,代碼行數:27,代碼來源:datasets.py


注:本文中的transforms.Compose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。