How to ignore certain categories during training?

The detailed problem is as follows:

I have a dataset. It has two parts: training and test. The training data has 40 classes and the test data has 20 classes. It is noted that this 20 classes of test data are common with the training data. During training, I will train both training and test data. The training data has label whereas the test data do not have label. I would like to use 2 loss functions jointly during training: Classification loss and distance loss. I would like to use classification loss for the labeled data and distance loss for the 20 common classes. How can I ignore other 20 classes from the training set which are not common in the test dataset?

How are you implementing the distance loss?

You could try to index the model’s output using the test class indices and compute your distance loss.

output = model(data)
output_test = output[:, test_indices]

However, I’m not sure, how your distance is calculated.

Also, I’m not familiar with your use case, but be careful using the testing data for training. :wink: