WongKinYiu / yolor

implementation of paper - You Only Learn One Representation: Unified Network for Multiple Tasks (https://arxiv.org/abs/2105.04206)
GNU General Public License v3.0
1.98k stars 524 forks source link

test.py Error #227

Open Minseokkim-0124 opened 2 years ago

Minseokkim-0124 commented 2 years ago

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?

Nikunjbansal99 commented 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.

Nikunjbansal99 commented 2 years ago

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)
Minseokkim-0124 commented 2 years ago

thx for your help^^