As long as your model output contains logits (log probabilities) for all six classes, e.g. as [batch_size, 6], there should be no problem from the point of view of your code.
That being said, I would see a problem that some labels (class1 and class4) are only available in the test set, so that your model shouldn’t have a chance to learn these classes.