This is a question about classification labels.

I am dividing a set of image data into five categories. I want to set the label like this, because these data are related. Can you tell me how to modify the related code?My original label is [0, 1, 2, 3, 4]
1 1 0 0 0 0
2 1 1 0 0 0
3 1 1 1 0 0
4 1 1 1 1 0
5 1 1 1 1 1

Thanks!

Hi,
This might be a bit inefficient and might take some time depending on the size of the dataset, but it will get the work done:

>>> previous_label=torch.tensor([0,1,2,3,4])
>>> x=previous_label.size()[0]
>>> new_label=torch.zeros([x,x])
>>> for i,val in enumerate(previous_label):
...     new_label[i,:val+1]=1
... 
>>> new_label
tensor([[1., 0., 0., 0., 0.],
        [1., 1., 0., 0., 0.],
        [1., 1., 1., 0., 0.],
        [1., 1., 1., 1., 0.],
        [1., 1., 1., 1., 1.]])

Let me know if this is what you were looking for :slight_smile:

Thank you very much!