You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
788 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"import os\n",
"os.chdir(\"..\")\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import cv2\n",
"from pathlib import Path\n",
"from src.utils.plotting import make_matching_figure, error_colormap"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def make_prediction_and_evaluation_plot(root_dir, pe, path=None, source='ScanNet'):\n",
" img0 = cv2.imread(str(root_dir / pe['pair_names'][0]), cv2.IMREAD_GRAYSCALE)\n",
" img1 = cv2.imread(str(root_dir / pe['pair_names'][1]), cv2.IMREAD_GRAYSCALE)\n",
" if source == 'ScanNet':\n",
" img0 = cv2.resize(img0, (640, 480))\n",
" img1 = cv2.resize(img1, (640, 480))\n",
"\n",
" thr = 5e-4\n",
" mkpts0 = pe['mkpts0_f']\n",
" mkpts1 = pe['mkpts1_f']\n",
" color = error_colormap(pe['epi_errs'], thr, alpha=0.3)\n",
"\n",
" text = [\n",
" f\"LoFTR\",\n",
" f\"#Matches: {len(mkpts0)}\",\n",
" f\"$\\\\Delta$R:{pe['R_errs']:.2f}°, $\\\\Delta$t:{pe['t_errs']:.2f}°\",\n",
" ]\n",
"\n",
" if path:\n",
" make_matching_figure(img0, img1, mkpts0, mkpts1, color, text=text, path=path)\n",
" else:\n",
" return make_matching_figure(img0, img1, mkpts0, mkpts1, color, text=text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualization on ScanNet\n",
"- Prediction and Evaluation"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"root_dir = Path(\"data/scannet/test\") # Scannet\n",
"npy_path = \"dump/loftr_ds_indoor/LoFTR_pred_eval.npy\"\n",
"dumps = np.load(npy_path, allow_pickle=True)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAugAAAEcCAYAAACVsUECAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAuJAAALiQE3ycutAAEAAElEQVR4nOz9edQl2Vneif7evSPiDN+YY81zSSVKJYEmkARIYmijJSMk1NBuL3ONfbttjN2YdhtjmnV9L7Tn69XNst023au5XBqv22AEqLlMVjPYDbIlIQGSkEpVJdVcmVWZlZnffIaI2HvfP3a88b1f1MlSib5rNX/kXivznO+cOBF73s/7vM9+t6SUuJFupBvpRrqRbqQb6Ua6kW6kG+lPRnL/Z2fgRrqRbqQb6Ua6kW6kG+lGupFupON0A6DfSDfSjXQj3Ug30o10I91IN9KfoHQDoN9IN9KNdCPdSDfSjXQj3Ug30p+gdAOg30g30o10I91IN9KNdCPdSDfSn6B0A6DfSDfSjXQj3Ug30o10I91IN9KfoHQDoN9IN9KNdCPdSDfSjXQj3Ug30p+gVLzclyKSACaTCZPJhJQSGpbRe4+I9J8dHh7SNA03wjb+yUgiwmQyYTQanfjctmFKCRFZ+fvrteOqz+197Pf23iJCjBHnHCkl2rbtr9V+NMyLiJzoY9crp73GOfeScq76jSbvPZPJhLIsAZjP58QYKYoC7z0As9mMEAJVVTEej1kulwBsbW0RY2Rvb4+iKCiKgvl83n9fVRWbm5tsbGzQtm2fr8ViwdHRUV9m7z2j0Yiqqjg8POzrqSgKxuMxzjn29/fZ399HRHDOsba2xmQywXvPwcEBs9nsRF3asmude+9P1PNyuaRpmpV1dCP9n5NuvvlmptMpIYSXjAfnHHt7e1y9ehWAlNLqwTtIOo+PRiPKsnzJuLNpuVz2ffVG+pORtN3gZJvFGF8y79rvh3PqsK1fbq0e3jfG+JLnDK9dde9V3+kcpvNSjJEQwnXXli+V7D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mYt8NX7KUGhJILt/8O+bUGevfequltlkNj+NUzaPtbYGhoSo9GoB+nr6+s9SB/m4XqAWZNdY/Vv26fsvXROt+WxdTCcU4btcvfdd58g9mzehuNFMae9t83LKiPGzsmrALfmY5iGbWGxjY6p4XUWAwL9mvOl0isC6AoMtVG/5Vu+hXe/+938rb/1t/rvtFK0sMpoamNaRqgoCr75m7+Zd7/73S95VgiBn/3Zn+XP/bk/9yXz9WM/9mM45/j+7//+E7/f3d3lD//wD/nf/rf/rQe8+lwdXLPZrF+UqqqiaZp+8HrvWSwWJwwHETnhsrDMkK0nO0EOreThZGMb1k4O2insZKjJAgQFSfobHXAKTFcZEArsFbg6505IkyxTqL+1zOhwQdJJwDJwOmFoXesCogBB820H1hCk2/paZdHaZGUalsGzC6g12FYtPtqWTdOcYE/VyLETsoLl8XjcGw4KdhWc2on6xRdfJITA/v4+IQR2dnY4Ojrq87BYLDg4OOCJJ57g4OCgz8fR0RF7e3uEEHjhhRcYj8eISM/Qzufzvl9rGyv40s82Njb6PqP1H2Nkf3+/v05EOHXqVL8Q1XXNZDI50abKeutYWiwWLJdL6rru86GAfBVTOQQt1hCzi7cyspahUgmSMvk22fFn86/G6tCg1IXE1psSAPqdjjstq5IP2nf0e+slG/ZTNZ5XeZXsPKD5Vm+GNYg1/23bMh6P+3z+cZOdh3QxsYBQ++xyueyNajsXaV7tvYbA3i522v52DtB+qN5YbXc7Jw7beAi27bU6f+izhgDX9i1LANg6sXOxnSf0ewtStHz6DMuu6/U677/cPGb7bYzxRB0Nnz0EJtpHbX6
"text/plain": [
"<Figure size 750x450 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = make_prediction_and_evaluation_plot(root_dir, dumps[2], source='ScanNet')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualization on MegaDepth\n",
"- Prediction and Evaluation"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"root_dir = Path(\"data/megadepth/test\") # MegaDepth\n",
"npy_path = \"dump/loftr_ds_outdoor/LoFTR_pred_eval.npy\"\n",
"dumps = np.load(npy_path, allow_pickle=True)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAugAAAEWCAYAAAA0KmJkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAuJAAALiQE3ycutAAEAAElEQVR4nOz9WYwlSXbfDf5897vHkpERlXtmVdZe3c3qZleTzSbV1EJpRAmQQIwWCHqaR2ke9Ol1BvPMBz1+0ACf5kUcAYIAQYMRJOrjzm6yu6qb1bVXVmblGpkZGfvdr+82Dx7madfC/EYUNZqhiDiBwL3X3dzs2Hbsf44fO2YJITijMzqjMzqjMzqjMzqjMzqjvxhk//+bgTM6ozM6ozM6ozM6ozM6ozN6TmcA/YzO6IzO6IzO6IzO6IzO6C8QnQH0MzqjMzqjMzqjMzqjMzqjv0B0BtDP6IzO6IzO6IzO6IzO6Iz+AtEZQD+jMzqjMzqjMzqjMzqjM/oLRGcA/YzO6IzO6IzO6IzO6IzO6C8QuYtu/tt/+28FgGVZ1TXbtimKYu63ZVkIIbDt53hffUbeV6/JZ1WSIR9lnvJZWZ4pf1M5Ol8q6TzU1cmUJ0BRFFXeMi9ZN1Pe8rrMQ+Xbtu1j/Ok8mvjXy9F51Pk66bqex6J0pvL0NlhUJ/W+zrOpDjqpPKnf1TEmhDjGu1q3RfWruwbzfa+n18s2tZdarlpH9Xddu9a1Q12Y1Do+FpWn9ktdPxVFcYz/RXzWkYk3OQfr8q3jL8/zuTmrzmVTuaa+Ur+rvJjSqL9V2aHzqV6T7WaSW3o7yDLUOpn68x/9o390+gY/ozM6ozM6o/+paKEFvQ502rZd/avg3LTY6wtS3WKvplFJ5r0IjOjl6ellPRaBc7VO6oKrg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Oj569fl79OGfFOfOymdBBx1/C4C8HVg1FRWHeisA1gmkHaSFVjee/z4MefPn6fZbFbXFlk7dTLVWedR/lajrpj6V8/vpH5W09ddV9tuETCVZIqGYxr/i/jSx76pnU6yAte1q86TEALHcY6BZcuyKpc5Ew+mkLBqv8j+0vunboOtqW1MSqtevzp5ZuJN8lU3ds7ojM7ojM7oLxedepOo7qMtSQUSQgjW1tYYjUYcHBzMAabHjx/z2muvVelknn/4h384t+BEUTS3WOpkshwDfPe7351L9+jRI+7duzeXVl2wJV86qQu4yWVDL3cRb3o96qzG8p4JRNTxsKjsRRZLHWTo7WwCD3XWzNO2i56mjr86vkyKjfrsSW9cTKB4Z2eHD598yLXr17jh3KCTdU7kXc3P1Eb6xsI6y70J1J3WSloHyHXS21B32ZB56eNBV35UMkU90RXSOqVIT6uD0EXjQi1/kYKi8ywt0ia+TeXr9VTlxSKFUh2nuoKs1tnUByaFRidTO552vJzRGZ3RGZ3R/5x0ogVdB+lgttrK357nEUVR9Vvei6KocoFR3U7kxk5JdQuwLEcHcZI++OADBoMBQRBw48YNrly5wuHhIZubm8a8TdfqLFMm8GACzzoYqAMkpnLV8k0hGfXn6gBPHVCpq5ue/2kUEhMw0vM3gZW6uuuWxEVtpT9XZ2U1jakkSfB9n+l0yhdffsGHVz9kc32TW/bn/NX9v4Zf+NW/w/ENzqZyTO5ZJoXiNJbX04AvUxsv6ms9Pz2UqAzdaOJJLUfmtUhRUnmoA9MmcFu3cXvRODPJBvlZB/Z1oCy/m6IHmWK7L3JrqQP8pvlqGh96PUzlLALxZ3RGZ3RGZ/SXi07l4qLH8dYXHzVdmqa0Wq1jC3IYhgghqmO59YVL0iJwtmjBH41GDAYDbNtmb2+PX/7lX+bVV1/l6dOn5Hl+rE4nAUcTKFX5XQQYTJbKRZY//VMH/XV5nBagqvmbgJPJRUC3Bte
"text/plain": [
"<Figure size 750x450 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = make_prediction_and_evaluation_plot(root_dir, dumps[51], source='MegaDepth')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.8 64-bit ('loftr': conda)",
"name": "python388jvsc74a57bd0e2d1507a0fcefcbd70c2e8d5c2edae879585b2c8df0be6cdbe280bf251175c7f"
},
"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.8.8-final"
},
"orig_nbformat": 2
},
"nbformat": 4,
"nbformat_minor": 2
}