建议将数据集根符号链接到$MMDETECTION/data。
如果您的文件夹结构不同,则可能需要更改配置文件中的相应路径。
# single-gpu testing 单GPU测试
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--out ${RESULT_FILE}] [--eval ${EVAL_METRICS}] [--show]
# multi-gpu testing 多GPU测试
./tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--out ${RESULT_FILE}] [--eval ${EVAL_METRICS}]
假设已经将模型权重下载到checkpoints/。
python tools/test.py configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth --show
# 生成测试结果,.json和.pkl文件,加--eval bbox生成框的信息,用于目标检测。
python tools/test.py configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth --eval bbox --show
python tools/test.py configs/mask_rcnn_r50_fpn_1x.py \
checkpoints/mask_rcnn_r50_fpn_1x_20181010-069fa190.pth \
--out results.pkl --eval bbox segm
python tools/dist_test.sh configs/mask_rcnn_r50_fpn_1x.py \
checkpoints/mask_rcnn_r50_fpn_1x_20181010-069fa190.pth \
8 --out results.pkl --eval bbox segm
我们提供了一个网络摄像头演示来说明结果。
python demo/webcam_demo.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${GPU_ID}] [--camera-id ${CAMERA-ID}] [--score-thr ${SCORE_THR}]
例子:
python demo/webcam_demo.py configs/faster_rcnn_r50_fpn_1x.py \
checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth
本演示可以在demo / inference_demo.ipynb中找到。
from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# test a single image and show the results
img = 'demo/demo.jpg' # or img = mmcv.imread(img), which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
show_result_pyplot(model, img, result)
# or save the visualization results to image files
show_result_pyplot(model, img, result, out_file='result.jpg')
from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
config_file = 'configs/ssd/ssd300_coco.py'
checkpoint_file = 'checkpoints/ssd300_coco_20210803_015428-d231a06e.pth'
# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# test a video and show the results
video = mmcv.VideoReader('demo/demo.mp4')
for frame in video:
result = inference_detector(model, frame)
show_result_pyplot(model, frame, result, wait_time=1)
python tools/train.py ${CONFIG_FILE}
例子:
python tools/train.py configs/ssd/ssd300_coco.py
如果要在命令中指定工作目录,则可以添加参数。–work_dir${YOUR_WORK_DIR}
bash ./tools/dist_train.sh ${CONFIG_FILE} ${GPU_NUM} [optional arguments]
例子(4个GPU一起训练):
bash ./tools/dist_train.sh ./configs/ssd/ssd300_coco.py 4
可选参数为:
绘制给定训练日志文件(log.json)的损耗(loss)/ mAP曲线。
pip install seaborn
python tools/analysis_tools/analyze_logs.py plot_curve [LOG.JSON][--keys ${KEYS}] [--title ${TITLE}] [--legend ${LEGEND}] [--backend ${BACKEND}] [--style ${STYLE}] [--out ${OUT_FILE}]
python tools/analysis_tools/analyze_logs.py plot_curve work_dirs/ssd300_coco/20220823_104638.log.json --keys loss_cls --legend loss_cls
python tools/analysis_tools/analyze_logs.py plot_curve work_dirs/ssd300_coco/20220823_104638.log.json --keys loss_cls loss_reg --out losses.pdf
python tools/analysis_tools/analyze_logs.py plot_curve work_dirs/ssd300_coco/20220823_104638.log.json --keys bbox_mAP --legend run
python tools/analysis_tools/analyze_logs.py plot_curve log1.json log2.json --keys bbox_mAP --legend run1 run2
python tools/analysis_tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}]
例如:
python tools/analysis_tools/get_flops.py configs/ssd/ssd300_coco.py
在将模型上载到AWS之前,您可能需要(1)将模型权重转换为CPU张量,(2)删除优化器状态,(3)计算检查点文件的哈希并将哈希ID附加到文件名中。
代码为:
python tools/model_converters/publish_model.py ${INPUT_FILENAME} ${OUTPUT_FILENAME}
例子:
python tools/model_converters/publish_model.py work_dirs/ssd300_coco/latest.pth ssd300_test.pth