1. 程式人生 > 其它 >ImageDataGenerator部分引數理解

ImageDataGenerator部分引數理解

技術標籤:計算機視覺pythontensorflow

此chapter為引數見解和怎麼測引數的過程

#僅介紹以下引數,圖片增強
from tensorflow.keras.preprocessing.image import ImageDataGenerator
datagen=ImageDataGenerator(rotation_range=40,#隨機旋轉角度
                          width_shift_range=0.2,#隨機水平遷移
                          height_shift_range=0.2,#隨機垂直遷移
                          shear_range=
0.2,#隨機剪下 zoom_range=0.2,#隨機放大 horizontal_flip=True,#映象 fill_mode='nearest'#畫素填充,‘constant',‘nearest',‘reflect'或‘wrap'之一,當進行變換時超出邊界的點將根據本引數給定的方法進行處理)

原圖

原圖

rotation_range

from tensorflow.keras.preprocessing import image
from tensorflow.
keras.preprocessing.image import ImageDataGenerator import matplotlib.pyplot as plt img = image.load_img('1.jpg') img_na=image.img_to_array(img) img_na=img_na.reshape((1,)+img_na.shape) datagen=ImageDataGenerator( rotation_range=40, # width_shift_range=0.2, # height_shift_range=0.2,
# shear_range=0.2, # zoom_range=0.2, # horizontal_flip=True, # fill_mode='nearest' ) def img_show(): i=0 for batch in datagen.flow(img_na,batch_size=1): plt.figure() imgplot=plt.imshow(image.array_to_img(batch[0])) plt.axis('off') if i%4==0: break return img_show()

在這裡插入圖片描述

width_shift_rangw,height_shift_range

datagen=ImageDataGenerator(
#                           rotation_range=40,
                           width_shift_range=0.2,
                           height_shift_range=0.2,
#                           shear_range=0.2,
#                           zoom_range=0.2,
#                           horizontal_flip=True,
#                           fill_mode='nearest'
                          )
img_show()

在這裡插入圖片描述

horizontal_flip=True

datagen=ImageDataGenerator(
#     rotation_range=40,
#                           width_shift_range=0.2,
#                           height_shift_range=0.2,
#                           shear_range=0.5,
#                           zoom_range=0.2,
                          horizontal_flip=True,
#                           fill_mode='nearest'
                          )

img_show()

在這裡插入圖片描述

zoom_range

datagen=ImageDataGenerator(
#     rotation_range=40,
#                           width_shift_range=0.2,
#                           height_shift_range=0.2,
#                           shear_range=0.5,
                          zoom_range=0.2,
#                           horizontal_flip=True,
#                           fill_mode='nearest'
                          )![在這裡插入圖片描述](https://img-blog.csdnimg.cn/20201210114317965.png#pic_center)

img_show()

在這裡插入圖片描述