报错处理“TypeError: can‘t convert cuda:0 device type tensor to numpy. ......”

 

Traceback (most recent call last):
  File "evaluation.py", line 81, in 
    metrics.update(labels=labels, preds=output)
  File "/media/ji/my/datasets/irdatesets/AGPCNet-main/utils/metrics.py", line 111, in update
    evaluate_worker(self, labels, preds)
  File "/media/ji/my/datasets/irdatesets/AGPCNet-main/utils/metrics.py", line 103, in evaluate_worker
    tp, fp, fn = batch_tp_fp_fn(pred, label, self.nclass)
  File "/media/ji/my/datasets/irdatesets/AGPCNet-main/utils/metrics.py", line 191, in batch_tp_fp_fn
    target = target.numpy().astype('int64')  # T
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

解决方案:

target.numpy() 改为:target.cpu().data.numpy()   

小目标检测论文:Attention-Guided Pyramid Context Networks for Infrared Small Target Detection论文复现时发现

你可能感兴趣的:(numpy,python,深度学习)