I would recommend to stick to the other approach, i.e. to return the image paths along with the data and target as shown in @Mona_Jalal’s code snippet.
The ii index in your test_loader loop does not necessarily correspond to the index which is used in your __getitem__, so your code might yield the wrong paths, e.g. if you use shuffle=True in your test_loader.
You could return change your __getitem__(self, index) to this:
def __getitem__(self, index):
    ...
    return t_image, mask, self.image_paths[index]