mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 13:28:59 +08:00
pylint and test cases for dataloader
This commit is contained in:
1 parent
391803759e
commit
80ad17700c
10 files changed
+94
-69
No files matched your search
@@ -20,18 +20,19 @@
|
||||
"import torch\n",
|
||||
"from torch.utils.data import DataLoader\n",
|
||||
"\n",
|
||||
"from mattport.nerf.dataset.utils import get_dataset_inputs\n",
|
||||
"from mattport.nerf.dataset.image_dataset import ImageDataset, collate_batch\n",
|
||||
"from mattport.nerf.dataset.collate import CollateIterDataset, collate_batch_size_one\n",
|
||||
"from mattport.nerf.dataset.utils import get_dataset_inputs\n",
|
||||
"from mattport.nerf.field_modules.ray_generator import RayGenerator\n",
|
||||
"from mattport.structures.rays import RayBundle\n",
|
||||
"from mattport.utils.io import get_absolute_path\n",
|
||||
"from mattport.viewer.plotly import get_line_segments_from_lines\n",
|
||||
"\n",
|
||||
"from hydra import compose, initialize\n",
|
||||
"from omegaconf import open_dict\n",
|
||||
"import pprint\n",
|
||||
"from tqdm import tqdm\n",
|
||||
"\n",
|
||||
"import goat\n",
|
||||
"import random\n",
|
||||
"from tqdm import tqdm"
|
||||
]
|
||||
@@ -49,16 +50,23 @@
|
||||
" \n",
|
||||
"cfg.dataset.data_directory = get_absolute_path(cfg.dataset.data_directory)\n",
|
||||
"dataset_inputs = get_dataset_inputs(**cfg.dataset)\n",
|
||||
"dataset = ImageDataset(\n",
|
||||
" image_filenames=dataset_inputs.image_filenames, downscale_factor=dataset_inputs.downscale_factor\n",
|
||||
"image_dataset = ImageDataset(\n",
|
||||
" image_filenames=dataset_inputs.image_filenames, downscale_factor=dataset_inputs.downscale_factor\n",
|
||||
" )\n",
|
||||
"iter_dataset = CollateIterDataset(\n",
|
||||
" image_dataset,\n",
|
||||
" collate_fn=lambda batch_list: collate_batch(\n",
|
||||
" batch_list, cfg.dataloader.num_rays_per_batch, keep_full_image=True\n",
|
||||
" ),\n",
|
||||
" num_samples_to_collate=cfg.dataloader.num_images_to_sample_from,\n",
|
||||
" num_times_to_repeat=cfg.dataloader.num_times_to_repeat_images,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"dataloader = DataLoader(\n",
|
||||
" dataset,\n",
|
||||
" batch_size=cfg.dataloader.num_images_to_sample_from,\n",
|
||||
" collate_fn=lambda batch: collate_batch(batch, cfg.dataloader.num_rays_per_batch, keep_full_image=True),\n",
|
||||
" iter_dataset,\n",
|
||||
" batch_size=1,\n",
|
||||
" num_workers=cfg.dataloader.num_workers,\n",
|
||||
" shuffle=True,\n",
|
||||
" collate_fn=collate_batch_size_one,\n",
|
||||
" pin_memory=True,\n",
|
||||
")\n",
|
||||
"dataloader_iter = iter(dataloader)\n",
|
||||
"\n",
|
||||
@@ -67,7 +75,7 @@
|
||||
"num_batches = 10\n",
|
||||
"for _ in tqdm(range(num_batches)):\n",
|
||||
" batch = next(dataloader_iter)\n",
|
||||
" ray_bundle = ray_generator.forward(batch.indices)\n",
|
||||
" ray_bundle = ray_generator.forward(batch[\"indices\"])\n",
|
||||
" break"
|
||||
]
|
||||
},
|
||||
@@ -78,7 +86,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"media.show_image(dataset.get_image(10))"
|
||||
"media.show_image(image_dataset.get_image(10))"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -90,11 +98,11 @@
|
||||
"source": [
|
||||
"def show_batch(batch):\n",
|
||||
" # set the color of the sampled rays\n",
|
||||
" c, y, x = [i.flatten() for i in torch.split(batch.indices, 1, dim=-1)]\n",
|
||||
" batch.image[c,y,x] = 1.0\n",
|
||||
" c, y, x = [i.flatten() for i in torch.split(batch[\"local_indices\"], 1, dim=-1)]\n",
|
||||
" batch[\"image\"][c,y,x] = 1.0\n",
|
||||
"\n",
|
||||
" # batch.image is num_images, h, w, 3\n",
|
||||
" images = torch.split(batch.image, 1, dim=0)\n",
|
||||
" # batch[\"image\"] is num_images, h, w, 3\n",
|
||||
" images = torch.split(batch[\"image\"], 1, dim=0)\n",
|
||||
" image_list = [image[0] for image in images]\n",
|
||||
" image = torch.cat(image_list, dim=1) # cat along the width dimension\n",
|
||||
"\n",
|
||||
@@ -117,16 +125,6 @@
|
||||
"batch = sample_and_show_batch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f5f2e2e8-8d12-4e12-9b9f-e70a4f25bcee",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# batch.keys()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -134,7 +132,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ray_indices = batch.indices\n",
|
||||
"ray_indices = batch[\"indices\"]\n",
|
||||
"ray_bundle = ray_generator(ray_indices)"
|
||||
]
|
||||
},
|
||||
@@ -180,7 +178,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"data += goat.plotly_utils.get_line_segments_from_lines(lines)"
|
||||
"data += get_line_segments_from_lines(lines)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -240,6 +238,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "722f5370-3b0f-4ad1-87a1-df479ae85b60",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in new issue
Block a user