Hi everyone,
I have a binary dataset with labels 0, 1.
I want to modify them in order to use the hinge loss (therefore I need to map them into -1, 1)
To do so I followed a strategy similar to the one suggested here; In particular I proceed as follows:
print('targets before', dict(Counter(train_ds.targets)))
if Loss_function=='Hinge':
label_map ={-1:0, 1:1}
for key in label_map:
train_ds.targets[train_ds.targets==label_map[key]]= key
valid_ds.targets[train_ds.targets==label_map[key]]= key
print('targets after', dict(Counter(train_ds.targets)))
In the code above I define a mapping dict and use it to modify the targets; this, however does not work.
Indeed from the print I always got (before and after the block) the same output, i.e.:
target before {1:10000, 0:10000}
target after {1:10000, 0:10000}
I had the suspect that the problem was due to incompatibility between the data type of targets and the one used in the dict; however the problem persist even using label_map ={int(-1):int(0), int(1):int(1)}
Do you have any idea?
Edit
I realized that the problem was in the fact that train_ds.targets
was a list of labels, not torch tensor.
Converting the list list to a torch tensor solve the problem, i.e. the output of the print become:
target before {1:10000, 0:10000}
target after {1:10000, -1:10000}
The doubt that I have now is:
the change in the labels do not reflect in the training loader (defined before the class mapping); why is this the case?
Even redefining the dataloader after the targets change do not solve the problem