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.99k stars 521 forks source link

got an error when using detect.py (on Colab) #183

Closed robmlee closed 2 years ago

robmlee commented 2 years ago

When using detect.py:

!python detect.py --source inference/images/horses.jpg --cfg cfg/yolor_p6.cfg --weights yolor_p6.pt --conf 0.25 --img-size 1280 --device 0 --output /content/drive/MyDrive/YOLOR-Output

I got an error as follow:

Namespace(agnostic_nms=False, augment=False, cfg='cfg/yolor_p6.cfg', classes=None, conf_thres=0.25, device='0', img_size=1280, iou_thres=0.5, names='data/coco.names', output='/content/drive/MyDrive/YOLOR-Output', save_txt=False, source='inference/images/horses.jpg', update=False, view_img=False, weights=['yolor_p6.pt'])
/usr/local/lib/python3.7/dist-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ../aten/src/ATen/native/TensorShape.cpp:2157.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Traceback (most recent call last):
  File "detect.py", line 186, in <module>
    detect()
  File "detect.py", line 44, in detect
    model.load_state_dict(torch.load(weights[0], map_location=device)['model'])
  File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 608, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 777, in _legacy_load
    magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, '<'.

I try to google on the error, but have no luck at all so far.

robmlee commented 2 years ago

I found that two commands in scripts/get_pretrain.sh:

rm ./cookie

acts very odd on Colab. After put a # sign before the command and rerun the scripts/get_pretrain.sh, the pretrained models download again, the error is gone and the inference can be made on the testing photo as it should be.