Hi Tùng!



 tungdop2:

Image classification have 2 label: style with 4 classes and layout with 5 classes.


The simplest approach would be to recognize that you have a
multi-label, nine-class problem.  The fact that the nine classes can
be – conceptually – grouped together into a four-class style group
and a five-class layout group is not something that you need to build
into your network architecture.
So a straightforward approach would be to have the final layer of
your model be a Linear with out_features = 9.  You would typically
use BCEWithLogitsLoss.  The output of your model would have
shape [nBatch, nClass = 9] and your label (the target you pass
to BCEWithLogitsLoss) would have the same shape.  Thus, for
nBatch = 1 your example label would be:
torch.tensor ([[1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0]])

(Note the leading nBatch = 1 (singleton) dimension.)
Best.
K. Frank