How to declare unknown class

In NodeJs, I try a standard sequential model for pictures classification:

this.model = tf.sequential();
this.kernel_size = [3, 3]
this.first_filters = 32
this.model.add( tf.layers.conv2d( {
	inputShape: [modelImageHeight, modelImageWidth , modelImageChannels],
	filters: this.first_filters,
	kernelSize: this.kernel_size,
	activation: 'relu',
}));
this.model.add( tf.layers.maxPooling2d( {poolSize: [2, 2] } ));
this.model.add( tf.layers.conv2d( { filters: 64, kernelSize: [2, 2], activation: 'relu'} ));
this.model.add( tf.layers.maxPooling2d( {poolSize: [2, 2] } ));
this.model.add( tf.layers.conv2d( { filters: 64, kernelSize: [2, 2], activation: 'relu'} ));
this.model.add(tf.layers.flatten());
this.model.add(tf.layers.dense( { units: 64, activation: 'relu' } ));
this.model.add(tf.layers.dense( { units: this.categoryCount, activation:'softmax' }));

In my dataset, I have only two categories/classes.
I want the model to predict one of the two class, or “unknown” if not one of these class.

Actually, with a picture of none of the both classes, the model answers a score equal to 1.0 with one of the both classes.
How to return a very low score, or a “unknown” class ?

Best regards.

Hi @fpi

So, there are a few ways you can solve this

1)Introduce a new class to your dataset as unknown and add images that you may think appear in the problem that don’t belong to either of the classes under the unknown label.

eg: Say you are trying to do object recognition with cars and pedestrians as your classes then in the unknown class you can add images of bikes, traffic lights etc for the unknown class.

2)You could implement a threshold for the confidence value below which the model should output unknown.

3)One class classification (OCC), in this instead of trying to differentiate between the different classes the approach is to identify a particular class among all the other classes by only training on the images of that particular class

You could read more about it here:- One-class classification - Wikipedia

You clould find an implementation of the same for deep learning in the following paper:-https://arxiv.org/pdf/1801.05365.pdf

Hope it helps :smile: