{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [
    "from mmdet3d.apis import inference_detector, init_model\n",
    "from mmdet3d.registry import VISUALIZERS\n",
    "from mmdet3d.utils import register_all_modules"
   ],
   "outputs": [],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [
    "# register all modules in mmdet3d into the registries\n",
    "register_all_modules()"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "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'"
   ],
   "outputs": [],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [
    "# build the model from a config file and a checkpoint file\n",
    "model = init_model(config_file, checkpoint_file, device='cuda:0')"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [
    "# init visualizer\n",
    "visualizer = VISUALIZERS.build(model.cfg.visualizer)\n",
    "visualizer.dataset_meta = {\n",
    "    'CLASSES': model.CLASSES,\n",
    "    'PALETTE': model.PALETTE\n",
    "}"
   ],
   "outputs": [],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "source": [
    "# test a single sample\n",
    "pcd = './data/kitti/000008.bin'\n",
    "result, data = inference_detector(model, pcd)\n",
    "points = data['inputs']['points']\n",
    "data_input = dict(points=points)"
   ],
   "outputs": [],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [
    "# show the results\n",
    "out_dir = './'\n",
    "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": [],
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.6 64-bit ('torch1.7-cu10.1': conda)"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  },
  "interpreter": {
   "hash": "a0c343fece975dd89087e8c2194dd4d3db28d7000f1b32ed9ed9d584dd54dbbe"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
