Code conversion from python 2 to python 3
The problem is(can) that cpu object is expected but it gpu object. Try to put the object to cpu: 
mask.cpu()
I'm setting up a new algorithm which combines an object detector(bounding box detector) which is in python 3 and a mask generator which is in python 2. The problem here is I have several python 2 files which is required for the mask generation algorithm. So I tried 2to3 to convert all my python 2 files to python 3. The script seemed like working but as it was a deep learning algorithm(for mask generation when bounding box coordinates are given as input) which needs some pytorch weights to be loaded, while testing the model in python 3 the program was throwing out error like

"RuntimeError: Expected object of type torch.FloatTensor but found
  type torch.cuda.FloatTensor for argument #2 ‘weight’"

I have searched in PyTorch forums but none of the posts were useful to me. Is it because my mask generation code is trained in python 2 ?
Does that means while loading the weights and testing the model I should use python 2 not python 3 ? It would be great if someone can shed some light on this. As a work around I can still use the object detector code downgraded to python 2. But still I want to know why it was throwing the error.