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.
:lol:lol:lol:lol:lol 666666 666666 666666 666666 666666 666666 在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’)