Python 基于增强器图像生成的列车keras模型

Python 基于增强器图像生成的列车keras模型,python,tensorflow,keras,augmentor,Python,Tensorflow,Keras,Augmentor,我正在尝试使用library Augmentor中的keras_生成器来训练keras模型,但问题是我无法获得比我已有的更多的图像 现在我有了一个目录,其中包含: images/ 0/0.png 1/1.png ... z/z.png 我运行以下python代码: import Augmentor pipeline = Augmentor.Pipeline("images") pipeline.rotate(probability=0.7, max_left_rotation=10,

我正在尝试使用library Augmentor中的keras_生成器来训练keras模型,但问题是我无法获得比我已有的更多的图像

现在我有了一个目录,其中包含:

images/
 0/0.png
 1/1.png
 ...
 z/z.png
我运行以下python代码:

import Augmentor
pipeline = Augmentor.Pipeline("images")
pipeline.rotate(probability=0.7, max_left_rotation=10, max_right_rotation=10)
pipeline.zoom(probability=0.5, min_factor=1.1, max_factor=1.3)
pipeline.random_distortion(probability=0.8, grid_width=4, grid_height=4, magnitude=1)
pipeline.greyscale(1.0)
pipeline.invert(1.0)
pipeline.status()
它给出了一个输出:

    Initialised with 22 image(s) found.
Output directory set to images/output.Operations: 5
    0: RotateRange (probability=0.7 max_left_rotation=-10 max_right_rotation=10 )
    1: Zoom (probability=0.5 min_factor=1.1 max_factor=1.3 )
    2: Distort (probability=0.8 grid_width=4 grid_height=4 magnitude=1 randomise_magnitude=True )
    3: Greyscale (probability=1.0 )
    4: Invert (probability=1.0 )
Images: 22
Classes: 22
    Class index: 0 Class label: 0 
    ...
    Class index: 20 Class label: x 
    Class index: 21 Class label: y 
Dimensions: 1
    Width: 28 Height: 28
Formats: 1
     PNG
然后我创建一个模型:

from keras.preprocessing.image import ImageDataGenerator
from keras.models import Model
from keras.optimizers import Adam
from keras.layers import Conv2D, Input, Dropout, Flatten, Dense, MaxPooling2D

img_input = Input(shape=(28, 28, 1))
x = Conv2D(32, 3, activation='relu')(img_input)
x = Conv2D(64, 3, activation='relu')(x)
x = MaxPooling2D(2, 2)(x)
x = Dropout(0.25)(x)
x = Flatten()(x)
x = Dense(128, activation='relu')(x)
x = Dropout(0.5)(x)
output = Dense(22, activation='softmax')(x)

model = Model(img_input, output)
model.compile(loss='categorical_crossentropy',
              optimizer=Adam(),
              metrics=['acc'])
并给它一个发电机来训练:

generator = pipeline.keras_generator(batch_size=128)
model.fit_generator(generator, steps_per_epoch=len(pipeline.augmentor_images)/128, epochs=5, verbose=1)
它运行一个输出

    WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Epoch 1/5
1/0 [==============================================================================================================================================================================] - 1s 1s/step - loss: 3.1237 - acc: 0.0312
Epoch 2/5
1/0 [==============================================================================================================================================================================] - 0s 361ms/step - loss: 2.9429 - acc: 0.1797
Epoch 3/5
1/0 [==============================================================================================================================================================================] - 0s 298ms/step - loss: 2.7841 - acc: 0.2188
Epoch 4/5
1/0 [==============================================================================================================================================================================] - 0s 417ms/step - loss: 2.4919 - acc: 0.3672
Epoch 5/5
1/0 [==============================================================================================================================================================================] - 0s 439ms/step - loss: 2.2927 - acc: 0.3438

所以它只看到一张图片,它位于合适类的图像目录中。如果不将图片保存在磁盘上,我如何向它发送数千张图片?

当您执行
next(generator)
时,您会得到什么。你有和你的批量大小相等的元素吗?@borarak你好。是的,我得到的图像数组和标签数组与我的批次大小相等。当你执行
next(generator)
时,你会得到什么。你有和你的批量大小相等的元素吗?@borarak你好。是的,我得到的图像数组和标签数组等于我的批量大小