Skip to content
Advertisement

Loss function for CNN sliding window model, for multi Object

model = models.Sequential()
model.add( layers.Conv2D( 32,(5,5), activation='relu', padding='same',input_shape=(512,512,3)) )
model.add( layers.MaxPooling2D((2,2)) )
           
model.add( layers.Conv2D( 64, (5,5), activation='relu', padding='same' ))           
model.add( layers.Conv2D( 64, (5,5), activation='relu', padding='same' ))
model.add( layers.MaxPooling2D((2,2)))
           
model.add( layers.Conv2D( 128, (5,5), activation='relu', padding='same' ))

model.add( layers.Conv2D( 128, (5,5), activation='relu', padding='same' ))
model.add( layers.MaxPooling2D((2,2)))

model.add( layers.Conv2D( 128, (5,5), activation='relu', padding='same' ))
model.add( layers.MaxPooling2D((2,2)))

model.add( layers.Conv2D( 5, (1,1), activation='relu', padding='same' ))
model.add( layers.MaxPooling2D((2,2)))

model.add( layers.Conv2D( 1, (1,1), activation='relu', padding='same' ))

I implemented a model with python using Keras which is series of convents layer that takes a 512*512 image and converts it to a tensor with the dimensions of 16*16. Im now trying to detect an object in this 16*16 tensor so that it gives me a 1 for detecting and a 0 otherwise. The problem is I don’t know which loss function I should use in Keras. I used binery_cronstropy and xx but the model trains in a way that only outputs 1 for one of the detected objects and 0 for everything else even though there is still objects to detect. I want to use the code in a way that detect All the present objects and not just one. Here is the code im working on.

Advertisement

Answer

binary_crossentropy is used in binary clasification (excluding classes with values of 1 or 0 ).

If you are detecting objects, you probably are in a multimodal problem with multiples classes and in the results you want a probability of there is a certain object in certain box/space of the image.

I didn’t try object detection but probably you should use categorical_crossentropy.

Advertisement