How to crop image and mask in patches?

You could use the functional API of torchvision.transforms as described in this post.