Keras flow_from_directory class index

I used it manually, but now I am using flow_from_directory to train my network with my own data. I just have one question. When I do model.predict (), how can I know that my index 0 for predictions is in the category of categories and index 1 is in the category of cats?

The code I am using is as follows.

train_datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
        train_images_path,  
        target_size=(64, 64),  
        batch_size=batch_size)  


validation_generator = test_datagen.flow_from_directory(
        validate_images_path,
        target_size=(64, 64),
        batch_size=batch_size)
early_stopping = keras.callbacks.EarlyStopping(monitor='val_acc', min_delta=0, patience=3, verbose=1, mode='auto')
history = model.fit_generator(
        train_generator,
        steps_per_epoch=1700,
        epochs=epochs,
        verbose=1,
        callbacks=[early_stopping],
        validation_data=validation_generator,
        validation_steps=196
)

      

What I wanted to know was the pairs of images and the sign of truth.

thank

+3


source to share


3 answers


You can have an index of each class generated by the generator with the class_indices property.

print(validation_generator.class_indices)

      



Plain...

+4


source


It's pretty straightforward. When you preprocess your data, just replace the class labels with some specific integers (you can call it id). So when you compute the loss or precision of a model result, simply compare the prediction with the underlying truth in terms of integer tags (id).



If you want the label text, you can return it from the id (integer).

+2


source


When you collect data, you determine it. There is no rule. But a simple way to check:

  • See what your first training style is, see for yourself: is it a cat or a dog?
  • then look at workout Y (result / grade / desired result), is it [0.1] or [1.0]?

This will answer your question.

For getting one sample from a generator, you can see this question: How to get one value from a generator in Python?

As defined in Keras Documentation , generator output is a tuple (inputs, targets)

+1


source







All Articles