RuntimeError converting mask rcnn to c++

Hi everyone,

I have built mask r cnn code in https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html. I can train model, and test well. But when I run code:

“example = torch.rand(1, 3, 559, 536)
model.to(‘cpu’)
traced_script_module = torch.jit.trace(model, example)”

I got an error:

"File “C:\Users\ncali\anaconda3\envs\pt_37\lib\site-packages\torchvision\models\detection_utils.py”, line 218, in decode_single pred_ctr_x = dx * widths[:, None] + ctr_x[:, None]

RuntimeError: expected device cpu but got device cuda:0"

I think it is related with “RuntimeError after moving fasterrcnn_resnet50_fpn to CPU from GPU #1738

I have just added some trace line in _utils.py:
image

in training phase, it returns :
image

but after “model.to(‘cpu’)”, I have get it:
image

Here is my new question:
I have tried by training over cpu, and overcome it. But now, I got this error:

“RuntimeError: Only tensors or tuples of tensors can be output from traced functions (getOutput at …\torch\csrc\jit\tracer.cpp:212)
(no backtrace available)” :confused: