crlong33 发表于 2024-1-16 17:55

yolo如何导出.weights和.cfg




各位老师好,最近新接触一个opencv库中的函数cv::dnn::readnet()函数;      参数1是yolo训练好的模型.weights后缀文件,
      参数2是超参数.cfg后缀的文件。
如何才能得到这2个后缀的文件呢(*.weigthts和*.cfg),或者其他的也行,因为yolov8训练好的都是*.pt和*.yaml配套。网上还可以发现能导出*.onnx,但是第二个参数怎么整呀?
如何导出一套来呢?只要能用上readnet函数就可以。



官网解释:

Net cv::dnn::readNet(const String & model,
const String & config = "",
const String & framework = ""
)

Python:
cv.dnn.readNet(model[, config[, framework]]) ->retval
cv.dnn.readNet(framework, bufferModel[, bufferConfig]) ->retval
Parameters
modelBinary file contains trained weights. The following file extensions are expected for models from different frameworks:
[*]*.caffemodel (Caffe, http://caffe.berkeleyvision.org/)
[*]*.pb (TensorFlow, https://www.tensorflow.org/)
[*]*.t7 | *.net (Torch, http://torch.ch/)
[*]*.weights (Darknet, https://pjreddie.com/darknet/)
[*]*.bin (DLDT, https://software.intel.com/openvino-toolkit)
[*]*.onnx (ONNX, https://onnx.ai/)

configText file contains network configuration. It could be a file with the following extensions:
[*]*.prototxt (Caffe, http://caffe.berkeleyvision.org/)
[*]*.pbtxt (TensorFlow, https://www.tensorflow.org/)
[*]*.cfg (Darknet, https://pjreddie.com/darknet/)
[*]*.xml (DLDT, https://software.intel.com/openvino-toolkit)

frameworkExplicit framework name tag to determine a format.


yuanadrt113 发表于 2024-1-16 21:55

paopao 发表于 2024-1-16 22:46

:lol:lol:lol:lol:lol

ice1s 发表于 2024-1-17 07:00

666666

ice1s 发表于 2024-1-17 07:01

666666

icsh 发表于 2024-1-17 07:01

666666

icsh 发表于 2024-1-17 07:02

666666

4102小白 发表于 2024-1-17 07:02

666666

4102小白 发表于 2024-1-17 07:03

666666

雷欧库珀 发表于 2024-1-17 10:05

在yolov5的export.py代码中添加:
from models.yolo import Model
model=Model(‘yolov5s.yaml’)
model.load_state_dict(torch.load(‘yolov5s.pt’)[‘model’].state_dict())
torch.save(model.state_dict(),‘yolov5s.weights’)
页: [1] 2 3 4 5
查看完整版本: yolo如何导出.weights和.cfg