可批量对图片进行旋转,增大,缩小等操作,生成新的图片
假设目录如下:
├── train_gen
└── train_org
└── sheep
└── 0.jpg
train_org是原始数据,子目录sheep为标签(注意源目录下必须要有子目录做为标签,即y),0.jpg为输入数据(即train_x)。 批量生成图片到train_gen/下
python代码
-
from keras.preprocessing import image
-
-
srcPath='/home/zm/download/jpg/test_gen/train_org/'
-
dstPath='/home/zm/download/jpg/test_gen/train_gen/'
-
-
dataGen = image.ImageDataGenerator(rescale=1. / 255, rotation_range = 45, zoom_range = 0.5)
-
genData = dataGen.flow_from_directory(srcPath, batch_size=1, shuffle=False, save_to_dir=dstPath,
-
save_prefix='gen', target_size=(224, 224))
-
-
for i in range(5):
-
genData.next()
执行
python3 ./img_gen.py
输出
Using TensorFlow backend.
Found 1 images belonging to 1 classes.
文件变化成如下
├── train_gen
│ ├── gen_0_1566435.png
│ ├── gen_0_2240910.png
│ ├── gen_0_4362670.png
│ ├── gen_0_6886943.png
│ └── gen_0_9432471.png
└── train_org
└── sheep
└── 0.jpg
作者:帅得不敢出门
阅读(11337) | 评论(0) | 转发(0) |