Dumping Image data and load using pytorch dataloader
I want to dump the data so that I can load it back for training my model.
My code snipped for dumping the data:
for batch_idx, (image, label) in enumerate(dataloader):
    image, label = image.to(device), label.to(device)
    perturbed_image = attack.perturb(image, label)
    
    #---------- Classifier ----------
    predict_A = classifier(perturbed_image)
    pred_label = torch.max(predict_A.data, 1)[1]
    
    if pred_label != label:
        adv_data.append( (perturbed_image.to(&quot;cpu&quot;), label.to(&quot;cpu&quot;)) )

Is there any other way I can dump it correctly so as to load it in the torch.utils.data.DataLoader.

The most straight forward approach would be to use torch.save to save the actual tensors of perturbed_image and label as binary files, and then use a custom Dataset. Note that the saved tensors are not single image/label, but rather batches of images/labels. Your new custom Dataset should account for it.
