I am currently attempting to make my first deep learning model which is meant to detect fire and smoke in images.
The code works up until I attempt to fit the model where it throws the error
ValueError: Exception encountered when calling layer "sequential_8" (type Sequential).
Input 0 of layer "conv2d_24" is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 1)
I loaded my images through glob:
fire = glob.glob('1/*.png')
Nonfire = glob.glob('0/*.png')
then turned them into lists to merge them into a pandas data frame.
Then I split my data into training and testing like this
test_size = int(len(df) * 0.1) # the test data will be 25% of the entire data
train = df.iloc[:-test_size,:].copy()
test = df.iloc[-test_size:,:].copy()
print(train.shape, test.shape)
x_train = train.drop('label',axis=1).copy()
y_train = train[['label']].copy()
x_test = test.drop('label',axis=1).copy()
y_test = test[['label']].copy()
and then built and compiled the model like this
model = Sequential()
model.add(Conv2D(128,(2,2),input_shape = (196,196,3),activation='relu'))
model.add(Conv2D(64,(2,2),activation='relu'))
model.add(MaxPooling2D())
model.add(Conv2D(32,(2,2),activation='relu'))
model.add(MaxPooling2D())
model.add(Flatten())
model.add(Dense(128))
model.add(Dense(1,activation= "sigmoid"))
#Model description
model.summary()
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
and all of the code works without error.
However, when I attempt to fit the model like this
model.fit(x_train,y_train,validation_data=(x_test,y_test),epochs = 30,batch_size = 32)
it throws the above error and I am unable to understand why.