Keras ImageDataGenerator - class like Save_Prefix?

How do I keep my enlarged images with a class label in the filename? Or, is there a way to find out which class a new image belongs to?

EDIT:

datagen = ImageDataGenerator(horizontal_flip=True, vertical_flip=True)
i = 0
for batch in datagen.flow_from_directory('data/train', target_size=
(100,100),
    shuffle=False, batch_size=batch_size, save_to_dir='data/train/'):
    i += 1
    if i > 20: # save 20 images
        break  # otherwise the generator would loop indefinitely
print("Saved flipped images")

      

I have three class subdirectories inside data / train. After that, I cannot determine which images were added, although I can see that about a third of the total images were saved. Is there something missing in my code to indicate that images should be named a class, and for each class to loop over to create new images?

EDIT # 2: Folder structure: data / train 3 classes in separate folders: n02088364, n02096585, n02108089 Newly generated images are saved in data / train and not in separate class folders.

+3


source to share


2 answers


# We draw a batch of images from the generator
batch = next(datagen)

# batch[0] is the list of images
# batch[1] is the list of associated classes

# We display the batch (here the batch is size 16) and their class
fig, m_axs = plt.subplots(1, 16, figsize = (26, 6))
for img, class_index_one_hot, ax1 in zip(batch[0], batch[1], m_axs.T):
    ax1.imshow(img)
    class_index = np.argmax(class_index_one_hot)
    ax1.set_title(str(class_index) + ':' + index_to_classes[class_index])
    ax1.axis('off')

      



+1


source


in your code, you can access the generated images class using a batch object. The package will be a tuple of length 2. The first element is an array containing all the batch images, the second element is an array containing all the batch image classes.



0


source







All Articles