Can I define n+1 outputs for n class classification?

I am sitting on an anomaly detection task and I had the following idea.

Assume I have 3 classes and each of them could have an anomalous sample. Then, I would train with 4 classes, the last one reserved for the anomaly. But in my training data I would never actually have any data on the class 4.

Now during inference, I would try to classify the data and if it is an anomaly it should have low scores for class 1 to 3 and thus be labeled as class 4.

Would this approach even compile? So expecting 4 class weights but having labels only for 3 classes?

This might be a good idea but I don’t think the model will automatically classify every “unknown” as class4 assuming it was never trained to output this label.

Yes, it would technically work since you don’t need to use all logit outputs.

technically correct is the best form of correct. Thanks!