I am trying to train a model to learn to generate bounding boxes. To that end I have created a dataframe of the form show below. The values in the xmin,ymin, xmax, ymax are integers
filepaths labels xmin ymin xmax ymax
0 C:\Temp\whales\test_images\000110707af0ba.jpg whale 25 81 183 118
1 C:\Temp\whales\test_images\0006287ec424cb.jpg whale 65 154 114 176
2 C:\Temp\whales\test_images\000809ecb2ccad.jpg whale 77 118 156 144
3 C:\Temp\whales\test_images\00098d1376dab2.jpg whale 9 61 220 176
4 C:\Temp\whales\test_images\000b8d89c738bd.jpg whale 3 12 223 222
The values in xmin, ymin, xmax, ymax are integers. I then try to create a train generator from the data frame with
train_gen=gen.flow_from_dataframe(train_df,x_col='filepaths', ycol=['xmin','ymin', 'xmax','ymax'],
target_size=img_size,color_mode='rgb',
class_mode='multi_output', batch_size=batch_size, shuffle=True,
seed=123)
Executing this code throws an error shown below
TypeError: If class_mode="multi_output", y_col must be a list. Received str.
I have read all the similar questions but found no solution. Also read documentation in detail but have not solved he problem. Looks to me like y_col is a list as the documentation specifies. I also tried using above code with class_mode='raw'. That throws an error
KeyError: 'class'
I am using tensorflow 2.4.0 and python 3.7. Any help would be most appreciated.
CodePudding user response:
Yeah just figured out that you should be passing y_col
and not ycol
. Here is a working example:
import tensorflow as tf
import pandas as pd
train_df = pd.DataFrame(
data = {
'filepaths': ['/content/result_image0.png', '/content/result_image1.png', '/content/result_image2.png'],
'labels': ['whale', 'whale', 'whale'],
'xmin': [25, 65, 77],
'ymin': [81, 154, 118],
'xmax': [183, 114, 156],
'ymax': [118, 176, 144]
}
)
img_gen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
columns = ['xmin','ymin', 'xmax','ymax']
train_gen=img_gen.flow_from_dataframe(train_df,x_col='filepaths', y_col = columns,
target_size=(100, 100), color_mode='rgb',
class_mode='multi_output', batch_size=2, shuffle=True,
seed=123)
Tested with class_mode
'multi_output' and 'raw'.