Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# ImageDataGenerator flow_from_dataframe
df_train = pd.read_csv(home_path + r'/emergency_train.csv')
df_train['emergency_or_not'] = df_train['emergency_or_not'].astype('str') # requires target in string format
train_generator_df = datagen.flow_from_dataframe(dataframe=df_train,
directory=home_path+'/images/',
x_col="image_names",
y_col="emergency_or_not",
class_mode="binary",
target_size=(200, 200),
batch_size=1,
rescale=1.0/255,
seed=2020)
# plotting images
fig, ax = plt.subplots(nrows=1, ncols=4, figsize=(15,15))
for i in range(4):
# convert to unsigned integers for plotting
image = next(train_generator_df)[0].astype('uint8')
# changing size from (1, 200, 200, 3) to (200, 200, 3) for plotting the image
image = np.squeeze(image)
# plot raw pixel data
ax[i].imshow(image)
ax[i].axis('off')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment