You need to first get all data out by:
all_label = torch.zeros(N,K)
for i,(data, label) in enumerate(dataloader):
      all_label[i]=label
label_binarize(all_label)

I’ll advise you to do it in Dataset, it’s a very easy operation, no need to make it complicated.