inference_demo.ipynb 7.93 KB
Newer Older
wuyuefeng's avatar
Demo  
wuyuefeng committed
1
2
3
4
{
 "cells": [
  {
   "cell_type": "code",
5
   "execution_count": 1,
6
   "source": [
7
8
9
10
11
12
13
14
15
16
17
18
19
    "from mmdet3d.apis import inference_detector, init_model\n",
    "from mmdet3d.registry import VISUALIZERS\n",
    "from mmdet3d.utils import register_all_modules"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "/home/PJLAB/zhuchenming/mmdet3d_refactor/mmengine/mmengine/model/utils.py:800: UserWarning: Cannot import torch.fx, `merge_dict` is a simple function to merge multiple dicts\n",
      "  warnings.warn('Cannot import torch.fx, `merge_dict` is a simple function '\n"
     ]
    }
20
   ],
wuyuefeng's avatar
Demo  
wuyuefeng committed
21
22
23
24
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
25
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
26
  },
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "# register all modules in mmdet3d into the registries\n",
    "register_all_modules()"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "/home/PJLAB/zhuchenming/mmdet3d_refactor/mmdetection3d/mmdet3d/models/backbones/mink_resnet.py:10: UserWarning: Please follow `getting_started.md` to install MinkowskiEngine.`\n",
      "  'Please follow `getting_started.md` to install MinkowskiEngine.`')\n"
     ]
    }
   ],
   "metadata": {}
  },
wuyuefeng's avatar
Demo  
wuyuefeng committed
46
47
48
49
50
51
52
  {
   "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'"
53
54
55
56
57
58
59
   ],
   "outputs": [],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
60
61
62
63
  },
  {
   "cell_type": "code",
   "execution_count": 9,
64
65
66
67
   "source": [
    "# build the model from a config file and a checkpoint file\n",
    "model = init_model(config_file, checkpoint_file, device='cuda:0')"
   ],
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "/home/PJLAB/zhuchenming/mmdet3d_refactor/mmdetection3d/mmdet3d/models/dense_heads/anchor3d_head.py:93: UserWarning: dir_offset and dir_limit_offset will be depressed and be incorporated into box coder in the future\n",
      "  'dir_offset and dir_limit_offset will be depressed and be '\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "local loads checkpoint from path: /home/PJLAB/zhuchenming/checkpoints/hv_second_secfpn_6x8_80e_kitti-3d-3class_20210831_022017-ae782e87.pth\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "# init visualizer\n",
    "visualizer = VISUALIZERS.build(model.cfg.visualizer)\n",
    "visualizer.dataset_meta = {\n",
    "    'CLASSES': model.CLASSES,\n",
    "    'PALETTE': model.PALETTE\n",
    "}"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "/home/PJLAB/zhuchenming/mmdet3d_refactor/mmengine/mmengine/visualization/visualizer.py:167: UserWarning: `Visualizer` backend is not initialized because save_dir is None.\n",
      "  warnings.warn('`Visualizer` backend is not initialized '\n"
     ]
    },
    {
     "output_type": "display_data",
     "data": {
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ],
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"446.4pt\" height=\"302.4pt\" viewBox=\"0 0 446.4 302.4\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2022-08-04T17:45:38.225868</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.5.2, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"axes_1\"/>\n </g>\n</svg>\n",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAb4AAAEuCAYAAADx63eqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEiUlEQVR4nO3VMQEAIAzAMMC/5+ECjiYK+nXPzAKAivM7AABeMj4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABI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ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIMT4AUowPgBTjAyDF+ABIueF8BVm9xhwpAAAAAElFTkSuQmCC"
     },
     "metadata": {
      "needs_background": "light"
     }
    }
   ],
wuyuefeng's avatar
Demo  
wuyuefeng committed
121
122
123
124
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
125
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
126
127
128
  },
  {
   "cell_type": "code",
129
   "execution_count": 11,
wuyuefeng's avatar
Demo  
wuyuefeng committed
130
131
   "source": [
    "# test a single sample\n",
132
133
134
135
    "pcd = './data/kitti/000008.bin'\n",
    "result, data = inference_detector(model, pcd)\n",
    "points = data['inputs']['points']\n",
    "data_input = dict(points=points)"
136
137
   ],
   "outputs": [],
wuyuefeng's avatar
Demo  
wuyuefeng committed
138
139
140
141
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
142
143
144
145
   }
  },
  {
   "cell_type": "code",
146
   "execution_count": 12,
wuyuefeng's avatar
Demo  
wuyuefeng committed
147
148
149
   "source": [
    "# show the results\n",
    "out_dir = './'\n",
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    "visualizer.add_datasample(\n",
    "    'result',\n",
    "    data_input,\n",
    "    pred_sample=result,\n",
    "    show=True,\n",
    "    wait_time=0,\n",
    "    out_file=out_dir,\n",
    "    vis_task='det')"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "\u001b[1;33m[Open3D WARNING] invalid color in PaintUniformColor, clipping to [0, 1]\n",
      "\u001b[0;m\u001b[1;33m[Open3D WARNING] invalid color in PaintUniformColor, clipping to [0, 1]\n",
      "\u001b[0;m"
     ]
    }
169
170
171
172
173
174
   ],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
wuyuefeng's avatar
Demo  
wuyuefeng committed
175
176
177
178
  }
 ],
 "metadata": {
  "kernelspec": {
179
180
   "name": "python3",
   "display_name": "Python 3.7.6 64-bit ('torch1.7-cu10.1': conda)"
wuyuefeng's avatar
Demo  
wuyuefeng committed
181
182
183
184
185
186
187
188
189
190
191
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
192
   "version": "3.7.6"
wuyuefeng's avatar
Demo  
wuyuefeng committed
193
194
195
196
197
198
199
200
201
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
202
203
204
  },
  "interpreter": {
   "hash": "a0c343fece975dd89087e8c2194dd4d3db28d7000f1b32ed9ed9d584dd54dbbe"
wuyuefeng's avatar
Demo  
wuyuefeng committed
205
206
207
208
209
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}