pytorch踩坑,TypeError: expected seqence object with len>=0 or a single integer

When looking at the Faster-R-CNN reproduction code ( https://blog.csdn.net/weixin_44791964/article/details/105739918 ), I found that an error was reported during the inference stage and Dataparallel could not gather

Refer to https://discuss.pytorch.org/t/nn-dataparallel-typeerror-expected-sequence-object-with-len-0-or-a-single-integer/97082/23 and found that the problem lies in the network output The Tensor was actually put on the CPU in advance by a certain function and turned into an ndarray, so Dataparallel cannot handle it

Yes. Sorry, in this line I put tensor to cpu before gather.

    return torch.unsqueeze(loss, 0), predicted_interaction.cpu().detach().view(-1, 1), correct_interaction.cpu().detach().view(-1, 1)

Looking at his answer, it means that the return value of model (input) should all be Tensor, but his return value is first transferred back to the CPU, and Dataparallel can only process cuda data, so an error is reported

Solution:

Either remove Dataparallel, or transfer the CPU after outputting the result.

Guess you like

Origin blog.csdn.net/qq_26751117/article/details/112537203