How do I design models for multiple labels?

train data’ shape is (3, 224, 224)

label is total 5

label 1 = (0~5)
label 2 = (0~7)
label 3 = (0~3)
label 4 = (0~2)
label 5 = (0~8)

so i mapped

example))
image <-> [1, 7, 3, 1, 4]

and

model = models.resnet50(pretrained=False)
in_features = model.fc.in_features
model.fc = nn.Linear(in_features=in_features, out_features=5)
model.to(device)
print(model)

Is it right to design this?

I have no idea how to set the loss and model if there are multiple such labels using Resnet50.

One idea is to work with hot vectors instead. So basically, your last fc layer will be connected to 5 different outputs such that :

  • output 1 is a 6 element vector that represents the first label. If your label is 3 for example then you vector would be [0, 0, 0, 1, 0, 0]
  • output 2 is 8 element vector.
    .
    . and so on

Once you have these representations, you apply CrossEntropyLoss on each one of your outputs. And your final loss is the sum of all these 5 losses.
You can also weight your loss labels if you think one label is more important than the other.