def create_aug_pipeline_val(input_size):
     """Image Augmentation Pipeline for Validation/Test Set."""
     p_val = Pipeline()
     # # Center Crop
     # p_val.crop_centre(probability=1, percentage_area=0.9)
     # Resize the image to the desired input size of the model
     p_val.resize(probability=1, width=input_size[0], height=input_size[1])
     return p_val
示例#2
0
    def __init__(self, train=True, root='../data'):
        
        if train:
            self.dataset = MNIST(root=root, train=True)
        else:
            self.dataset = MNIST(root=root, train=False)

        self.transform = transforms.Compose( [transforms.ToTensor()] ) 

        self.p = Pipeline()
        self.p.random_distortion(probability=0.5, grid_width=7, grid_height=7, magnitude=1)
示例#3
0
 def __init__(self):
     self.augmentor_pipeline = Pipeline()
     self.augmentor_pipeline.add_operation(Operations.Crop(probability=1, width=64, height=64, centre=False))
     self.augmentor_pipeline.add_operation(
         Operations.Resize(probability=1, width=512, height=512, resample_filter="BILINEAR")
     )
     self.imgaug_transform = iaa.Sequential(
         [iaa.CropToFixedSize(width=64, height=64), iaa.Scale(size=512, interpolation="linear")]
     )
     self.solt_stream = slc.Stream(
         [slt.CropTransform(crop_size=(64, 64), crop_mode="r"), slt.ResizeTransform(resize_to=(512, 512))]
     )
示例#4
0
def make_pipeline(imageset_path, output_dir):
    """returns an augmentation pipeline for a given image set"""
    p = Pipeline(imageset_path, output_dir)
    p.random_distortion(probability=0.7,
                        grid_width=4,
                        grid_height=4,
                        magnitude=8)
    p.flip_left_right(probability=0.5)
    p.flip_top_bottom(probability=0.5)
    p.zoom(probability=0.3, min_factor=1.1, max_factor=1.4)
    p.rotate(probability=0.5, max_left_rotation=10, max_right_rotation=10)
    return p
示例#5
0
 def __init__(self):
     self.imgaug_transform = iaa.Sequential(
         [iaa.Multiply((1.5, 1.5), per_channel=False), iaa.Add((127, 127), per_channel=False)]
     )
     self.augmentor_pipeline = Pipeline()
     self.augmentor_pipeline.add_operation(
         Operations.RandomBrightness(probability=1, min_factor=1.5, max_factor=1.5)
     )
     self.augmentor_pipeline.add_operation(Operations.RandomContrast(probability=1, min_factor=1.5, max_factor=1.5))
     self.solt_stream = slc.Stream(
         [
             slt.ImageRandomBrightness(p=1, brightness_range=(127, 127)),
             slt.ImageRandomContrast(p=1, contrast_range=(1.5, 1.5)),
         ]
     )
    def create_aug_pipeline_train(input_size):
        """Image Augmentation Pipeline for Training Set."""

        p_train = Pipeline()
        # Random crop
        p_train.add_operation(CropPercentageRange(probability=1, min_percentage_area=0.8, max_percentage_area=1, centre=False))
        # Rotate the image by either 90, 180, or 270 degrees randomly
        p_train.rotate_random_90(probability=0.5)
        # Flip the image along its vertical axis
        p_train.flip_top_bottom(probability=0.5)
        # Flip the image along its horizontal axis
        p_train.flip_left_right(probability=0.5)
        # Random change brightness of the image
        p_train.random_brightness(probability=0.5, min_factor=0.9, max_factor=1.1)
        # Random change saturation of the image
        p_train.random_color(probability=0.5, min_factor=0.9, max_factor=1.1)
        # Resize the image to the desired input size of the model
        p_train.resize(probability=1, width=input_size[0], height=input_size[1])

        return p_train
    png = data.train.images[i]
    png = np.array(png, dtype='float')
    pixels = png.reshape((28, 28))
    image.imsave('image_no_{}.png'.format(i), pixels, cmap='gray')

# In[10]:

print(os.listdir())

# In[11]:

from Augmentor import Pipeline

# In[12]:

augmentor = Pipeline('/home/asherif844/sparkNotebooks/Ch03/MNIST/images')

# In[13]:

augmentor.rotate(probability=0.9, max_left_rotation=25, max_right_rotation=25)

# In[14]:

for i in range(1, 3):
    augmentor.sample(10)

# In[15]:

xtrain = data.train.images
ytrain = np.asarray(data.train.labels)
xtest = data.test.images
示例#8
0
随机20度范围内的旋转。变换时,边界外像素点的填充采用“reflect”模式。图像均被缩放为256*256大小,像素值被调整到0-1之间。
'''

# this is import from Augmentor third-party package
# import Augmentor
#
# # create a new pipeline
# file_path = "C:\\liyu\\files\\tiff\\cells"
# p = Augmentor.Pipeline(file_path)

from Augmentor.Pipeline import *
import time

# create a new pipeline
file_path = "C:\\liyu\\files\\tiff\\newtest"
p = Pipeline(file_path)

# add operations to the pipeline

# 水平翻转
p.flip_left_right(probability=0.8)

# # 垂直翻转
# p.flip_top_bottom(probability=0.5)
#
# # 随机90, 180, 270 度旋转
# p.rotate_random_90(probability=0.75)
#
# # 随机20度内旋转,不变形, 四角填充黑色,图片大小不变
# p.rotate_without_crop(probability=0.5, max_left_rotation=20, max_right_rotation=20)
#