faster-rcnn-rgbd icon indicating copy to clipboard operation
faster-rcnn-rgbd copied to clipboard

can't convert CUDA tensor to numpy

Open 7-qiliu opened this issue 5 years ago • 3 comments

there is a problem in line 248 of trainer.py: meter.add(loss_d[key])

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

how to solve it?

7-qiliu avatar Aug 25 '19 02:08 7-qiliu

Maybe it cause by Pytorch version. You should install Pytorch==0.3.0 to run this code. Or modify some code using 0.4.0 version. I recommend you modify from original Chen Yun's faster rcnn with refering to this repo, because it is 2 years ago code.

gd2016229035 avatar Aug 26 '19 03:08 gd2016229035

there is a problem in line 248 of trainer.py: meter.add(loss_d[key])

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

how to solve it? have you correctly run this ?

YAwei666 avatar Aug 28 '19 14:08 YAwei666

@YAwei666 change the whole function from

def update_meters(self, losses):
        loss_d = {k: at.scalar(v) for k, v in losses._asdict().items()}
        for key, meter in self.meters.items():
            meter.add(loss_d[key])

to

def update_meters(self, losses):
        loss_d = {k: v.item() for k, v in losses._asdict().items()}
        for key, meter in self.meters.items():
            meter.add(loss_d[key])

7-qiliu avatar Aug 29 '19 02:08 7-qiliu