inference_demo.ipynb 3.05 KB
Newer Older
wuyuefeng's avatar
Demo  
wuyuefeng committed
1
2
3
4
{
 "cells": [
  {
   "cell_type": "code",
ChaimZhu's avatar
ChaimZhu committed
5
   "execution_count": null,
6
   "source": [
7
8
9
10
    "from mmdet3d.apis import inference_detector, init_model\n",
    "from mmdet3d.registry import VISUALIZERS\n",
    "from mmdet3d.utils import register_all_modules"
   ],
ChaimZhu's avatar
ChaimZhu committed
11
   "outputs": [],
wuyuefeng's avatar
Demo  
wuyuefeng committed
12
13
14
15
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
16
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
17
  },
18
19
  {
   "cell_type": "code",
ChaimZhu's avatar
ChaimZhu committed
20
   "execution_count": null,
21
22
23
24
   "source": [
    "# register all modules in mmdet3d into the registries\n",
    "register_all_modules()"
   ],
ChaimZhu's avatar
ChaimZhu committed
25
   "outputs": [],
26
27
   "metadata": {}
  },
wuyuefeng's avatar
Demo  
wuyuefeng committed
28
29
30
31
32
33
34
  {
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "config_file = '../configs/second/hv_second_secfpn_6x8_80e_kitti-3d-car.py'\n",
    "# download the checkpoint from model zoo and put it in `checkpoints/`\n",
    "checkpoint_file = '../work_dirs/second/epoch_40.pth'"
35
36
37
38
39
40
41
   ],
   "outputs": [],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
42
43
44
  },
  {
   "cell_type": "code",
ChaimZhu's avatar
ChaimZhu committed
45
   "execution_count": null,
46
47
48
49
   "source": [
    "# build the model from a config file and a checkpoint file\n",
    "model = init_model(config_file, checkpoint_file, device='cuda:0')"
   ],
ChaimZhu's avatar
ChaimZhu committed
50
   "outputs": [],
51
52
53
54
   "metadata": {}
  },
  {
   "cell_type": "code",
ChaimZhu's avatar
ChaimZhu committed
55
   "execution_count": null,
56
57
58
59
60
61
62
63
   "source": [
    "# init visualizer\n",
    "visualizer = VISUALIZERS.build(model.cfg.visualizer)\n",
    "visualizer.dataset_meta = {\n",
    "    'CLASSES': model.CLASSES,\n",
    "    'PALETTE': model.PALETTE\n",
    "}"
   ],
ChaimZhu's avatar
ChaimZhu committed
64
   "outputs": [],
wuyuefeng's avatar
Demo  
wuyuefeng committed
65
66
67
68
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
69
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
70
71
72
  },
  {
   "cell_type": "code",
73
   "execution_count": 11,
wuyuefeng's avatar
Demo  
wuyuefeng committed
74
75
   "source": [
    "# test a single sample\n",
76
77
78
79
    "pcd = './data/kitti/000008.bin'\n",
    "result, data = inference_detector(model, pcd)\n",
    "points = data['inputs']['points']\n",
    "data_input = dict(points=points)"
80
81
   ],
   "outputs": [],
wuyuefeng's avatar
Demo  
wuyuefeng committed
82
83
84
85
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
86
87
88
89
   }
  },
  {
   "cell_type": "code",
ChaimZhu's avatar
ChaimZhu committed
90
   "execution_count": null,
wuyuefeng's avatar
Demo  
wuyuefeng committed
91
92
93
   "source": [
    "# show the results\n",
    "out_dir = './'\n",
94
95
96
    "visualizer.add_datasample(\n",
    "    'result',\n",
    "    data_input,\n",
97
98
    "    data_sample=result,\n",
    "    draw_gt=False,\n",
99
100
101
102
103
    "    show=True,\n",
    "    wait_time=0,\n",
    "    out_file=out_dir,\n",
    "    vis_task='det')"
   ],
ChaimZhu's avatar
ChaimZhu committed
104
   "outputs": [],
105
106
107
108
109
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
110
111
112
113
  }
 ],
 "metadata": {
  "kernelspec": {
114
115
   "name": "python3",
   "display_name": "Python 3.7.6 64-bit ('torch1.7-cu10.1': conda)"
wuyuefeng's avatar
Demo  
wuyuefeng committed
116
117
118
119
120
121
122
123
124
125
126
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
127
   "version": "3.7.6"
wuyuefeng's avatar
Demo  
wuyuefeng committed
128
129
130
131
132
133
134
135
136
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
137
138
139
  },
  "interpreter": {
   "hash": "a0c343fece975dd89087e8c2194dd4d3db28d7000f1b32ed9ed9d584dd54dbbe"
wuyuefeng's avatar
Demo  
wuyuefeng committed
140
141
142
143
144
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}