Adarsh Wase
Adarsh Wase

Reputation: 1890

How to add "OTHER" class in Neural Network?

I have to classify between Real, Fake and Other images but I only have dataset of Real and Fake Faces, how do I add 'other' class, that is neither Real nor Fake face ?

This is how I loaded my dataset

TRAINING_DIR = "Dataset\Training Data"
train_datagen = ImageDataGenerator()
train_generator = train_datagen.flow_from_directory(TRAINING_DIR,
                                                    batch_size=16,
                                                    target_size=(300, 300))

and this is my output

Found 1944 images belonging to 2 classes.

Upvotes: 2

Views: 507

Answers (2)

Mathias Müller
Mathias Müller

Reputation: 22617

  1. Real Face 2. Fake Face 3. Other Object

There is this machine learning competition and they told us to add "other" class. and they didn't provide data, so that's why I was asking

Does this mean you are not allowed to use any additional data? If you can, take some other images that are not faces. Learn a second, separate model M2 that has two classes: FACE and OTHER. For this model, label all of your face images (all real and fake ones together) as FACE.

Train your original model M1 the way you are doing already, with the two classes REAL and FAKE.

After training those two models, follow a decision process such as this one:

For an input image `I`,

Does `M2` predict that the input is a `FACE`?
|--Yes: Does `M1` predict the image is `REAL`?
    |--Yes: Output "real image".
    |--No: Output "fake image".
|--No: Output "other"

If you cannot use any additional data, try Andrey's answer or look into methods that can detect out-of-distribution inputs.

Upvotes: 2

Andrey
Andrey

Reputation: 6367

You can predict based on the output of your network. If it predicts the first class with more than 90% probability - then it is the first class. If less then 10% - then it is the second. Otherwise - it is "Other"

Upvotes: 0

Related Questions