WongKinYiu / ScaledYOLOv4

Scaled-YOLOv4: Scaling Cross Stage Partial Network
GNU General Public License v3.0
2.02k stars 572 forks source link

YOLOv4-CSP:get error when running test.py #258

Open jackydinosaur opened 3 years ago

jackydinosaur commented 3 years ago

Hi, thanks for the great work!!

The testing command is :python test.py --img 640 --conf 0.001 --iou 0.65 --batch 8 --device 0 --data coco.yaml --cfg models/yolov4-csp.cfg --weights weights/yolov4-csp.weights

3 errors occurred.

I run this code on Windows 10 and Ubuntu 18.04, the same errors occurred.


Using torch 1.7.1 CUDA:0 (GeForce GTX 1080 Ti, 11177MB)

Model Summary: 516 layers, 52921437 parameters, 52921437 gradients Traceback (most recent call last): File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serialization.py", line 308, in _check_seekable f.seek(f.tell()) AttributeError: 'list' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "test.py", line 67, in test ckpt = torch.load(weights, map_location=device) # load checkpoint File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serializati on.py", line 581, in load with _open_file_like(f, 'rb') as opened_file: File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serialization.py", line 235, in _open_file_like return _open_buffer_reader(name_or_buffer) File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serializaton.py", line 220, in init _check_seekable(buffer) File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serialization.py", line 311, in _check_seekable raise_err_msg(["seek", "tell"], e) File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serialization.py", line 304, in raise_err_msg raise type(e)(msg) AttributeError: 'list' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "test.py", line 319, in test(opt.data, File "test.py", line 71, in test load_darknet_weights(model, weights) File "/Data/jackydinosaur/Yolov4/YOLOv4-CSP/models/models.py", line 575, in load_darknet_weights file = Path(weights).name File "/opt/miniconda/envs/yolov4/lib/python3.8/pathlib.py", line 1042, in new self = cls._from_parts(args, init=False) File "/opt/miniconda/envs/yolov4/lib/python3.8/pathlib.py", line 683, in _from_parts drv, root, parts = self._parse_args(args) File "/opt/miniconda/envs/yolov4/lib/python3.8/pathlib.py", line 667, in _parse_args a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not list

how might able to solve it?

Thanks a lot.

WongKinYiu commented 3 years ago

File "test.py", line 67, in test ckpt = torch.load(weights, map_location=device) # load checkpoint

try to change this line to: ckpt = torch.load(weights[0], map_location=device) # load checkpoint

jackydinosaur commented 3 years ago

Thanks a lot! File "test.py", line 67,71 in test, I change 「weights」to「weights[0]」. However, another error occurred.


Using torch 1.7.1 CUDA:0 (GeForce GTX 1080 Ti, 11177MB)

Model Summary: 516 layers, 52921437 parameters, 52921437 gradients Scanning labels ../YOLOv4-CSP/coco/labels/val2017.cache3 (1205 found, 0 missing, 13 empty, 0 duplicate, for 5000 Scanning labels ../YOLOv4-CSP/coco/labels/val2017.cache3 (2430 found, 0 missing, 21 empty, 0 duplicate, for 5000 Scanning labels ../YOLOv4-CSP/coco/labels/val2017.cache3 (3659 found, 0 missing, 32 empty, 0 duplicate, for 5000 Scanning labels ../YOLOv4-CSP/coco/labels/val2017.cache3 (4883 found, 0 missing, 48 empty, 0 duplicate, for 5000 Scanning labels ../YOLOv4-CSP/coco/labels/val2017.cache3 (4952 found, 0 missing, 48 empty, 0 duplicate, for 5000 images): 5000it [00:00, 12318.62it/s] Class Images Targets P R mAP@.5 mAP@.5:.95: 100%|█| 625/625 [02 all 5e+03 3.63e+04 0.43 0.742 0.666 0.478 Speed: 13.9/2.2/16.1 ms inference/NMS/total per 640x640 image at batch-size 8 Traceback (most recent call last): File "test.py", line 320, in test(opt.data, File "test.py", line 260, in test anno_json = glob.glob('../coco/annotations/instances_val*.json')[0] # annotations json IndexError: list index out of range

I checked 「nc:80」 in coco.yaml and「classes=80」inyolov4-csp-cfg. Changing numpy version=1.17 didn't work.

how might able to solve it?

Thanks a lot.

WongKinYiu commented 3 years ago

File "test.py", line 260, in test anno_json = glob.glob('../coco/annotations/instances_val*.json')[0] # annotations json

try to change this line to: anno_json = glob.glob('./coco/annotations/instances_val*.json')[0] # annotations json

jackydinosaur commented 3 years ago

It works! I truly appreciate your help very much. It's important for me to learning.

jackydinosaur commented 3 years ago

Hello Wong, When I running detect.py some errors occurred.

1.command:python detect.py --weights weights/yolov4-csp.weights --source inference/images/000001.jpg --cfg models/yolov4-csp.cfg


Namespace(agnostic_nms=False, augment=False, cfg='models/yolov4-csp.cfg', classes=None, conf_thres=0.4, device='', img_size=640, iou_thres=0.5, names='data/coco.names', output='inference/output', save_txt=False, source='inference/images/000001.jpg', update=False, view_img=False, weights=['weights/yolov4-csp.weights']) Traceback (most recent call last): File "detect.py", line 186, in detect() File "detect.py", line 44, in detect model.load_state_dict(torch.load(weights[0], map_location=device)['model']) File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serialization.py", line 595, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serialization.py", line 764, in _legacy_load magic_number = pickle_module.load(f, pickle_load_args) _pickle.UnpicklingError: invalid load key, '\x00'.

2.command:python detect.py --weights weights/yolov4-p5.pt --source inference/images/000001.jpg --cfg models/yolov4-csp.cfg

Namespace(agnostic_nms=False, augment=False, cfg='models/yolov4-csp.cfg', classe s=None, conf_thres=0.4, device='', img_size=640, iou_thres=0.5, names='data/coco .names', output='inference/output', save_txt=False, source='inference/images/000 001.jpg', update=False, view_img=False, weights=['weights/yolov4-p5.pt']) Traceback (most recent call last): File "detect.py", line 186, in detect() File "detect.py", line 44, in detect model.load_state_dict(torch.load(weights[0], map_location=device)['model']) File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serializati on.py", line 594, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args ) File "/opt/miniconda/envs/yolov4/lib/python3.8/site-packages/torch/serializati on.py", line 853, in _load result = unpickler.load() File "/Data/jackydinosaur/Yolov4/YOLOv4-CSP/models/yolo.py", line 10, in from models.experimental import MixConv2d, CrossConv, C3 File "/Data/jackydinosaur/Yolov4/YOLOv4-CSP/models/experimental.py", line 7 <!DOCTYPE html> ^ SyntaxError: invalid syntax

how might able to solve it?

I am looking forward to your reply.

WongKinYiu commented 3 years ago

i fixed detect.py, just update your detect.py.

jackydinosaur commented 3 years ago

It works! Thanks a lot!