Keras ImageDataGenerator.flow文件名

时间:2018-03-05 19:44:19

标签: python image-processing keras generator saving-data

我有一个包含2500个编号图像的文件夹和一个labels.txt文件,其中包含图像文件名编号顺序的逗号分隔标签。

我想生成随机旋转(原始训练样本数量的10倍,总共25000个),保存编号为1到25000的新图像,然后用逗号创建一个新的labels.txt文件按编号图像的顺序分隔标签值。

我采用这种方法的主要问题是,我似乎无法将batch_size设置为大于图像总数(理想情况下),或将save_prefix设置为一个迭代器,计算图像忽略批号(因为如果我做10批2500我认为名称将搞砸)。有没有办法做到这一点?到目前为止,这是我的代码:

n_images = 2500    

datagen = ImageDataGenerator(rotation_range=180)

# fit parameters from data
datagen.fit(X_train)

# configure batch size and retrieve one batch of images
for X_batch, y_batch in datagen.flow(X_train, y_train,
                                     seed=42,
                                     batch_size=10*n_images, 
                                     save_to_dir=augment_path, 
                                     save_prefix='aug', 
                                     save_format='png', 
                                     shuffle=False):

    # convert labels back and write to file
    nums = y_batch.argmax(axis=1)+1
    write_labels = ','.join([str(i) for i in nums.tolist()])+','
    f = open(augment_path+"/labels.txt", "a+")
    f.write(write_labels)
    f.close()

    break

此外,添加到保存图像的最后一个数字表示什么?例如,aug_0_1685.png

0 个答案:

没有答案