Skip to content

Instantly share code, notes, and snippets.

@L-Lewis
Last active October 2, 2019 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L-Lewis/a34845b596c15dbb41ed34b9f3ff729b to your computer and use it in GitHub Desktop.
Save L-Lewis/a34845b596c15dbb41ed34b9f3ff729b to your computer and use it in GitHub Desktop.
from keras.preprocessing.image import ImageDataGenerator
import pandas as pd
# Getting the images and rescaling
image_folder = 'model3_images/'
image_generator = ImageDataGenerator(rescale=1./255).flow_from_directory(
image_folder, shuffle=False, class_mode='binary',
target_size=(128, 128), batch_size=20000)
images, labels = next(image_generator)
# Output: Found 20000 images belonging to 2 classes.
# Checking the labels
image_generator.class_indices
# Output: {'danger': 0, 'safe': 1}
# Getting the ordered list of filenames for the images
image_files = pd.Series(image_generator.filenames)
image_files = list(image_files.str.split("\\", expand=True)[1].str[:-4])
# Sorting the structured data into the same order as the images
df_sorted = df.reindex(image_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment