1. 下载Netron
Windows端下载Netron并安装:Github网址
下载.exe后安装
在Netron中.pt文件形成可视化结构尚在开发阶段,成果比较简陋,接下来用YOLO自带的脚本生成.onnx文件
2. exprot.py
没有onnx环境的先pip进行安装;
修改配置参数,将模型和数据集修改成自己的,超参数按自己需求修改:
def run(data=ROOT / 'data/coco128.yaml', # 'dataset.yaml path'
weights=ROOT / 'yolov5s.pt', # weights path
imgsz=(640, 640), # image (height, width)
batch_size=1, # batch size
device='cpu', # cuda device, i.e. 0 or 0,1,2,3 or cpu
include=('torchscript', 'onnx'), # include formats
half=False, # FP16 half-precision export
inplace=False, # set YOLOv5 Detect() inplace=True
train=False, # model.train() mode
optimize=False, # TorchScript: optimize for mobile
int8=False, # CoreML/TF INT8 quantization
dynamic=False, # ONNX/TF: dynamic axes
simplify=False, # ONNX: simplify model
opset=12, # ONNX: opset version
verbose=False, # TensorRT: verbose log
workspace=4, # TensorRT: workspace size (GB)
nms=False, # TF: add NMS to model
agnostic_nms=False, # TF: add agnostic NMS to model
topk_per_class=100, # TF.js NMS: topk per class to keep
topk_all=100, # TF.js NMS: topk for all classes to keep
iou_thres=0.45, # TF.js NMS: IoU threshold
conf_thres=0.25 # TF.js NMS: confidence threshold
):
执行后生成.onnx文件;
用Netron打开.onnx文件得到完整的网络模型,以YOLOv5s为例:
看着都头大,具体结构接下去再仔细分析