NoobCoder:

No, there is no need to be the same image, but I want to know which patch belongs to which image and be able to reconstruct the whole image.


In that case you could just return the image name or a specific id for each patch and the corresponding mask in the __getitem__ method.
Since each model output will then have the corresponding image name, you should be able to sort these outputs according to the original image name.



 NoobCoder:

Based on other discussions, as long as I am working with Variables , I can write the function.


Variables are deprecated since PyTorch 0.4 so you should use tensors in newer versions.



 NoobCoder:

But in my case, because I have to calculate the edge based on mask (which needs some filtering and …) I have to access the .data() of Variable , so I am a bit confused about how to do that.


You shouldn’t access the .data attribute, as it may yield unwanted side effects. If you need the post-process the output with an edge detection algorithm, you could either implement it in PyTorch directly or use another library and implement the backward method via a custom autograd.Function as described here 8.