Reputation: 161
I recently upgraded my Colab instance to TensorFlow 2.0 and have attempted to train a Sequential Classification model on a batch of PNG images. I have used the !tf_upgrade_v2
command listed on tensorflow.org to upgrade the script from TensorFlow 1.14 to 2.0 format.
When I attempt to train the model using model.fit_generator
code below I get a re-occurring non-fatal UserWarning line after line as the model runs through each epoch.
# Train the model
history = model.fit_generator(
train_generator,
steps_per_epoch=nb_train_samples // batch_size,
epochs=epochs,
validation_data=validation_generator,
validation_steps=nb_validation_samples // batch_size)
An example of the warning is:
1/449 [..............................] - ETA: 12:04 - loss: 3.0403 - accuracy: 0.1250
/usr/local/lib/python3.6/dist-packages/PIL/Image.py:914: UserWarning: Palette images
with Transparency expressed in bytes should be converted to RGBA images to RGBA
images')
This warning did not appear when using TensorFlow 1.14 when trained on the same batch of PNG images. The TF2.0 model does continue to train, however it is slowing the training process significantly as it keeps printing to the warning.
I have gone back to the dataset and tried converting the PNGs ensuring that they are in RGB format not RGBA using the example listed here however this has failed to resolve the problem.
Upvotes: 0
Views: 1448
Reputation: 161
After further research I found further details about the ImageDataGenerator and specifically the flow_from_dataframe
method in the TensorFlow Core r2.0 documentation.
The UserWarning described can be resolved by adding the color_mode='rgba'
parameter to the flow_from_dataframe
method.
For example:
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rotation_range=10,
width_shift_range=0.1,
height_shift_range=0.1,
rescale=1. / 255,
shear_range=0.1,
zoom_range=0.2,
horizontal_flip=False,
fill_mode='nearest')
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(150, 150),
batch_size=16,
save_format='png',
class_mode='sparse',
color_mode='rgba')
Upvotes: 2