subject['image_name']  #this is a string, at least that's what my dataloader is returning
image                  #this is a tensor object of shape [1, 128, 128, 128]

I am new to Pytorch so it is hard to figure this out on how to detach and save it.
Here is my dataloader object
class SomethingDataset(Dataset):
    def __init__(self, csv_file, root_dir):
        self.df = pd.read_csv(csv_file, header = None)
        self.root = root_dir
        
    def __len__(self):
        return len(self.df)
    
    def __getitem__(self, subejct_id):
#        folder_path = self.df[subject_id, 0]
        image_name = self.df.iloc[subject_id, 0]
        image_path = os.path.join(self.df.iloc[subject_id, 1])
        gt_path = os.path.join(self.df.iloc[subject_id, 2])
        image = nib.load(image_path)
        gt = nib.load(gt_path)
        image_data = np.reshape(image.get_fdata().astype(np.float32), (1, 128, 128, 128))
        gt_data = np.reshape(gt.get_data().astype(np.float32), (1, 128, 128, 128))
        affine = image.affine
        sample = {'image_name':image_name, 'image_data':image_data, 'gt_data':gt_data, 'affine':affine}
        return sample