在tools/deploy/export_model.py注册数据集
from detectron2.data.datasets import register_coco_instances
register_coco_instances("val2017", {}, "/newhome/wangjd/annotations/instances_val2017.json",
"/newhome/wangjd/val2017")
修改configs下的文件,我这用的Base-RCNN-FPN.yaml
修改如下
DATASETS:
TRAIN: ("val2017",)
TEST: ("val2017",)
转换命令,onnx1.9及以后删除了onnx.optimizer,改为了onnxoptimizer,所以需要pip install onnxoptimizer,
vim /newhome/wangjd/anaconda3/envs/detection/lib/python3.9/site-packages/caffe2/python/onnx/backend.py
把里面所有的onnx.optimizer改为onnxoptimizer
./export_model.py --config-file ../../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --output ./output --export-method caffe2_tracing --format onnx MODEL.WEIGHTS ../../output/model_final.pth