#boxes[idx]为tensor
x1, y1, x2, y2 = boxes[idx][0], boxes[idx][1], boxes[idx][2], boxes[idx][3]
tensor输出
GPU tensor转CPU numpy:
先将GPU tensor转CPU tensor
a=boxes[idx].cpu
b=a.numpy #报错Cannot call numpy() on Variable that requires grad. Use var.detach().numpy() instead
#right
b=a.detach().numpy()
所以可以写成:
b = boxes[idx].cpu().detach().numpy() #GPU tensor to CPU numpy
运行结果: