WongKinYiu / ScaledYOLOv4

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

Error when running export.py #150

Open bittergourd1224 opened 3 years ago

bittergourd1224 commented 3 years ago

I tried to run models/export.py to covert the model to torchscript. The command I used is: python3 export.py --weights ../runs/exp3_yolov4-csp/weights/best.pt --img-size 640 640 --batch-size 1

An error occured:

Namespace(batch_size=1, img_size=[640, 640], weights='../runs/exp3_yolov4-csp/weights/best.pt')
Traceback (most recent call last):
  File "export.py", line 21, in <module>
    model = torch.load(opt.weights, map_location=torch.device('cpu'))['model'].float()
AttributeError: 'collections.OrderedDict' object has no attribute 'float'

It seams like the model isn't loaded in the right format. Maybe there's something wrong with the code?

WongKinYiu commented 3 years ago

https://github.com/AlexeyAB/darknet/issues/7002

rickardsjodin commented 3 years ago

I have the same problem. @WongKinYiu The linked code only support .weights files and not .pt?

WongKinYiu commented 3 years ago

you could convert .pt to .weights first. https://github.com/WongKinYiu/ScaledYOLOv4/blob/yolov4-csp/models/models.py#L647

rickardsjodin commented 3 years ago

I get problems when converting the tiny model to .weights, related to https://github.com/WongKinYiu/ScaledYOLOv4/issues/165.

@WongKinYiu Is there any way of training yolov4-tiny in python and convert to .weights?

WongKinYiu commented 3 years ago

currently yolov4-tiny, group convolution, depthwise convolution, ... are not compatible between pytorch and darknet.