mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-11 02:24:38 +08:00
* updated three.js version. only send camera information when it moves * changing code back to updating camera constantly because packets seem to be lost * name change * starting viewer docs * new workflow * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * ga * homepage * homepage * / to ? * more documentation * fixed none error * instant ngp fix * faster image sending over tcp. instant ngp bin fix. lowest res when moving * black * requirements
201 lines
5.8 KiB
Plaintext
201 lines
5.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3c00934d-0f14-4c1a-a563-94d627b377e5",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Notebook to visualize the viewer functionality\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "8501e01d-f932-4a75-8259-2def67a546d7",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"os.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"\n",
|
|
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"4\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "b15dfdc1-5054-40bc-9631-4c7426eecfd9",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from notebook_imports import *\n",
|
|
"\n",
|
|
"import time\n",
|
|
"import torch\n",
|
|
"from torch.utils.data import DataLoader\n",
|
|
"\n",
|
|
"from pyrad.data.dataloader import TrainDataloader\n",
|
|
"from pyrad.data.image_dataset import ImageDataset, PanopticImageDataset\n",
|
|
"from pyrad.data.image_sampler import CacheImageSampler\n",
|
|
"from pyrad.data.pixel_sampler import PixelSampler\n",
|
|
"from pyrad.data.utils import DatasetInputs, get_dataset_inputs_from_dataset_config\n",
|
|
"from pyrad.graphs.modules.ray_generator import RayGenerator\n",
|
|
"from pyrad.graphs.modules.scene_colliders import SceneBoundsCollider, AABBBoxCollider\n",
|
|
"from pyrad.cameras.cameras import get_camera\n",
|
|
"from pyrad.cameras.camera_paths import InterpolatedCameraPath\n",
|
|
"from pyrad.cameras.rays import RayBundle\n",
|
|
"from pyrad.utils.io import get_absolute_path\n",
|
|
"from pyrad.utils.plotly import get_line_segments_from_lines\n",
|
|
"from pyrad.cameras.cameras import get_camera_model\n",
|
|
"from pyrad.utils.misc import get_dict_to_torch, instantiate_from_dict_config\n",
|
|
"from pyrad.engine.trainer import Trainer\n",
|
|
"from pyrad.utils.config import Config, setup_config\n",
|
|
"\n",
|
|
"# the new import\n",
|
|
"from pyrad.viewer.server import vis_utils\n",
|
|
"\n",
|
|
"\n",
|
|
"from hydra import compose, initialize\n",
|
|
"from omegaconf import open_dict\n",
|
|
"import pprint\n",
|
|
"from tqdm import tqdm\n",
|
|
"import random\n",
|
|
"\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"import umsgpack\n",
|
|
"from pyrad.viewer.server.utils import get_chunks, get_intrinsics_matrix_and_camera_to_world_h\n",
|
|
"\n",
|
|
"from pyrad.viewer.server.visualizer import Viewer"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "7fe7478d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"with initialize(version_base=None, config_path=\"../configs\"):\n",
|
|
" config = compose(\n",
|
|
" config_name=\"graph_instant_ngp.yaml\",\n",
|
|
" overrides=[\n",
|
|
" \"trainer.resume_train.load_dir=/shared/ethanweber/pyrad/outputs/blender_lego/instant_ngp/2022-07-05_200513/checkpoints\",\n",
|
|
" \"trainer.resume_train.load_step=5000\",\n",
|
|
" # \"viewer.render_image_height=50\"\n",
|
|
" ],\n",
|
|
" )\n",
|
|
" config = setup_config(config)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "26d6da3c-e28a-4c55-9592-d90dccb86051",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"vis = Viewer(zmq_url=\"tcp://127.0.0.1:6000\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "642b0a25-0e88-4eac-b661-a57a74fb10fc",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"dataset_inputs = get_dataset_inputs_from_dataset_config(**config.data.dataset_inputs_train, split=\"train\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "938f090b-3b28-4fd6-82dc-d4b5c5917134",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# ImageDataset\n",
|
|
"image_dataset_train = instantiate_from_dict_config(config.data.image_dataset_train, **dataset_inputs.as_dict())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "fd04703a-aa50-45e4-95fd-4d881ff18d61",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"estimated_time: 3.3333333333333335\n",
|
|
"time_elapsed: 3.510408878326416\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# move a camera around\n",
|
|
"num_cameras = len(dataset_inputs.intrinsics)\n",
|
|
"intrinsics = dataset_inputs.intrinsics\n",
|
|
"camera_to_world = dataset_inputs.camera_to_world\n",
|
|
"idx0, idx1 = random.sample(range(num_cameras), k=2)\n",
|
|
"camera_a = get_camera(intrinsics[idx0], camera_to_world[idx0], None)\n",
|
|
"camera_b = get_camera(intrinsics[idx1], camera_to_world[idx1], None)\n",
|
|
"\n",
|
|
"num_steps = 100\n",
|
|
"fps = 30\n",
|
|
"estimated_time = num_steps / fps\n",
|
|
"print(\"estimated_time:\", estimated_time)\n",
|
|
"\n",
|
|
"camera_path = InterpolatedCameraPath(camera_a, camera_b)\n",
|
|
"cameras = camera_path.get_path(steps=num_steps)\n",
|
|
"\n",
|
|
"start = time.time()\n",
|
|
"for camera in cameras:\n",
|
|
" vis_utils.set_camera(vis, camera)\n",
|
|
"\n",
|
|
" # render an image\n",
|
|
" # outputs = trainer.render_image_in_viewer()\n",
|
|
"\n",
|
|
" time.sleep(1 / fps)\n",
|
|
" # break\n",
|
|
"time_elapsed = time.time() - start\n",
|
|
"print(\"time_elapsed:\", time_elapsed)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0d937035-563c-412e-95ff-750ae54a42be",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"interpreter": {
|
|
"hash": "4a749acc7d255f078aee52e0584cc77b3cb5aaed1b3a7407ec4262c1bf6cb526"
|
|
},
|
|
"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
|
|
}
|