源码分析-demo-对象检测

 

python demo/demo.py --config-file

configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input 001.jpg

--output results --opts MODEL.WEIGHTS

detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl


参数解释

 demo/demo.py:demo文件

  config-file:选择配置文件

  output:输出位置(如果想直接查看,删除这个参数即可)

  MODEL.WEIGHTS:预先训练好的模型


调用关系


基本流程是先下载pkl模型文件,再解析参数,加载配置文件(default的和参数的,再合并)。

然后读image文件,这里使用实例分割算法处理数据。

获取到预测的box等信息后,调用Visualizer的相关函数将检测结果绘制出来。


调用的log信息如下。

[32m[05/14 15:39:49 detectron2]:[0mArguments: Namespace(confidence_threshold=0.5, config_file='configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml', input=['001.jpg'], opts=['MODEL.WEIGHTS', 'detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl'], output='results', video_input=None, webcam=False)

sxia: cpu_device= cpu

[32m[05/14 15:39:51 fvcore.common.checkpoint]:[0mLoading checkpoint from detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

[32m[05/14 15:39:51 fvcore.common.file_io]:[0mURL https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl cached in /home/lappai/.torch/fvcore_cache/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

[32m[05/14 15:39:51 fvcore.common.checkpoint]:[0mReading a file from 'Detectron2 Model Zoo'

sxia: args.input= ['001.jpg']

sxia  __call__:

sxia: run_on_image predictions= {'instances': Instances(num_instances=16, image_height=342, image_width=512, fields=[pred_boxes: Boxes(tensor([[8.4740e+00, 4.6892e+01, 1.4996e+02, 3.3636e+02],

        [1.2094e+02, 2.8676e+01, 2.4164e+02, 3.4125e+02],

        [3.9989e+02, 1.1977e+02, 5.0410e+02, 3.4135e+02],

        [2.3525e+02, 5.9974e+01, 3.8057e+02, 3.4017e+02],

        [3.5989e+02, 1.0638e+02, 4.3428e+02, 3.2155e+02],

        [4.1590e+02, 1.0385e+02, 4.4406e+02, 1.5214e+02],

        [2.7101e+02, 8.3826e+01, 3.0224e+02, 1.5380e+02],

        [2.8008e+02, 1.1305e+02, 3.2311e+02, 1.8048e+02],

        [3.1624e+02, 1.6404e+02, 4.0676e+02, 2.9497e+02],

        [3.0986e+02, 5.6478e+01, 3.8312e+02, 2.0319e+02],

        [1.1140e+00, 8.9818e+01, 6.5928e+01, 1.8706e+02],

        [0.0000e+00, 1.0031e+02, 5.6573e+01, 3.3716e+02],

        [1.3246e-01, 1.2312e+02, 6.7227e+01, 1.6550e+02],

        [1.3788e-02, 8.6321e+01, 2.8173e+01, 1.4170e+02],

        [4.8467e+02, 1.7300e+02, 5.1018e+02, 2.8373e+02],

        [4.0865e+02, 9.6892e+01, 4.2856e+02, 1.4300e+02]], device='cuda:0')), scores: tensor([0.9969, 0.9952, 0.9943, 0.9886, 0.9663, 0.9632, 0.8624, 0.7518, 0.6952,

        0.6793, 0.5957, 0.5795, 0.5773, 0.5474, 0.5355, 0.5209],

      device='cuda:0'), pred_classes: tensor([ 0,  0,  0,  0,  0,  0,  0,  0, 26,  0,  0,  0,  0,  0, 26,  0],

      device='cuda:0'), pred_masks: tensor([[[False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        ...,

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False]],

        [[False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        ...,

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False]],

        [[False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        ...,

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False]],

        ...,

        [[False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        ...,

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False]],

        [[False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        ...,

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False]],

        [[False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        ...,

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False],

        [False, False, False,  ..., False, False, False]]], device='cuda:0')])}

[32m[05/14 15:39:51 detectron2]:[0m001.jpg: detected 16 instances in 0.12s

sxia: args.output= results

sxia: out_filename= results

你可能感兴趣的:(源码分析-demo-对象检测)