I'm trying to train a CNN which can detect. Therefore, I have images in a folder called "allImages". I'm storing the information of the corresponding image in a csv-file. In order to handle the large amount of data I'm using the flow_from_dataframe function.
The CSV file is looking like this:
Firstly, I've initialized the flow_from_DataFrame method
traindf=pd.read_csv("face_features.csv",)
columns = ['LTX','LTY','LBX','LBY','RBX','RBY','RTX','RTY','TLLX','TLLY','TLRX','TLRY','BottomX','BottomY','TRLX','TRLY','TRRX','TRRY']
datagen=ImageDataGenerator(rescale=1./255.,validation_split=0.25)
train_generator=datagen.flow_from_dataframe(
dataframe=traindf,
directory="allImages/",
x_col='StringName',
y_col=columns,
subset="training",
batch_size=32,
seed=42,
class_mode = "input",
shuffle=True,
target_size=(158,163))
Then, I'm trying to build and fit the model.
model_layers = [
tf.keras.layers.Conv2D( 158 , input_shape=(32, 158,163,3) , kernel_size=( 3 , 3 ), activation='relu' ),
tf.keras.layers.Conv2D( 158 , kernel_size=( 3 , 3 ) , strides=2 , activation='relu' ),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Conv2D( 18 , kernel_size=( 3 , 3 ) , strides=1 , activation='relu' ),
tf.keras.layers.Conv2D( 18 , kernel_size=( 3 , 3 ) , strides=1 , activation='relu' ),
tf.keras.layers.Conv2D( 18 , kernel_size=( 3 , 3 ) , strides=1 ),
]
model = tf.keras.Sequential(model_layers)
model.compile( loss=tf.keras.losses.mean_squared_error , optimizer=tf.keras.optimizers.Adam( lr=0.0001 ) , metrics=[ 'mse' ] )
model.fit_generator(generator=train_generator,
steps_per_epoch=20,
epochs=20)
But unfortunately keras is throwing the input-error.
WARNING:tensorflow:Model was constructed with shape (None, 32, 158, 163,
3) for input Tensor("conv2d_92_input:0", shape=(None, 32, 158, 163, 3),
dtype=float32), but it was called on an input with incompatible shape (None, None, None, None).
When I'm trying to get the x shape of the train_generator. I'm getting (32, 158, 163, 3).
Can anybody help to resolve the issue?
Appreciate your time.