当前位置:网站首页>Data enhancement

Data enhancement

2022-06-11 16:00:00 zhao_ crystal

Catalog

1. Implementation method of data enhancement

2. Data enhancement in tf In the implementation of

2.1  adopt ImageDataGenerator Enhance the data


1. Implementation method of data enhancement

(1) normalization
    Normalize the data to a certain range , Make the network easier to learn .

(2) Image transformation
  Flip , The tensile , tailoring , deformation ( Rich data )

(3) Color change
  Contrast , brightness

(4) Multiscale clipping

2. Data enhancement in tf In the implementation of

adopt keras.preprocessing.image.ImageDataGenerator Interface to implement data enhancement

rescale = 1./255, # Zoom all pixels to 0——1, Because the values of all pixels are 0——255 Between .

rotation_range = 40, # A way of image enhancement , such as ratation_range = 40, Indicates that the random rotation angle of the image is -40——40 Between degrees .

width_shift_range = 0.2, # Displacement in the horizontal direction , Less than 1, It is the ratio of displacement ; Greater than 1, Is the value of the moving pixel .width_shift_range = 0.2, Indicates random translation of the image 0——20%

height_shift_range = 0.2, # Displacement in the vertical direction

shear_range = 0.2, # Shear strength

zoom_range = 0.2, # Scaling strength

horizontal_flip = True, # Whether to do random inversion in the horizontal direction

fill_mode = 'nearest') # When processing pictures , Use when pixels need to be filled . such as , Enlarge the image , Some pixels need to be filled .

2.1  adopt ImageDataGenerator Enhance the data

#  Training data 
train_datagen= keras.preprocessing.image.ImageDataGenerator(
    rescale = 1./255, #  Zoom all pixels to 0——1, Because the values of all pixels are 0——255 Between .
    rotation_range = 40, #  A way of image enhancement , such as  ratation_range = 40,  Indicates that the random rotation angle of the image is -40——40 Between degrees .
    width_shift_range = 0.2, #  Displacement in the horizontal direction , Less than 1, It is the ratio of displacement ; Greater than 1, Is the value of the moving pixel .width_shift_range = 0.2, Indicates random translation of the image 0——20%
    height_shift_range = 0.2, #  Displacement in the vertical direction 
    shear_range = 0.2, #  Shear strength 
    zoom_range = 0.2, #  Scaling strength 
    horizontal_flip = True, #  Whether to do random inversion in the horizontal direction 
    fill_mode = 'nearest') #  When processing pictures , Use when pixels need to be filled . such as , Enlarge the image , Some pixels need to be filled .


train_generator = train_datagen.flow_from_directory(
    train_dir, 
    target_size = (height, width),
    batch_size = batch_size,
    seed = 7, 
    shuffle = True,
    class_mode = "categorical")

#  Validation data 
valid_datagen= keras.preprocessing.image.ImageDataGenerator(
    rescale = 1./255 #  Zoom all pixels to 0——1, Because the values of all pixels are 0——255 Between .
    )


valid_generator = train_datagen.flow_from_directory(
    valid_dir, 
    target_size = (height, width),
    batch_size = batch_size,
    seed = 7, 
    shuffle = False,
    class_mode = "categorical")

For more codes, see : This code is based on convolutional neural network .

原网站

版权声明
本文为[zhao_ crystal]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011938290260.html