Open Minseokkim-0124 opened 2 years ago
Facing the Same Issue. If I am running a test.py script on the CPU. It is running fine. Got this Error on GPU Tesla P-100.
Issue Fixed: Replace output_to_target function in plots.py file with:
def output_to_target(output, width, height):
# Convert model output to target format [batch_id, class_id, x, y, w, h, conf]
targets = []
for i, o in enumerate(output):
if o is not None:
if isinstance(o, torch.Tensor):
o = o.cpu().numpy()
for pred in o:
box = pred[:4]
w = (box[2] - box[0]) / width
h = (box[3] - box[1]) / height
x = box[0] / width + w / 2
y = box[1] / height + h / 2
conf = pred[4]
cls = int(pred[5])
targets.append([i, cls, x, y, w, h, conf])
return np.array(targets)
thx for your help^^
I trained the model with my custom dataset and I am trying to get a test evaluation. But, I have some problems.
!python test.py --data ./test.yaml --img 416 --batch 32 --device 0 --cfg ./cfg/yolor_p6.cfg --weights /content/drive/MyDrive/best.pt
I got errors like below
Traceback (most recent call last): File "test.py", line 330, in
save_conf=opt.save_conf,
File "test.py", line 226, in test
plot_images(img, output_to_target(output, width, height), paths, f, names) # predictions
File "/content/yolor/utils/plots.py", line 108, in output_to_target
return np.array(targets)
File "/usr/local/lib/python3.7/dist-packages/torch/tensor.py", line 630, in array
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
Plus I want to know if I use 416 image size, WARNING: --img-size 416 must be multiple of max stride 64, updating to 448 occurs. How can I solve this?