I saw someone posted a similar problem #116
Does this have something to do with Pytorch version???
Anyone with solution, plz contact me, thank you.
OK, it seems that Pytorch 0.3.0 can solve the problem. Maybe it is the version caused the problem.
I also met this problem when I try to compile with pytorch 0.4.0? how to solve this problem? while i do not want to change the version of my pytorch...
modify faster-rcnn.pytorch\lib\model\rpn\anchor_target_layer.py +156, from
num_examples = torch.sum(labels[i] >= 0)
to
num_examples = torch.sum(labels[i] >= 0).item()
another issue can be resoved with modify faster-rcnn.pytorch\lib\model\rpn\proposal_target_layer_cascade.py +133, from
labels = gt_boxes[:,:,4].contiguous().view(-1).index(offset.view(-1))\
.view(batch_size, -1)
to
labels = gt_boxes[:,:,4].contiguous().view(-1).index((offset.view(-1), ))\
.view(batch_size, -1)
Hi @xylcbd, thank you for your solutions. But I meet with anothor issue caused by:
Traceback (most recent call last):
File "trainval_net.py", line 332, in
clip_gradient(fasterRCNN, 10.)
File "/home/yanjp/faster-rcnn.pytorch/lib/model/utils/net_utils.py", line 52, in clip_gradient
p.grad.mul_(norm)
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #3 'other'
Exception NameError: "global name 'FileNotFoundError' is not defined" in
I try to add norm.cuda() to solve it, but failed as:
Traceback (most recent call last):
File "trainval_net.py", line 332, in
clip_gradient(fasterRCNN, 10.)
File "/home/yanjp/faster-rcnn.pytorch/lib/model/utils/net_utils.py", line 51, in clip_gradient
norm = norm.cuda()
AttributeError: 'float' object has no attribute 'cuda'
Exception NameError: "global name 'FileNotFoundError' is not defined" in
could you kindly offer some advices? Thanks a lot!
@jwyang, maybe you should check the input parameter "clip_norm", is it hosted by CUDA?
Thanks for your opinion@xylcbd I have checked clip_norm, it is a float constant. At last I solve my problem by adding
norm = torch.tensor([norm],device='cuda')
before
faster-rcnn.pytorch/lib/model/utils/net_utils.py", line 51,
And now it seems work
@xylcbd thanks so much for your solution. It works for me now
@yjump @wtliao where did you put it exactly? can you please see if i put it in the right position?:
norm = clip_norm / max(totalnorm, clip_norm)
for p in model.parameters():
if p.requires_grad:
p.grad.mul_(norm)
norm = torch.tensor([norm],device='cuda')
@isalirezag put it before p.grad.mul_(norm) as gradiants are calculated on GPU
@yjump @wtliao Thank you so much for your solution!
Hi @xylcbd, thank you for your solutions. But I meet with anothor issue caused by:
File "/media/csu/新加卷/AI Competition/Baidu Competition/intermediary_contest/faster-rcnn.pytorch-master/trainval_net.py", line 316, in
loss.backward()
File "/home/csu/anaconda3/lib/python3.6/site-packages/torch/tensor.py", line 93, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/home/csu/anaconda3/lib/python3.6/site-packages/torch/autograd/__init__.py", line 89, in backward
allow_unreachable=True) # allow_unreachable flag
File "/media/csu/新加卷/AI Competition/Baidu Competition/intermediary_contest/faster-rcnn.pytorch-master/lib/model/roi_align/functions/roi_align.py", line 38, in backward
assert(self.feature_size is not None and grad_output.is_cuda)
AssertionError
Could you offer me some advice?Thanks a lot
@kurosaki-fish ,no,have you solved the problem?
For me, changing
totalnorm = np.sqrt(totalnorm)
to
totalnorm = torch.sqrt(totalnorm)
Solved this problem RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor...
command:python trainval_net.py --cuda
Solved the problem: AssertionError
the current master supports pytorch 0.4.0 now, feel free to use it!
I also met this problem when I try to compile with pytorch 0.4.0? how to solve this problem? while i do not want to change the version of my pytorch
Have you solved your problem?
Most helpful comment
modify faster-rcnn.pytorch\lib\model\rpn\anchor_target_layer.py +156, from
num_examples = torch.sum(labels[i] >= 0)to
num_examples = torch.sum(labels[i] >= 0).item()