1
$\begingroup$

I designed a fire detection using Deep Learning binary classification in Keras (fire vs none). It's a simple model with a few layers. In my training dataset, I included both fire and smoke, and they are both detected (all under "fire"; mostly real fires are detected though. Smoke is less accurate).

Now I need to differentiate these two in my detection results. So basically it would be 3 classes (fire, smoke, none ). One solution that came into my mind was building a binary classification model and pipeline it after the main one. So it gets the main detections as input and prints which of the two classes it belongs to.

Is there any other approaches? What are pros/cons of various approaches?

Here is my simple architecture:

def create_model():
  model = Sequential()
  model.add(Conv2D(32, kernel_size = (3, 3), activation='relu', input_shape=(300, 300, 3)))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(128, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(128, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Dropout(0.2))
  model.add(Flatten())
  model.add(Dense(256, activation='relu'))
  model.add(Dropout(0.2))
  model.add(Dense(64, activation='relu'))
  model.add(Dense(2, activation = 'softmax'))

  return model

#....
if retrain_from_prior_model == False:
    model = create_model()
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
else:
    model = load_model("checkpoints/model.h5")
$\endgroup$
7
  • 1
    $\begingroup$ I would probably also simply try to use a final softmax layer with 3 neurons for the three categories: fire, smoke, and none. $\endgroup$ – Oxbowerce Feb 13 '20 at 17:21
  • $\begingroup$ Is it a problem for you to retrain your model from scratch with 3 labels? $\endgroup$ – Mathias Müller Feb 13 '20 at 17:28
  • 1
    $\begingroup$ he/she would also need to change the loss function to reflect multiclass classification. $\endgroup$ – Victor Ng Feb 13 '20 at 20:52
  • $\begingroup$ @Oxbowerce can you elaborate more?! Sorry kinda new to DL. $\endgroup$ – Tina J Feb 13 '20 at 21:19
  • 1
    $\begingroup$ With more than 2 classes, you cannot use binary cross-entropy as the loss function: you would need to replace with sparse categorical cross-entropy. The last dense layer would need to have size 3 instead of 2. You could try methods to re-use your existing model (such as fine-tuning, pseudo rehearsal), but they are more complex than simply retraining with 3 labels. $\endgroup$ – Mathias Müller Feb 14 '20 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.