Multiple output head

how to implement multiple head classification fo single model

You can define multiple heads in the __init__ method of your model and use different paths in the forward method. A short example is given e.g. here, where two classifiers are used.

@ptrblck thanks, one doubt I have trained my model with different two datasets. then I want to have two output heads.

I doubt if I give one input how do my model give two different outputs? (won’t be the same output?)
not changing any loss function,

Is the current model using a single output layer? Are these two datasets using the same number of classes? If so, what would the two heads to in your use case, i.e. would they try to predict a different number of classes?

current model using a single output layer. yes, the same number of classes.

what is the advantages of using two head classification(if we have same classes)
another dataset I have different labels.

I don’t know if there would be any advantages, but it depends on your use case and apparently you have some ideas with it. :wink:
If both heads are supposed to return the same number of classes (e.g. 2 classes), but different labels, you would have to be able to split the input data, so that the first head would get data from the first dataset and the second one from the second dataset. While this would be possible during training (since you have the labels) it won’t be possible during evaluation/testing.

@ptrblck thank you

If I have a number of labels different in two datasets, how I can train my model related to different head

As explained before, you could split the input batches using the targets and forward the data to the corresponding head during training. However, since this won’t work during testing you would have to come up with a strategy how this can be done and why you want to use different heads.