Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 7, 2024
1 parent f1b363a commit abcc87e
Show file tree
Hide file tree
Showing 9 changed files with 3,134 additions and 2,927 deletions.
27 changes: 14 additions & 13 deletions notebooks/cosypose/inspect_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"from pathlib import Path\n",
"import numpy as np\n",
"import torch\n",
"import torch.nn.functional as F\n",
"import matplotlib.pyplot as plt\n",
"from happypose.pose_estimators.cosypose.cosypose.visualization.bokeh_utils import plot_image\n",
"from bokeh.io import output_notebook, show; output_notebook()\n",
"from bokeh.layouts import grid, gridplot\n",
"from happypose.pose_estimators.cosypose.cosypose.datasets.datasets_cfg import make_scene_dataset"
"from happypose.pose_estimators.cosypose.cosypose.visualization.bokeh_utils import (\n",
" plot_image,\n",
")\n",
"from bokeh.io import output_notebook, show\n",
"\n",
"output_notebook()\n",
"from bokeh.layouts import gridplot\n",
"\n",
"from happypose.pose_estimators.cosypose.cosypose.datasets.datasets_cfg import (\n",
" make_scene_dataset,\n",
")"
]
},
{
Expand All @@ -26,7 +29,7 @@
"outputs": [],
"source": [
"# ds_name = 'ycbv.train.real'\n",
"ds_name = 'synthetic.tless-1M.train'\n",
"ds_name = \"synthetic.tless-1M.train\"\n",
"scene_ds = make_scene_dataset(ds_name)"
]
},
Expand All @@ -36,16 +39,14 @@
"metadata": {},
"outputs": [],
"source": [
"from happypose.pose_estimators.cosypose.cosypose.visualization.plotter import Plotter\n",
"\n",
"figures = []\n",
"ids = np.random.randint(len(scene_ds), size=9)\n",
"for idx in ids:\n",
" im, mask, obs = scene_ds[idx]\n",
" im = np.asarray(im)[..., :3]\n",
" f, _ = plot_image(im, axes=False, tools='save')\n",
" f, _ = plot_image(im, axes=False, tools=\"save\")\n",
" figures.append(f)\n",
"plot = gridplot(figures, ncols=3, sizing_mode='scale_width')\n",
"plot = gridplot(figures, ncols=3, sizing_mode=\"scale_width\")\n",
"show(plot)"
]
}
Expand Down
40 changes: 27 additions & 13 deletions notebooks/cosypose/make_ycbv_per_object.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,53 @@
"import numpy as np\n",
"import pandas as pd\n",
"import torch\n",
"\n",
"from happypose.pose_estimators.cosypose.cosypose.config import LOCAL_DATA_DIR\n",
"\n",
"friendly_names = (LOCAL_DATA_DIR / 'bop_datasets/ycbv/ycbv_friendly_names.txt').read_text()\n",
"friendly_names = {str(int(l.split(' ')[0])): l.split(' ')[1] for l in friendly_names.split('\\n')[:-1]}\n",
"friendly_names = (\n",
" LOCAL_DATA_DIR / \"bop_datasets/ycbv/ycbv_friendly_names.txt\"\n",
").read_text()\n",
"friendly_names = {\n",
" str(int(l.split(\" \")[0])): l.split(\" \")[1] for l in friendly_names.split(\"\\n\")[:-1]\n",
"}\n",
"\n",
"\n",
"def make_errors_dict(key, result_id):\n",
" x = torch.load(LOCAL_DATA_DIR / 'results' / result_id / 'results.pth.tar')\n",
" eval_df = x['dfs']['posecnn_init/refiner/iteration=2']\n",
" scores = eval_df[f'{key}_ntop=1_matching=CLASS']['gt']['AUC/objects']\n",
" x = torch.load(LOCAL_DATA_DIR / \"results\" / result_id / \"results.pth.tar\")\n",
" eval_df = x[\"dfs\"][\"posecnn_init/refiner/iteration=2\"]\n",
" scores = eval_df[f\"{key}_ntop=1_matching=CLASS\"][\"gt\"][\"AUC/objects\"]\n",
" object_names = scores.objects.values\n",
" this_friendly_names = [friendly_names[str(int(x.split('_')[1]))] for x in object_names]\n",
" this_friendly_names = [\n",
" friendly_names[str(int(x.split(\"_\")[1]))] for x in object_names\n",
" ]\n",
" this_scores = {this_friendly_names[n]: scores.values[n] for n in range(len(scores))}\n",
" return this_scores\n",
"\n",
"\n",
"def make_summary_df(result_id):\n",
" metrics = dict()\n",
" metrics_k = ['ADD', 'ADD-S', 'ADD(-S)']\n",
" metrics_k = [\"ADD\", \"ADD-S\", \"ADD(-S)\"]\n",
" for k in metrics_k:\n",
" scores = make_errors_dict(k, result_id)\n",
" metrics[k] = scores\n",
" names = list(metrics[metrics_k[0]].keys())\n",
" names += ['mean']\n",
" df = {'object': names}\n",
" names += [\"mean\"]\n",
" df = {\"object\": names}\n",
" for k in metrics_k:\n",
" df[k] = [metrics[k][o] * 100 if o != 'mean' else np.mean(list(metrics[k].values())) * 100 for o in names]\n",
" df[k] = [\n",
" metrics[k][o] * 100\n",
" if o != \"mean\"\n",
" else np.mean(list(metrics[k].values())) * 100\n",
" for o in names\n",
" ]\n",
" df = pd.DataFrame(df)\n",
" return pd.DataFrame(df).set_index('object')\n",
" return pd.DataFrame(df).set_index(\"object\")\n",
"\n",
"\n",
"result_id = 'ycbv-n_views=1--5154971130'\n",
"result_id = \"ycbv-n_views=1--5154971130\"\n",
"df = make_summary_df(result_id)\n",
"\n",
"pd.options.display.float_format = '{:,.1f}'.format\n",
"pd.options.display.float_format = \"{:,.1f}\".format\n",
"df"
]
}
Expand Down
86 changes: 62 additions & 24 deletions notebooks/cosypose/paper_training_logs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"from happypose.pose_estimators.cosypose.cosypose.utils.logs_bokeh import Plotter\n",
"from pathlib import Path\n",
"\n",
"from happypose.pose_estimators.cosypose.cosypose.config import LOCAL_DATA_DIR\n",
"log_dir = Path(LOCAL_DATA_DIR / 'experiments')\n",
"from happypose.pose_estimators.cosypose.cosypose.utils.logs_bokeh import Plotter\n",
"\n",
"log_dir = Path(LOCAL_DATA_DIR / \"experiments\")\n",
"assert log_dir.exists()"
]
},
Expand All @@ -23,25 +25,43 @@
"source": [
"# T-LESS\n",
"run_ids = [\n",
" 'tless-coarse--10219',\n",
" 'tless-refiner--585928',\n",
"] \n",
" \"tless-coarse--10219\",\n",
" \"tless-refiner--585928\",\n",
"]\n",
"plotter = Plotter(log_dir)\n",
"plotter.load_logs(run_ids)\n",
"\n",
"plotter.plot_train_fields(['train_loss_TCO', 'val_loss_TCO'], semilogy=True, title='TCO')\n",
"plotter.plot_train_fields(\n",
" [\"train_loss_TCO\", \"val_loss_TCO\"], semilogy=True, title=\"TCO\"\n",
")\n",
"\n",
"plotter.plot_eval_field('pix2pose_detections/coarse/iteration=1/ADD-S/0.1d',\n",
" title='ADD-S/0.1d', y_range=[0.0, 0.9], new_row=True)\n",
"plotter.plot_eval_field(\n",
" \"pix2pose_detections/coarse/iteration=1/ADD-S/0.1d\",\n",
" title=\"ADD-S/0.1d\",\n",
" y_range=[0.0, 0.9],\n",
" new_row=True,\n",
")\n",
"\n",
"plotter.plot_eval_field('pix2pose_coarse/refiner/iteration=1/ADD-S/0.1d', datasets='auto', \n",
" title='ADD-S/0.1d', y_range=[0.0, 0.9], new_row=False)\n",
"plotter.plot_eval_field(\n",
" \"pix2pose_coarse/refiner/iteration=1/ADD-S/0.1d\",\n",
" datasets=\"auto\",\n",
" title=\"ADD-S/0.1d\",\n",
" y_range=[0.0, 0.9],\n",
" new_row=False,\n",
")\n",
"\n",
"\n",
"plotter.plot_train_fields(['grad_norm', ], semilogy=True, title='grad', new_row=True)\n",
"plotter.plot_train_fields(\n",
" [\n",
" \"grad_norm\",\n",
" ],\n",
" semilogy=True,\n",
" title=\"grad\",\n",
" new_row=True,\n",
")\n",
"\n",
"plotter.plot_train_fields(['learning_rate'], semilogy=False, title='lr', new_row=True)\n",
"plotter.plot_train_fields(['time_forward', 'time_backward', 'time_data'], title='time')\n",
"plotter.plot_train_fields([\"learning_rate\"], semilogy=False, title=\"lr\", new_row=True)\n",
"plotter.plot_train_fields([\"time_forward\", \"time_backward\", \"time_data\"], title=\"time\")\n",
"\n",
"plotter.show_configs()\n",
"plotter.show()"
Expand All @@ -55,25 +75,43 @@
"source": [
"# YCB-Video\n",
"run_ids = [\n",
" 'ycbv-refiner-syntonly--596719',\n",
" 'ycbv-refiner-finetune--251020',\n",
"] \n",
" \"ycbv-refiner-syntonly--596719\",\n",
" \"ycbv-refiner-finetune--251020\",\n",
"]\n",
"plotter = Plotter(log_dir)\n",
"plotter.load_logs(run_ids)\n",
"\n",
"plotter.plot_train_fields(['train_loss_TCO', 'val_loss_TCO'], semilogy=True, title='TCO')\n",
"plotter.plot_train_fields(\n",
" [\"train_loss_TCO\", \"val_loss_TCO\"], semilogy=True, title=\"TCO\"\n",
")\n",
"\n",
"plotter.plot_eval_field('posecnn_coarse/refiner/iteration=1/ADD(-S)/AUC/objects/mean',\n",
" title='ADD(-S)/AUC', y_range=[0.6, 0.9], new_row=True)\n",
"plotter.plot_eval_field(\n",
" \"posecnn_coarse/refiner/iteration=1/ADD(-S)/AUC/objects/mean\",\n",
" title=\"ADD(-S)/AUC\",\n",
" y_range=[0.6, 0.9],\n",
" new_row=True,\n",
")\n",
"\n",
"plotter.plot_eval_field('posecnn_coarse/refiner/iteration=1/ADD(-S)/AUC/objects/mean',\n",
" datasets='auto', title='ADD(-S)/AUC', y_range=[0.6, 0.9], new_row=False)\n",
"plotter.plot_eval_field(\n",
" \"posecnn_coarse/refiner/iteration=1/ADD(-S)/AUC/objects/mean\",\n",
" datasets=\"auto\",\n",
" title=\"ADD(-S)/AUC\",\n",
" y_range=[0.6, 0.9],\n",
" new_row=False,\n",
")\n",
"\n",
"\n",
"plotter.plot_train_fields(['grad_norm', ], semilogy=True, title='grad', new_row=True)\n",
"plotter.plot_train_fields(\n",
" [\n",
" \"grad_norm\",\n",
" ],\n",
" semilogy=True,\n",
" title=\"grad\",\n",
" new_row=True,\n",
")\n",
"\n",
"plotter.plot_train_fields(['learning_rate'], semilogy=False, title='lr', new_row=True)\n",
"plotter.plot_train_fields(['time_forward', 'time_backward', 'time_data'], title='time')\n",
"plotter.plot_train_fields([\"learning_rate\"], semilogy=False, title=\"lr\", new_row=True)\n",
"plotter.plot_train_fields([\"time_forward\", \"time_backward\", \"time_data\"], title=\"time\")\n",
"\n",
"plotter.show_configs()\n",
"plotter.show()"
Expand Down
37 changes: 22 additions & 15 deletions notebooks/cosypose/render_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"from happypose.pose_estimators.cosypose.cosypose.rendering.bullet_scene_renderer import BulletSceneRenderer\n",
"from happypose.pose_estimators.cosypose.cosypose.datasets.datasets_cfg import make_scene_dataset\n",
"from bokeh.io import output_notebook, show; output_notebook()\n",
"from bokeh.plotting import gridplot\n",
"import matplotlib.pyplot as plt\n",
"from happypose.pose_estimators.cosypose.cosypose.rendering.bullet_scene_renderer import (\n",
" BulletSceneRenderer,\n",
")\n",
"from happypose.pose_estimators.cosypose.cosypose.datasets.datasets_cfg import (\n",
" make_scene_dataset,\n",
")\n",
"from bokeh.io import output_notebook, show\n",
"\n",
"output_notebook()\n",
"import os\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from happypose.pose_estimators.cosypose.cosypose.lib3d import Transform\n",
"from bokeh.plotting import gridplot\n",
"\n",
"from happypose.pose_estimators.cosypose.cosypose.visualization.plotter import Plotter\n",
"import os\n",
"os.environ['CUDA_VISIBLE_DEVICES'] = '0'"
"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\""
]
},
{
Expand All @@ -28,7 +34,7 @@
"outputs": [],
"source": [
"# ds_name, urdf_ds_name = 'synthetic.ycbv-1M.train', 'ycbv'\n",
"ds_name, urdf_ds_name = 'tless.primesense.test', 'tless.cad'\n",
"ds_name, urdf_ds_name = \"tless.primesense.test\", \"tless.cad\"\n",
"scene_ds = make_scene_dataset(ds_name)"
]
},
Expand All @@ -44,21 +50,22 @@
" idx = np.random.randint(len(scene_ds))\n",
" print(\"idx:\", idx)\n",
" ds_rgb, mask, state = scene_ds[idx]\n",
" \n",
" objects = state['objects']\n",
" camera = state['camera']\n",
"\n",
" objects = state[\"objects\"]\n",
" camera = state[\"camera\"]\n",
" cameras = [camera]\n",
" image = renderer.render_scene(objects, cameras)[0]['rgb']\n",
" image = renderer.render_scene(objects, cameras)[0][\"rgb\"]\n",
" renderer.disconnect()\n",
" return ds_rgb, image\n",
"\n",
"\n",
"ds_rgb, render_rgb = get_random_image(scene_ds)\n",
"\n",
"plotter = Plotter()\n",
"fig_ds_rgb = plotter.plot_image(ds_rgb)\n",
"fig_render_rgb = plotter.plot_image(render_rgb)\n",
"fig_overlay = plotter.plot_overlay(ds_rgb, render_rgb)\n",
"show(gridplot([[fig_ds_rgb, fig_render_rgb, fig_overlay]], sizing_mode='scale_width'))"
"show(gridplot([[fig_ds_rgb, fig_render_rgb, fig_overlay]], sizing_mode=\"scale_width\"))"
]
}
],
Expand Down
Loading

0 comments on commit abcc87e

Please sign in to comment.