CaoWGG / TensorRT-YOLOv4

tensorrt5, yolov4, yolov3,yolov3-tniy,yolov3-tniy-prn
264 stars 76 forks source link

转onnx时报错 #20

Open tosonw opened 4 years ago

tosonw commented 4 years ago

您好,我在使用自己训练模型转onnx时,报错: Traceback (most recent call last): File "tools/yolo_to_onnx.py", line 748, in main() File "tools/yolo_to_onnx.py", line 743, in main verbose=True) File "tools/yolo_to_onnx.py", line 345, in build_onnx_graph conv_params) File "tools/yolo_to_onnx.py", line 219, in load_conv_weights conv_params, 'conv', 'weights') File "tools/yolo_to_onnx.py", line 248, in _create_param_tensors conv_params, param_category, suffix) File "tools/yolo_to_onnx.py", line 280, in _load_one_param_type buffer=self.weights_file.read(param_size * 4)) TypeError: buffer is too small for requested array

我看网络结构完全没问题,可以导入预训练模型进行迁移学习,cfg文件只修改了classes,其它没有改变,请问是哪里出了问题?? 我用官网预训练模型转的时候也没有问题

CaoWGG commented 4 years ago

@tosonw 你好,你的.weights文件是不是没有把所有的层的参数都保存啊? 你可以先试一下官方的80类的.cfg .weights看看会不会出现类似错误

tosonw commented 4 years ago

@CaoWGG 我使用官方.cfg和.weigth时是没问题的

tosonw commented 4 years ago

@CaoWGG 我使用自己的数据集训练了一个2分类,就出了问题

CaoWGG commented 4 years ago

@tosonw 我猜 你保存的weights有问题,因为有网友自己训练的模型是正常转的

tosonw commented 4 years ago

@CaoWGG 我保存模型的代码:torch.save(model.state_dict(), 'logs/Epoch%d-Total_Loss%.4f-Val_Loss%.4f.pth'%((epoch+1),total_loss/(epoch_size+1),val_loss/(epoch_size_val+1))) model就是模型结构,这个我对比过,除了命名不同,其他通道和结构等没有问题

HappyKerry commented 4 years ago

@tosonw 你这个是用torch版训的?torch存出来的得在darknet上微调吧

tosonw commented 4 years ago

@Happykerry 微调??是修改最后输出维度吗?

HappyKerry commented 4 years ago

@tosonw 权重微调,我用torch存出来的模型 用darknet啥也检不到

CaoWGG commented 4 years ago

@tosonw 不能直接加载torch保存的权重(pth),得加载darknet保存的权重格式

tosonw commented 4 years ago

@CaoWGG 我开始用的的官方的yolov4_weights.pth,转换成功了

tosonw commented 4 years ago

@tosonw 权重微调,我用torch存出来的模型 用darknet啥也检不到

@HappyKerry 我测过保存出的pth权重,检测完全正常

CaoWGG commented 4 years ago

@tosonw 额,可能它就把yolov4.weights换了个名字成yolov4-weights.pth。 从保存的格式上来说,.pth是不会被darknet框架正常读取的

tosonw commented 4 years ago

@tosonw 额,可能它就把yolov4.weights换了个名字成yolov4-weights.pth。 从保存的格式上来说,.pth是不会被darknet框架正常读取的

@CaoWGG 好的,麻烦您了,我再去研究下

tosonw commented 4 years ago

@tosonw 额,可能它就把yolov4.weights换了个名字成yolov4-weights.pth。 从保存的格式上来说,.pth是不会被darknet框架正常读取的

@CaoWGG 好的,麻烦您了,我再去研究下

@CaoWGG 可是我自己训练出来的centernet的pth文件使用您TensorRT-centernet是可以转换的

tosonw commented 4 years ago

@tosonw 额,可能它就把yolov4.weights换了个名字成yolov4-weights.pth。 从保存的格式上来说,.pth是不会被darknet框架正常读取的

@CaoWGG 好的,麻烦您了,我再去研究下

@CaoWGG 可是我自己训练出来的centernet的pth文件使用您TensorRT-centernet是可以转换的

@CaoWGG 我自己使用torch.onnx转的onnx文件,没有报错,但不能使用您的代码转为tensorrt

CaoWGG commented 4 years ago

@tosonw 这个repo里生成的onnx 有一些自定义的onnx op 为什么不用darknet框架训练yolo呢?

tosonw commented 4 years ago

@CaoWGG 用的别人的代码。。。。但我检查过结构,是一样的,而且训练出来效果也还可以,就没有换

tosonw commented 4 years ago

@CaoWGG 已经改好了,是由于我的cfg没有改对,改来对应就可以转了

waittim commented 3 years ago

@CaoWGG 已经改好了,是由于我的cfg没有改对,改来对应就可以转了

请问具体是什么没改对呢……我也是二分类遇到同个问题了……