Ejemplo n.º 1
0
def get_transform(train=True,
                  resize=(224, 224),
                  useImgaug=True,
                  advanced=False):
    if train:
        if useImgaug:
            transforms = bboxAug.Compose([
                bboxAug.Augment(advanced=advanced),
                bboxAug.Pad(),
                bboxAug.Resize(resize, False),
                bboxAug.ToTensor(),  # PIL --> tensor
                # bboxAug.Normalize()  # tensor --> tensor
                bboxAug.Normalize(image_std=[0.229, 0.224, 0.225])
            ])
        else:
            transforms = bboxAug.Compose([
                bboxAugv2.RandomHorizontalFlip(),
                bboxAugv2.ResizeFixMinAndRandomCrop(int(resize[0] * 1.1),
                                                    resize),  # 用于resize到固定大小
                # bboxAugv2.RandomDropAndResizeMaxMin(0.2, 600, 1000),  # 用于 fasterrecnn
                bboxAugv2.RandomLight(),
                bboxAugv2.RandomColor(),
                bboxAugv2.RandomChanels(),
                bboxAugv2.RandomNoise(),
                bboxAugv2.RandomBlur(),
                bboxAugv2.RandomRotate(),
                bboxAugv2.RandomAffine(),
                bboxAugv2.RandomDropPixelV2(),
                bboxAugv2.RandomCutMixV2(),
                bboxAugv2.RandomMosaic(),
                bboxAug.ToTensor(),  # PIL --> tensor
                # bboxAug.Normalize()  # tensor --> tensor
                bboxAug.Normalize(image_std=[0.229, 0.224, 0.225])
            ])
            """
            transforms = bboxAug.Compose([
                # bboxAug.RandomChoice(),
                bboxAug.RandomHorizontalFlip(),
                bboxAug.RandomBrightness(),
                bboxAug.RandomBlur(),
                bboxAug.RandomSaturation(),
                bboxAug.RandomHue(),
                # bboxAug.RandomRotate(angle=5),
                # bboxAug.RandomTranslate(),
                bboxAug.Pad(), bboxAug.Resize(resize, False),
                bboxAug.ToTensor(),  # PIL --> tensor
                # bboxAug.Normalize()  # tensor --> tensor
                bboxAug.Normalize(image_std=[0.229, 0.224, 0.225])
            ])
            """
    else:
        transforms = bboxAug.Compose([
            bboxAug.Pad(),
            bboxAug.Resize(resize, False),
            bboxAug.ToTensor(),  # PIL --> tensor
            # bboxAug.Normalize()  # tensor --> tensor
            bboxAug.Normalize(image_std=[0.229, 0.224, 0.225])
        ])

    return transforms
Ejemplo n.º 2
0
def get_transform_keypoints(train=True,
                            resize=(224, 224),
                            useImgaug=True,
                            advanced=False):
    if train:
        transforms = bboxAug.Compose([
            bboxAug.RandomHorizontalFlip(),
            bboxAug.RandomBrightness(),
            bboxAug.RandomBlur(),
            bboxAug.RandomSaturation(),
            bboxAug.RandomHue(),
            bboxAug.Pad(),
            bboxAug.Resize(resize, False),
            bboxAug.ToTensor(),  # PIL --> tensor
            # bboxAug.Normalize()  # tensor --> tensor
            bboxAug.Normalize(image_std=[0.229, 0.224, 0.225])
        ])
    else:
        transforms = bboxAug.Compose([
            bboxAug.Pad(),
            bboxAug.Resize(resize, False),
            bboxAug.ToTensor(),  # PIL --> tensor
            # bboxAug.Normalize()  # tensor --> tensor
            bboxAug.Normalize(image_std=[0.229, 0.224, 0.225])
        ])

    return transforms
Ejemplo n.º 3
0
def get_transforms(mode, advanced=False):
    if mode == 0:  # 推荐
        return bboxAug.Compose([
            bboxAug.Augment(advanced),
            bboxAugv2.ResizeFixMinAndRandomCrop(448,
                                                (416, 416)),  # 用于resize到固定大小
            # bboxAugv2.RandomDropAndResizeMaxMin(0.2,600,1000), # 用于 fasterrecnn
            bboxAugv2.RandomRotate(),
            bboxAugv2.RandomAffine(),
            bboxAugv2.RandomDropPixelV2(),
            # # bboxAugv2.RandomCutMixV2(),
            bboxAugv2.RandomMosaic(),
            # random.choice([bboxAugv2.RandomCutMixV2(),bboxAugv2.RandomMosaic()]),
            bboxAug.ToTensor(),  # PIL --> tensor
            # bboxAug.Normalize() # tensor --> tensor
        ])
    elif mode == 1:  # 推荐
        return bboxAug.Compose([
            bboxAugv2.RandomHorizontalFlip(),
            bboxAugv2.ResizeFixMinAndRandomCrop(448,
                                                (416, 416)),  # 用于resize到固定大小
            # bboxAugv2.RandomDropAndResizeMaxMin(0.2,600,1000), # 用于 fasterrecnn
            bboxAugv2.RandomLight(),
            bboxAugv2.RandomColor(),
            bboxAugv2.RandomChanels(),
            bboxAugv2.RandomNoise(),
            bboxAugv2.RandomBlur(),
            bboxAugv2.RandomRotate(),
            bboxAugv2.RandomAffine(),
            bboxAugv2.RandomDropPixelV2(),
            # bboxAugv2.RandomCutMixV2(),
            bboxAugv2.RandomMosaic(),
            # random.choice([bboxAugv2.RandomCutMixV2(),bboxAugv2.RandomMosaic()]),
            bboxAug.ToTensor(),  # PIL --> tensor
            # bboxAug.Normalize() # tensor --> tensor
        ])
    elif mode == 2:  # 不推荐
        return bboxAug.Compose([
            # bboxAug.RandomChoice(),
            bboxAug.RandomHorizontalFlip(),
            bboxAug.RandomBrightness(),
            bboxAug.RandomBlur(),
            bboxAug.RandomSaturation(),
            bboxAug.RandomHue(),
            bboxAug.RandomRotate(angle=5),
            # bboxAug.RandomTranslate(), # 有问题
            # bboxAug.Augment(False),
            bboxAug.Pad(),
            bboxAug.Resize((416, 416), False),
            # bboxAug.ResizeMinMax(600,1000),
            # bboxAug.ResizeFixAndPad(),
            # bboxAug.RandomHSV(),
            bboxAug.RandomCutout(),
            bboxAug.ToTensor(),  # PIL --> tensor
            # bboxAug.Normalize() # tensor --> tensor
        ])