From 2c42e7ab02a8f0c7a1e9dbdc7272c566d58587e2 Mon Sep 17 00:00:00 2001 From: kwea123 Date: Mon, 4 Jul 2022 16:07:57 +0900 Subject: [PATCH] add testing notebook --- test.ipynb | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 test.ipynb diff --git a/test.ipynb b/test.ipynb new file mode 100644 index 00000000..43f28931 --- /dev/null +++ b/test.ipynb @@ -0,0 +1,168 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "f940df18", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loading 200 test images ...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "200it [00:10, 18.82it/s]\n" + ] + } + ], + "source": [ + "import torch\n", + "import time\n", + "import numpy as np\n", + "from models.networks import NGP\n", + "from models.rendering import render\n", + "from metrics import psnr\n", + "import matplotlib.pyplot as plt\n", + "from tqdm.notebook import tqdm\n", + "from datasets import dataset_dict\n", + "import imageio\n", + "import cv2\n", + "import os\n", + "from utils import load_ckpt\n", + "from train import depth2img\n", + "\n", + "scene = 'Lego'\n", + "dataset = dataset_dict['nsvf'](\n", + " f'/home/ubuntu/data/nerf_data/Synthetic_NeRF/{scene}/',\n", + " split='test',\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "b5867076", + "metadata": {}, + "outputs": [], + "source": [ + "model = NGP(scale=1.0).cuda()\n", + "load_ckpt(model, f'ckpts/{scene}/epoch=19_slim.ckpt')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "314ef2c9", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ddac57fd3ea94435aa986aec47fb4951", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0/200 [00:00" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.subplots(figsize=(15, 12))\n", + "plt.tight_layout()\n", + "plt.subplot(221)\n", + "plt.title('pred')\n", + "pred = results['rgb'].reshape(dataset.img_wh[1], dataset.img_wh[0], 3).cpu().numpy()\n", + "plt.imshow(pred)\n", + "plt.subplot(222)\n", + "plt.title('depth')\n", + "depth = results['depth'].reshape(dataset.img_wh[1], dataset.img_wh[0]).cpu().numpy()\n", + "depth_ = depth2img(depth)\n", + "plt.imshow(depth_)\n", + "plt.subplot(223)\n", + "plt.title('opacity')\n", + "plt.imshow(results['opacity'].reshape(dataset.img_wh[1], dataset.img_wh[0]).cpu().numpy(), 'bone')\n", + "plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "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.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}