Example #1
0
def test_random_sized_crop_size():
    image = np.ones((100, 100, 3))
    bboxes = [[0.2, 0.3, 0.6, 0.8], [0.3, 0.4, 0.7, 0.9, 99]]
    aug = RandomSizedCrop((70, 90), 50, 50, p=1.)
    transformed = aug(image=image, bboxes=bboxes)
    assert transformed['image'].shape == (50, 50, 3)
    assert len(bboxes) == len(transformed['bboxes'])
Example #2
0
def test_random_sized_crop_size():
    image = np.ones((100, 100, 3))
    keypoints = [(0.2, 0.3, 0.6, 0.8), (0.3, 0.4, 0.7, 0.9, 99)]
    aug = RandomSizedCrop(min_max_height=(70, 90), height=50, width=50, p=1.0)
    transformed = aug(image=image, keypoints=keypoints)
    assert transformed["image"].shape == (50, 50, 3)
    assert len(keypoints) == len(transformed["keypoints"])
Example #3
0
def test_random_sized_crop_size():
    image = np.ones((100, 100, 3))
    bboxes = [[0.2, 0.3, 0.6, 0.8], [0.3, 0.4, 0.7, 0.9, 99]]
    aug = RandomSizedCrop(min_max_height=(70, 90), height=50, width=50, p=1.0)
    transformed = aug(image=image, bboxes=bboxes)
    assert transformed["image"].shape == (50, 50, 3)
    assert len(bboxes) == len(transformed["bboxes"])
import os
from PIL import Image
from torch.utils import data
import numpy as np
from torchvision import transforms as T
import cv2

##导入albumentations来做图像增强
input_size = 224
import albumentations
from albumentations.augmentations.transforms import Resize, RandomSizedCrop, ShiftScaleRotate, HorizontalFlip, Normalize, RandomBrightnessContrast, MotionBlur, Blur, GaussNoise, JpegCompression

train_transform = albumentations.Compose([
                                          RandomSizedCrop(min_max_height=(input_size//3,input_size//3),height=input_size,width=input_size),
                                          ShiftScaleRotate(p=0.3, scale_limit=0.25, border_mode=1, rotate_limit=25),
                                          HorizontalFlip(p=0.2),
                                          RandomBrightnessContrast(p=0.3, brightness_limit=0.25, contrast_limit=0.5),
                                          MotionBlur(p=.2),
                                          GaussNoise(p=.2),
                                          JpegCompression(p=.2, quality_lower=50),
                                          Normalize(mean=[0.485, 0.456, 0.406],
                                    std=[0.229, 0.224, 0.225])
])
val_transform = albumentations.Compose([
                                        Resize(input_size,input_size),
                                        Normalize(mean=[0.485, 0.456, 0.406],
                                    std=[0.229, 0.224, 0.225])
])

class MyDataset(data.Dataset):
    def __init__(self,root,transforms = None,is_train=True):
Example #5
0
 def __init__(self, **kwargs):
     self.obj = RandomSizedCrop(**kwargs)