mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-04 14:58:55 +08:00
Switch from point samples to frustum samples
This commit is contained in:
1 parent
609bf32d22
commit
1b20028ea3
17 files changed
+255
-102
No files matched your search
@@ -36,6 +36,9 @@
|
|||||||
"\n",
|
"\n",
|
||||||
" ray_bundle = camera.generate_camera_rays()\n",
|
" ray_bundle = camera.generate_camera_rays()\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" print(\"Pixel Area\")\n",
|
||||||
|
" media.show_image(ray_bundle.pixel_area, width=400, cmap=\"hot\")\n",
|
||||||
|
"\n",
|
||||||
" origins = ray_bundle.origins.view(-1, 3)\n",
|
" origins = ray_bundle.origins.view(-1, 3)\n",
|
||||||
" directions = ray_bundle.directions.view(-1, 3)\n",
|
" directions = ray_bundle.directions.view(-1, 3)\n",
|
||||||
" coords = coords.view(-1, 3)\n",
|
" coords = coords.view(-1, 3)\n",
|
||||||
@@ -95,6 +98,25 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "display_data"
|
"output_type": "display_data"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Pixel Area\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<table class=\"show_images\" style=\"border-spacing:0px;\"><tr><td style=\"padding:1px;\"><img width=\"400\" height=\"200\" style=\"image-rendering:pixelated; object-fit:cover;\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAUCAIAAABwJOjsAAADHklEQVR4nMXWUU/bShAF4A/sBCuGxiKkoNKK+1Cp///nVLovCIIaJUaGkMgkCr0P6423oCvdtxutNl4nO2fmnNmZPSqZMuULl1zzhW9xrkbx1ZRLJlSMKBiAHS0bGmrmLHhgptm440E3z5jzwIIF+YATRoz4xJhzzplSFVzzNWJfccGEsw/AK2oqSgqOobrTtlrWrFmxYsQJA/KCgpKSMz5RMWEq8nDNTSRhyoQxZQK85onzSEZ4/0ZremfDiifOIkpAzAcUSdBnnDEmqxINvsVxyZSjQHoBw1ZZm847b7I/aMhWxk1ncxTDLQ4RD6IXIeiKSqT7kqsEu5pww1cqTsArjaN7n28Na9izieQ2qkbFYxJrgMuPKRjGtwUjslEMfMJF9KCa8IPvXHPBKXhhSUWh+mlbW9PQsOBMNjLa9MaHMQfyIRkDBpGHwgfBO81v+M6PD8CT+Nya1p54ZMmnTthi06kZUDKGIeKwHjKM2B3vB9nHQdeQ39f8xQUlWCceNI5mxvNe0pKiQw32A9YxeciGjOPozkD8vUjE747wRRyXCV6Y646fct5vHDDozR7H5MvIJYswZ4evgwYDMfdPOaXktMvqDjW8P6Hot0Qj2QcI3VH/Pz459qTznmwfn3ZxDFteeeGFdWRYsnzhlbbfEo3sP0AgPyze4p93DHexCISxpqxpWCY5HLDXLONoqK2TjTt2vdm3BDt/i/5t2XY+KwPYRl/xpnNH91QJanqOZ8y493vuiVXcu6YVuAr2d9GDfJsw+hod7erOc+w554z5fBsTKuTwO+C/ubWgJrDzzIp1Z/M1UWAbIm7ZJvRs2G9kIdA6ltCSYa36SUvzvmS651ZTd21xSS2Evt/YJMYD0Bt5m6gZ66uGyWNX87pKEg7BtjatHc36JqGl9ntuwTz23l+xMT921lZ66QNcvos8HAQNoVaNbPFn693HDjieK+fv22IdrwB3fbvfN53iB9FfI3Z+iPWdrCOuFn1Xt4vXjMd/vwgs+RVvGw8sOsUTufu4810S7jNPabtuVTN0Xb1rO8v/fPVpA9keeeI5CXrHP/lziWwXcc0lAAAAAElFTkSuQmCC\"/></td></tr></table>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"<IPython.core.display.HTML object>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/html": [
|
"text/html": [
|
||||||
@@ -13827,9 +13849,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"text/html": [
|
"text/html": [
|
||||||
"<div> <div id=\"d75d3488-4a45-4126-a402-c8db9194f943\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"d75d3488-4a45-4126-a402-c8db9194f943\")) { Plotly.newPlot( \"d75d3488-4a45-4126-a402-c8db9194f943\", [{\"line\":{\"color\":\"lightblue\",\"width\":1},\"marker\":{\"color\":[[0.02500000037252903,0.012500000186264515,1.0],[0.02500000037252903,0.012500000186264515,1.0],[0.02500000037252903,0.03750000149011612,1.0],[0.02500000037252903,0.03750000149011612,1.0],[0.02500000037252903,0.0625,1.0],[0.02500000037252903,0.0625,1.0],[0.02500000037252903,0.08749999850988388,1.0],[0.02500000037252903,0.08749999850988388,1.0],[0.02500000037252903,0.11249999701976776,1.0],[0.02500000037252903,0.11249999701976776,1.0],[0.02500000037252903,0.13750000298023224,1.0],[0.02500000037252903,0.13750000298023224,1.0],[0.02500000037252903,0.16249999403953552,1.0],[0.02500000037252903,0.16249999403953552,1.0],[0.02500000037252903,0.1875,1.0],[0.02500000037252903,0.1875,1.0],[0.02500000037252903,0.21250000596046448,1.0],[0.02500000037252903,0.21250000596046448,1.0],[0.02500000037252903,0.23749999701976776,1.0],[0.02500000037252903,0.23749999701976776,1.0],[0.02500000037252903,0.26249998807907104,1.0],[0.02500000037252903,0.26249998807907104,1.0],[0.02500000037252903,0.2874999940395355,1.0],[0.02500000037252903,0.2874999940395355,1.0],[0.02500000037252903,0.3125,1.0],[0.02500000037252903,0.3125,1.0],[0.02500000037252903,0.3375000059604645,1.0],[0.02500000037252903,0.3375000059604645,1.0],[0.02500000037252903,0.36250001192092896,1.0],[0.02500000037252903,0.36250001192092896,1.0],[0.02500000037252903,0.38749998807907104,1.0],[0.02500000037252903,0.38749998807907104,1.0],[0.02500000037252903,0.4124999940395355,1.0],[0.02500000037252903,0.4124999940395355,1.0],[0.02500000037252903,0.4375,1.0],[0.02500000037252903,0.4375,1.0],[0.02500000037252903,0.4625000059604645,1.0],[0.02500000037252903,0.4625000059604645,1.0],[0.02500000037252903,0.48750001192092896,1.0],[0.02500000037252903,0.48750001192092896,1.0],[0.02500000037252903,0.512499988079071,1.0],[0.02500000037252903,0.512499988079071,1.0],[0.02500000037252903,0.5375000238418579,1.0],[0.02500000037252903,0.5375000238418579,1.0],[0.02500000037252903,0.5625,1.0],[0.02500000037252903,0.5625,1.0],[0.02500000037252903,0.5874999761581421,1.0],[0.02500000037252903,0.5874999761581421,1.0],[0.02500000037252903,0.612500011920929,1.0],[0.02500000037252903,0.612500011920929,1.0],[0.02500000037252903,0.637499988079071,1.0],[0.02500000037252903,0.637499988079071,1.0],[0.02500000037252903,0.6625000238418579,1.0],[0.02500000037252903,0.6625000238418579,1.0],[0.02500000037252903,0.6875,1.0],[0.02500000037252903,0.6875,1.0],[0.02500000037252903,0.7124999761581421,1.0],[0.02500000037252903,0.7124999761581421,1.0],[0.02500000037252903,0.737500011920929,1.0],[0.02500000037252903,0.737500011920929,1.0],[0.02500000037252903,0.762499988079071,1.0],[0.02500000037252903,0.762499988079071,1.0],[0.02500000037252903,0.7875000238418579,1.0],[0.02500000037252903,0.7875000238418579,1.0],[0.02500000037252903,0.8125,1.0],[0.02500000037252903,0.8125,1.0],[0.02500000037252903,0.8374999761581421,1.0],[0.02500000037252903,0.8374999761581421,1.0],[0.02500000037252903,0.862500011920929,1.0],[0.02500000037252903,0.862500011920929,1.0],[0.02500000037252903,0.887499988079071,1.0],[0.02500000037252903,0.887499988079071,1.0],[0.02500000037252903,0.9125000238418579,1.0],[0.02500000037252903,0.9125000238418579,1.0],[0.02500000037252903,0.9375,1.0],[0.02500000037252903,0.9375,1.0],[0.02500000037252903,0.9624999761581421,1.0],[0.02500000037252903,0.9624999761581421,1.0],[0.02500000037252903,0.987500011920929,1.0],[0.02500000037252903,0.987500011920929,1.0],[0.07500000298023224,0.012500000186264515,1.0],[0.07500000298023224,0.012500000186264515,1.0],[0.07500000298023224,0.03750000149011612,1.0],[0.07500000298023224,0.03750000149011612,1.0],[0.07500000298023224,0.0625,1.0],[0.07500000298023224,0.0625,1.0],[0.07500000298023224,0.08749999850988388,1.0],[0.07500000298023224,0.08749999850988388,1.0],[0.07500000298023224,0.11249999701976776,1.0],[0.07500000298023224,0.11249999701976776,1.0],[0.07500000298023224,0.13750000298023224,1.0],[0.07500000298023224,0.13750000298023224,1.0],[0.07500000298023224,0.16249999403953552,1.0],[0.07500000298023224,0.16249999403953552,1.0],[0.07500000298023224,0.1875,1.0],[0.07500000298023224,0.1875,1.0],[0.07500000298023224,0.21250000596046448,1.0],[0.07500000298023224,0.21250000596046448,1.0],[0.07500000298023224,0.23749999701976776,1.0],[0.07500000298023224,0.23749999701976776,1.0],[0.07500000298023224,0.26249998807907104,1.0],[0.07500000298023224,0.26249998807907104,Line truncated
|
"<div> <div id=\"49bc671f-d62b-4465-8360-e415200ac509\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"49bc671f-d62b-4465-8360-e415200ac509\")) { Plotly.newPlot( \"49bc671f-d62b-4465-8360-e415200ac509\", [{\"line\":{\"color\":\"lightblue\",\"width\":1},\"marker\":{\"color\":[[0.02500000037252903,0.012500000186264515,1.0],[0.02500000037252903,0.012500000186264515,1.0],[0.02500000037252903,0.03750000149011612,1.0],[0.02500000037252903,0.03750000149011612,1.0],[0.02500000037252903,0.0625,1.0],[0.02500000037252903,0.0625,1.0],[0.02500000037252903,0.08749999850988388,1.0],[0.02500000037252903,0.08749999850988388,1.0],[0.02500000037252903,0.11249999701976776,1.0],[0.02500000037252903,0.11249999701976776,1.0],[0.02500000037252903,0.13750000298023224,1.0],[0.02500000037252903,0.13750000298023224,1.0],[0.02500000037252903,0.16249999403953552,1.0],[0.02500000037252903,0.16249999403953552,1.0],[0.02500000037252903,0.1875,1.0],[0.02500000037252903,0.1875,1.0],[0.02500000037252903,0.21250000596046448,1.0],[0.02500000037252903,0.21250000596046448,1.0],[0.02500000037252903,0.23749999701976776,1.0],[0.02500000037252903,0.23749999701976776,1.0],[0.02500000037252903,0.26249998807907104,1.0],[0.02500000037252903,0.26249998807907104,1.0],[0.02500000037252903,0.2874999940395355,1.0],[0.02500000037252903,0.2874999940395355,1.0],[0.02500000037252903,0.3125,1.0],[0.02500000037252903,0.3125,1.0],[0.02500000037252903,0.3375000059604645,1.0],[0.02500000037252903,0.3375000059604645,1.0],[0.02500000037252903,0.36250001192092896,1.0],[0.02500000037252903,0.36250001192092896,1.0],[0.02500000037252903,0.38749998807907104,1.0],[0.02500000037252903,0.38749998807907104,1.0],[0.02500000037252903,0.4124999940395355,1.0],[0.02500000037252903,0.4124999940395355,1.0],[0.02500000037252903,0.4375,1.0],[0.02500000037252903,0.4375,1.0],[0.02500000037252903,0.4625000059604645,1.0],[0.02500000037252903,0.4625000059604645,1.0],[0.02500000037252903,0.48750001192092896,1.0],[0.02500000037252903,0.48750001192092896,1.0],[0.02500000037252903,0.512499988079071,1.0],[0.02500000037252903,0.512499988079071,1.0],[0.02500000037252903,0.5375000238418579,1.0],[0.02500000037252903,0.5375000238418579,1.0],[0.02500000037252903,0.5625,1.0],[0.02500000037252903,0.5625,1.0],[0.02500000037252903,0.5874999761581421,1.0],[0.02500000037252903,0.5874999761581421,1.0],[0.02500000037252903,0.612500011920929,1.0],[0.02500000037252903,0.612500011920929,1.0],[0.02500000037252903,0.637499988079071,1.0],[0.02500000037252903,0.637499988079071,1.0],[0.02500000037252903,0.6625000238418579,1.0],[0.02500000037252903,0.6625000238418579,1.0],[0.02500000037252903,0.6875,1.0],[0.02500000037252903,0.6875,1.0],[0.02500000037252903,0.7124999761581421,1.0],[0.02500000037252903,0.7124999761581421,1.0],[0.02500000037252903,0.737500011920929,1.0],[0.02500000037252903,0.737500011920929,1.0],[0.02500000037252903,0.762499988079071,1.0],[0.02500000037252903,0.762499988079071,1.0],[0.02500000037252903,0.7875000238418579,1.0],[0.02500000037252903,0.7875000238418579,1.0],[0.02500000037252903,0.8125,1.0],[0.02500000037252903,0.8125,1.0],[0.02500000037252903,0.8374999761581421,1.0],[0.02500000037252903,0.8374999761581421,1.0],[0.02500000037252903,0.862500011920929,1.0],[0.02500000037252903,0.862500011920929,1.0],[0.02500000037252903,0.887499988079071,1.0],[0.02500000037252903,0.887499988079071,1.0],[0.02500000037252903,0.9125000238418579,1.0],[0.02500000037252903,0.9125000238418579,1.0],[0.02500000037252903,0.9375,1.0],[0.02500000037252903,0.9375,1.0],[0.02500000037252903,0.9624999761581421,1.0],[0.02500000037252903,0.9624999761581421,1.0],[0.02500000037252903,0.987500011920929,1.0],[0.02500000037252903,0.987500011920929,1.0],[0.07500000298023224,0.012500000186264515,1.0],[0.07500000298023224,0.012500000186264515,1.0],[0.07500000298023224,0.03750000149011612,1.0],[0.07500000298023224,0.03750000149011612,1.0],[0.07500000298023224,0.0625,1.0],[0.07500000298023224,0.0625,1.0],[0.07500000298023224,0.08749999850988388,1.0],[0.07500000298023224,0.08749999850988388,1.0],[0.07500000298023224,0.11249999701976776,1.0],[0.07500000298023224,0.11249999701976776,1.0],[0.07500000298023224,0.13750000298023224,1.0],[0.07500000298023224,0.13750000298023224,1.0],[0.07500000298023224,0.16249999403953552,1.0],[0.07500000298023224,0.16249999403953552,1.0],[0.07500000298023224,0.1875,1.0],[0.07500000298023224,0.1875,1.0],[0.07500000298023224,0.21250000596046448,1.0],[0.07500000298023224,0.21250000596046448,1.0],[0.07500000298023224,0.23749999701976776,1.0],[0.07500000298023224,0.23749999701976776,1.0],[0.07500000298023224,0.26249998807907104,1.0],[0.07500000298023224,0.26249998807907104,Line truncated
|
||||||
" \n",
|
" \n",
|
||||||
"var gd = document.getElementById('d75d3488-4a45-4126-a402-c8db9194f943');\n",
|
"var gd = document.getElementById('49bc671f-d62b-4465-8360-e415200ac509');\n",
|
||||||
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
||||||
" var display = window.getComputedStyle(gd).display;\n",
|
" var display = window.getComputedStyle(gd).display;\n",
|
||||||
" if (!display || display === 'none') {{\n",
|
" if (!display || display === 'none') {{\n",
|
||||||
@@ -13899,6 +13921,25 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "display_data"
|
"output_type": "display_data"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Pixel Area\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<table class=\"show_images\" style=\"border-spacing:0px;\"><tr><td style=\"padding:1px;\"><img width=\"400\" height=\"133\" style=\"image-rendering:pixelated; object-fit:cover;\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAKCAIAAAAsFXl4AAAANUlEQVR4nGPkZqAVYPxJO6P/H6ed0f97aWf0fxoZzUQjcxkYGFgYGPpoZDQto5GGiY92WQYAcF8LuVd2kUAAAAAASUVORK5CYII=\"/></td></tr></table>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"<IPython.core.display.HTML object>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"application/vnd.plotly.v1+json": {
|
"application/vnd.plotly.v1+json": {
|
||||||
@@ -19545,9 +19586,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"text/html": [
|
"text/html": [
|
||||||
"<div> <div id=\"a6545d9d-c955-4e8d-9557-0c96f7e2cc4c\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"a6545d9d-c955-4e8d-9557-0c96f7e2cc4c\")) { Plotly.newPlot( \"a6545d9d-c955-4e8d-9557-0c96f7e2cc4c\", [{\"line\":{\"color\":\"lightblue\",\"width\":1},\"marker\":{\"color\":[[0.05000000074505806,0.01666666753590107,1.0],[0.05000000074505806,0.01666666753590107,1.0],[0.05000000074505806,0.05000000074505806,1.0],[0.05000000074505806,0.05000000074505806,1.0],[0.05000000074505806,0.0833333358168602,1.0],[0.05000000074505806,0.0833333358168602,1.0],[0.05000000074505806,0.11666666716337204,1.0],[0.05000000074505806,0.11666666716337204,1.0],[0.05000000074505806,0.15000000596046448,1.0],[0.05000000074505806,0.15000000596046448,1.0],[0.05000000074505806,0.18333333730697632,1.0],[0.05000000074505806,0.18333333730697632,1.0],[0.05000000074505806,0.21666666865348816,1.0],[0.05000000074505806,0.21666666865348816,1.0],[0.05000000074505806,0.25,1.0],[0.05000000074505806,0.25,1.0],[0.05000000074505806,0.28333333134651184,1.0],[0.05000000074505806,0.28333333134651184,1.0],[0.05000000074505806,0.3166666626930237,1.0],[0.05000000074505806,0.3166666626930237,1.0],[0.05000000074505806,0.3499999940395355,1.0],[0.05000000074505806,0.3499999940395355,1.0],[0.05000000074505806,0.38333332538604736,1.0],[0.05000000074505806,0.38333332538604736,1.0],[0.05000000074505806,0.4166666567325592,1.0],[0.05000000074505806,0.4166666567325592,1.0],[0.05000000074505806,0.44999998807907104,1.0],[0.05000000074505806,0.44999998807907104,1.0],[0.05000000074505806,0.4833333194255829,1.0],[0.05000000074505806,0.4833333194255829,1.0],[0.05000000074505806,0.5166666507720947,1.0],[0.05000000074505806,0.5166666507720947,1.0],[0.05000000074505806,0.550000011920929,1.0],[0.05000000074505806,0.550000011920929,1.0],[0.05000000074505806,0.5833333134651184,1.0],[0.05000000074505806,0.5833333134651184,1.0],[0.05000000074505806,0.6166666746139526,1.0],[0.05000000074505806,0.6166666746139526,1.0],[0.05000000074505806,0.6499999761581421,1.0],[0.05000000074505806,0.6499999761581421,1.0],[0.05000000074505806,0.6833333373069763,1.0],[0.05000000074505806,0.6833333373069763,1.0],[0.05000000074505806,0.7166666388511658,1.0],[0.05000000074505806,0.7166666388511658,1.0],[0.05000000074505806,0.75,1.0],[0.05000000074505806,0.75,1.0],[0.05000000074505806,0.7833333611488342,1.0],[0.05000000074505806,0.7833333611488342,1.0],[0.05000000074505806,0.8166666626930237,1.0],[0.05000000074505806,0.8166666626930237,1.0],[0.05000000074505806,0.8500000238418579,1.0],[0.05000000074505806,0.8500000238418579,1.0],[0.05000000074505806,0.8833333253860474,1.0],[0.05000000074505806,0.8833333253860474,1.0],[0.05000000074505806,0.9166666865348816,1.0],[0.05000000074505806,0.9166666865348816,1.0],[0.05000000074505806,0.949999988079071,1.0],[0.05000000074505806,0.949999988079071,1.0],[0.05000000074505806,0.9833333492279053,1.0],[0.05000000074505806,0.9833333492279053,1.0],[0.15000000596046448,0.01666666753590107,1.0],[0.15000000596046448,0.01666666753590107,1.0],[0.15000000596046448,0.05000000074505806,1.0],[0.15000000596046448,0.05000000074505806,1.0],[0.15000000596046448,0.0833333358168602,1.0],[0.15000000596046448,0.0833333358168602,1.0],[0.15000000596046448,0.11666666716337204,1.0],[0.15000000596046448,0.11666666716337204,1.0],[0.15000000596046448,0.15000000596046448,1.0],[0.15000000596046448,0.15000000596046448,1.0],[0.15000000596046448,0.18333333730697632,1.0],[0.15000000596046448,0.18333333730697632,1.0],[0.15000000596046448,0.21666666865348816,1.0],[0.15000000596046448,0.21666666865348816,1.0],[0.15000000596046448,0.25,1.0],[0.15000000596046448,0.25,1.0],[0.15000000596046448,0.28333333134651184,1.0],[0.15000000596046448,0.28333333134651184,1.0],[0.15000000596046448,0.3166666626930237,1.0],[0.15000000596046448,0.3166666626930237,1.0],[0.15000000596046448,0.3499999940395355,1.0],[0.15000000596046448,0.3499999940395355,1.0],[0.15000000596046448,0.38333332538604736,1.0],[0.15000000596046448,0.38333332538604736,1.0],[0.15000000596046448,0.4166666567325592,1.0],[0.15000000596046448,0.4166666567325592,1.0],[0.15000000596046448,0.44999998807907104,1.0],[0.15000000596046448,0.44999998807907104,1.0],[0.15000000596046448,0.4833333194255829,1.0],[0.15000000596046448,0.4833333194255829,1.0],[0.15000000596046448,0.5166666507720947,1.0],[0.15000000596046448,0.5166666507720947,1.0],[0.15000000596046448,0.550000011920929,1.0],[0.15000000596046448,0.550000011920929,1.0],[0.15000000596046448,0.5833333134651184,1.0],[0.15000000596046448,0.5833333134651184,1.0],[0.15000000596046448,0.6166666746139526,1.0],[0.15000000596046448,0.6166666746139526,1.0],[0.1500000059604644Line truncated
|
"<div> <div id=\"56306009-ef7b-4247-810f-4805501d4c60\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"56306009-ef7b-4247-810f-4805501d4c60\")) { Plotly.newPlot( \"56306009-ef7b-4247-810f-4805501d4c60\", [{\"line\":{\"color\":\"lightblue\",\"width\":1},\"marker\":{\"color\":[[0.05000000074505806,0.01666666753590107,1.0],[0.05000000074505806,0.01666666753590107,1.0],[0.05000000074505806,0.05000000074505806,1.0],[0.05000000074505806,0.05000000074505806,1.0],[0.05000000074505806,0.0833333358168602,1.0],[0.05000000074505806,0.0833333358168602,1.0],[0.05000000074505806,0.11666666716337204,1.0],[0.05000000074505806,0.11666666716337204,1.0],[0.05000000074505806,0.15000000596046448,1.0],[0.05000000074505806,0.15000000596046448,1.0],[0.05000000074505806,0.18333333730697632,1.0],[0.05000000074505806,0.18333333730697632,1.0],[0.05000000074505806,0.21666666865348816,1.0],[0.05000000074505806,0.21666666865348816,1.0],[0.05000000074505806,0.25,1.0],[0.05000000074505806,0.25,1.0],[0.05000000074505806,0.28333333134651184,1.0],[0.05000000074505806,0.28333333134651184,1.0],[0.05000000074505806,0.3166666626930237,1.0],[0.05000000074505806,0.3166666626930237,1.0],[0.05000000074505806,0.3499999940395355,1.0],[0.05000000074505806,0.3499999940395355,1.0],[0.05000000074505806,0.38333332538604736,1.0],[0.05000000074505806,0.38333332538604736,1.0],[0.05000000074505806,0.4166666567325592,1.0],[0.05000000074505806,0.4166666567325592,1.0],[0.05000000074505806,0.44999998807907104,1.0],[0.05000000074505806,0.44999998807907104,1.0],[0.05000000074505806,0.4833333194255829,1.0],[0.05000000074505806,0.4833333194255829,1.0],[0.05000000074505806,0.5166666507720947,1.0],[0.05000000074505806,0.5166666507720947,1.0],[0.05000000074505806,0.550000011920929,1.0],[0.05000000074505806,0.550000011920929,1.0],[0.05000000074505806,0.5833333134651184,1.0],[0.05000000074505806,0.5833333134651184,1.0],[0.05000000074505806,0.6166666746139526,1.0],[0.05000000074505806,0.6166666746139526,1.0],[0.05000000074505806,0.6499999761581421,1.0],[0.05000000074505806,0.6499999761581421,1.0],[0.05000000074505806,0.6833333373069763,1.0],[0.05000000074505806,0.6833333373069763,1.0],[0.05000000074505806,0.7166666388511658,1.0],[0.05000000074505806,0.7166666388511658,1.0],[0.05000000074505806,0.75,1.0],[0.05000000074505806,0.75,1.0],[0.05000000074505806,0.7833333611488342,1.0],[0.05000000074505806,0.7833333611488342,1.0],[0.05000000074505806,0.8166666626930237,1.0],[0.05000000074505806,0.8166666626930237,1.0],[0.05000000074505806,0.8500000238418579,1.0],[0.05000000074505806,0.8500000238418579,1.0],[0.05000000074505806,0.8833333253860474,1.0],[0.05000000074505806,0.8833333253860474,1.0],[0.05000000074505806,0.9166666865348816,1.0],[0.05000000074505806,0.9166666865348816,1.0],[0.05000000074505806,0.949999988079071,1.0],[0.05000000074505806,0.949999988079071,1.0],[0.05000000074505806,0.9833333492279053,1.0],[0.05000000074505806,0.9833333492279053,1.0],[0.15000000596046448,0.01666666753590107,1.0],[0.15000000596046448,0.01666666753590107,1.0],[0.15000000596046448,0.05000000074505806,1.0],[0.15000000596046448,0.05000000074505806,1.0],[0.15000000596046448,0.0833333358168602,1.0],[0.15000000596046448,0.0833333358168602,1.0],[0.15000000596046448,0.11666666716337204,1.0],[0.15000000596046448,0.11666666716337204,1.0],[0.15000000596046448,0.15000000596046448,1.0],[0.15000000596046448,0.15000000596046448,1.0],[0.15000000596046448,0.18333333730697632,1.0],[0.15000000596046448,0.18333333730697632,1.0],[0.15000000596046448,0.21666666865348816,1.0],[0.15000000596046448,0.21666666865348816,1.0],[0.15000000596046448,0.25,1.0],[0.15000000596046448,0.25,1.0],[0.15000000596046448,0.28333333134651184,1.0],[0.15000000596046448,0.28333333134651184,1.0],[0.15000000596046448,0.3166666626930237,1.0],[0.15000000596046448,0.3166666626930237,1.0],[0.15000000596046448,0.3499999940395355,1.0],[0.15000000596046448,0.3499999940395355,1.0],[0.15000000596046448,0.38333332538604736,1.0],[0.15000000596046448,0.38333332538604736,1.0],[0.15000000596046448,0.4166666567325592,1.0],[0.15000000596046448,0.4166666567325592,1.0],[0.15000000596046448,0.44999998807907104,1.0],[0.15000000596046448,0.44999998807907104,1.0],[0.15000000596046448,0.4833333194255829,1.0],[0.15000000596046448,0.4833333194255829,1.0],[0.15000000596046448,0.5166666507720947,1.0],[0.15000000596046448,0.5166666507720947,1.0],[0.15000000596046448,0.550000011920929,1.0],[0.15000000596046448,0.550000011920929,1.0],[0.15000000596046448,0.5833333134651184,1.0],[0.15000000596046448,0.5833333134651184,1.0],[0.15000000596046448,0.6166666746139526,1.0],[0.15000000596046448,0.6166666746139526,1.0],[0.1500000059604644Line truncated
|
||||||
" \n",
|
" \n",
|
||||||
"var gd = document.getElementById('a6545d9d-c955-4e8d-9557-0c96f7e2cc4c');\n",
|
"var gd = document.getElementById('56306009-ef7b-4247-810f-4805501d4c60');\n",
|
||||||
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
||||||
" var display = window.getComputedStyle(gd).display;\n",
|
" var display = window.getComputedStyle(gd).display;\n",
|
||||||
" if (!display || display === 'none') {{\n",
|
" if (!display || display === 'none') {{\n",
|
||||||
@@ -19594,10 +19635,10 @@
|
|||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"interpreter": {
|
"interpreter": {
|
||||||
"hash": "024fe9dea615e4e34961116ff517c7e9f5910440e3d2c8eb4560299f11aaf2e7"
|
"hash": "41f62990c6e03ccb48eec29860b83c64e20fcd45204ae5014afab6809cd6f1f1"
|
||||||
},
|
},
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 3.9.12 ('pyrad')",
|
"display_name": "Python 3.8.12 ('pyrad')",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
@@ -19611,7 +19652,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.9.12"
|
"version": "3.8.12"
|
||||||
},
|
},
|
||||||
"orig_nbformat": 4
|
"orig_nbformat": 4
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import torch
|
|||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
from pyrad.nerf.field_modules.field_heads import FieldHeadNames
|
from pyrad.nerf.field_modules.field_heads import FieldHeadNames
|
||||||
|
|
||||||
from pyrad.structures.rays import PointSamples
|
from pyrad.structures.rays import Frustums, PointSamples
|
||||||
from pyrad.utils.misc import is_not_none
|
from pyrad.utils.misc import is_not_none
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +19,16 @@ class Field(nn.Module):
|
|||||||
|
|
||||||
def density_fn(self, positions):
|
def density_fn(self, positions):
|
||||||
"""Returns only the density. Used primarily with the occupancy grid."""
|
"""Returns only the density. Used primarily with the occupancy grid."""
|
||||||
point_samples = PointSamples(positions=positions)
|
# Need to figure out a better way to descibe positions with a ray.
|
||||||
|
point_samples = PointSamples(
|
||||||
|
frustums=Frustums(
|
||||||
|
origins=positions,
|
||||||
|
directions=torch.ones_like(positions),
|
||||||
|
frustum_starts=torch.zeros((*positions.shape[:-1], 1)),
|
||||||
|
frustum_ends=torch.zeros((*positions.shape[:-1], 1)),
|
||||||
|
pixel_area=torch.ones((*positions.shape[:-1], 1)),
|
||||||
|
)
|
||||||
|
)
|
||||||
density, _ = self.get_density(point_samples)
|
density, _ = self.get_density(point_samples)
|
||||||
return density
|
return density
|
||||||
|
|
||||||
@@ -55,9 +64,7 @@ class Field(nn.Module):
|
|||||||
if is_not_none(valid_mask):
|
if is_not_none(valid_mask):
|
||||||
# Hacky handling of empty masks. Tests on a single ray but doesn't use results
|
# Hacky handling of empty masks. Tests on a single ray but doesn't use results
|
||||||
if not valid_mask.any():
|
if not valid_mask.any():
|
||||||
point_samples = PointSamples(
|
point_samples = PointSamples(frustums=Frustums.get_mock_frustum())
|
||||||
positions=point_samples.positions[0, :], directions=point_samples.directions[0, :]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
point_samples = point_samples.apply_masks()
|
point_samples = point_samples.apply_masks()
|
||||||
density_masked, density_embedding_masked = self.get_density(point_samples)
|
density_masked, density_embedding_masked = self.get_density(point_samples)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class NeRFField(Field):
|
|||||||
|
|
||||||
def get_density(self, point_samples: PointSamples):
|
def get_density(self, point_samples: PointSamples):
|
||||||
"""Computes and returns the densities."""
|
"""Computes and returns the densities."""
|
||||||
encoded_xyz = self.position_encoding(point_samples.positions)
|
encoded_xyz = self.position_encoding(point_samples.frustums.get_positions())
|
||||||
base_mlp_out = self.mlp_base(encoded_xyz)
|
base_mlp_out = self.mlp_base(encoded_xyz)
|
||||||
density = self.field_output_density(base_mlp_out)
|
density = self.field_output_density(base_mlp_out)
|
||||||
return density, base_mlp_out
|
return density, base_mlp_out
|
||||||
@@ -74,7 +74,7 @@ class NeRFField(Field):
|
|||||||
"""Computes and returns the outputs."""
|
"""Computes and returns the outputs."""
|
||||||
outputs = {}
|
outputs = {}
|
||||||
for field_head in self.field_heads:
|
for field_head in self.field_heads:
|
||||||
encoded_dir = self.direction_encoding(point_samples.directions)
|
encoded_dir = self.direction_encoding(point_samples.frustums.directions)
|
||||||
mlp_out = self.mlp_head(torch.cat([encoded_dir, density_embedding], dim=-1))
|
mlp_out = self.mlp_head(torch.cat([encoded_dir, density_embedding], dim=-1))
|
||||||
outputs[field_head.field_head_name] = field_head(mlp_out)
|
outputs[field_head.field_head_name] = field_head(mlp_out)
|
||||||
return outputs
|
return outputs
|
||||||
@@ -81,7 +81,7 @@ class VanillaNerfWField(Field):
|
|||||||
|
|
||||||
def get_density(self, point_samples: PointSamples):
|
def get_density(self, point_samples: PointSamples):
|
||||||
"""Computes and returns the densities."""
|
"""Computes and returns the densities."""
|
||||||
encoded_xyz = self.position_encoding(point_samples.positions)
|
encoded_xyz = self.position_encoding(point_samples.frustums.positions())
|
||||||
base_mlp_out = self.mlp_base(encoded_xyz)
|
base_mlp_out = self.mlp_base(encoded_xyz)
|
||||||
density = self.field_head_density(base_mlp_out)
|
density = self.field_head_density(base_mlp_out)
|
||||||
return density, base_mlp_out
|
return density, base_mlp_out
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class NGPGraph(Graph):
|
|||||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_uniform)
|
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_uniform)
|
||||||
field_outputs_pdf = self.field.forward(ray_samples_pdf.to_point_samples())
|
field_outputs_pdf = self.field.forward(ray_samples_pdf.to_point_samples())
|
||||||
|
|
||||||
ts, indices = torch.sort(torch.cat([ray_samples_uniform.ts, ray_samples_pdf.ts], -1), -1)
|
ts, indices = torch.sort(torch.cat([ray_samples_uniform.bins, ray_samples_pdf.bins], -1), -1)
|
||||||
ray_samples = ray_bundle.get_ray_samples(ts)
|
ray_samples = ray_bundle.get_ray_samples(ts)
|
||||||
field_outputs = {}
|
field_outputs = {}
|
||||||
for fo_name, _ in field_outputs_pdf.items():
|
for fo_name, _ in field_outputs_pdf.items():
|
||||||
@@ -96,11 +96,11 @@ class NGPGraph(Graph):
|
|||||||
weights=weights,
|
weights=weights,
|
||||||
)
|
)
|
||||||
accumulation = self.renderer_accumulation(weights)
|
accumulation = self.renderer_accumulation(weights)
|
||||||
depth = self.renderer_depth(weights, ray_samples.ts)
|
depth = self.renderer_depth(weights, ray_samples.bins)
|
||||||
|
|
||||||
densities_occupancy_grid = self.occupancy_grid.get_densities(ray_samples.positions)
|
densities_occupancy_grid = self.occupancy_grid.get_densities(ray_samples.positions)
|
||||||
weights_occupancy_grid = ray_samples.get_weights(densities_occupancy_grid)
|
weights_occupancy_grid = ray_samples.get_weights(densities_occupancy_grid)
|
||||||
depth_occupancy_grid = self.renderer_depth(weights_occupancy_grid, ray_samples.ts)
|
depth_occupancy_grid = self.renderer_depth(weights_occupancy_grid, ray_samples.bins)
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
"rgb": rgb,
|
"rgb": rgb,
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class NerfWGraph(Graph):
|
|||||||
rgb=field_outputs_coarse[FieldHeadNames.RGB],
|
rgb=field_outputs_coarse[FieldHeadNames.RGB],
|
||||||
weights=weights_coarse,
|
weights=weights_coarse,
|
||||||
)
|
)
|
||||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.ts)
|
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.bins)
|
||||||
|
|
||||||
# pdf sampling
|
# pdf sampling
|
||||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||||
@@ -131,8 +131,8 @@ class NerfWGraph(Graph):
|
|||||||
density_transient = field_outputs_fine[FieldHeadNames.TRANSIENT_DENSITY]
|
density_transient = field_outputs_fine[FieldHeadNames.TRANSIENT_DENSITY]
|
||||||
|
|
||||||
# depth
|
# depth
|
||||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.ts)
|
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.bins)
|
||||||
depth_fine_static = self.renderer_depth(weights_fine_static, ray_samples_pdf.ts)
|
depth_fine_static = self.renderer_depth(weights_fine_static, ray_samples_pdf.bins)
|
||||||
|
|
||||||
# uncertainty
|
# uncertainty
|
||||||
uncertainty = self.renderer_uncertainty(field_outputs_fine[FieldHeadNames.UNCERTAINTY], weights_fine_transient)
|
uncertainty = self.renderer_uncertainty(field_outputs_fine[FieldHeadNames.UNCERTAINTY], weights_fine_transient)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class SemanticNerfGraph(NeRFGraph):
|
|||||||
weights=weights_coarse,
|
weights=weights_coarse,
|
||||||
)
|
)
|
||||||
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
||||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.ts)
|
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.bins)
|
||||||
|
|
||||||
# pdf sampling
|
# pdf sampling
|
||||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||||
@@ -134,7 +134,7 @@ class SemanticNerfGraph(NeRFGraph):
|
|||||||
weights=weights_fine,
|
weights=weights_fine,
|
||||||
)
|
)
|
||||||
accumulation_fine = self.renderer_accumulation(weights_fine)
|
accumulation_fine = self.renderer_accumulation(weights_fine)
|
||||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.ts)
|
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.bins)
|
||||||
semantic_fine = self.renderer_semantic(field_outputs_fine[FieldHeadNames.SEMANTICS], weights=weights_fine)
|
semantic_fine = self.renderer_semantic(field_outputs_fine[FieldHeadNames.SEMANTICS], weights=weights_fine)
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class NeRFGraph(Graph):
|
|||||||
weights=weights_coarse,
|
weights=weights_coarse,
|
||||||
)
|
)
|
||||||
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
||||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.ts)
|
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.bins)
|
||||||
|
|
||||||
# pdf sampling
|
# pdf sampling
|
||||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||||
@@ -104,7 +104,7 @@ class NeRFGraph(Graph):
|
|||||||
weights=weights_fine,
|
weights=weights_fine,
|
||||||
)
|
)
|
||||||
accumulation_fine = self.renderer_accumulation(weights_fine)
|
accumulation_fine = self.renderer_accumulation(weights_fine)
|
||||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.ts)
|
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.bins)
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
"rgb_coarse": rgb_coarse,
|
"rgb_coarse": rgb_coarse,
|
||||||
|
|||||||
+16
-13
@@ -32,7 +32,7 @@ class Sampler(nn.Module):
|
|||||||
"""Generate ray samples with optional occupancy filtering"""
|
"""Generate ray samples with optional occupancy filtering"""
|
||||||
ray_samples = self.generate_ray_samples(*args, **kwargs)
|
ray_samples = self.generate_ray_samples(*args, **kwargs)
|
||||||
if self.occupancy_field is not None:
|
if self.occupancy_field is not None:
|
||||||
densities = self.occupancy_field.get_densities(ray_samples.positions)
|
densities = self.occupancy_field.get_densities(ray_samples.frustums.get_positions())
|
||||||
weights = ray_samples.get_weights(densities)
|
weights = ray_samples.get_weights(densities)
|
||||||
|
|
||||||
valid_mask = weights >= self.weight_threshold
|
valid_mask = weights >= self.weight_threshold
|
||||||
@@ -83,18 +83,19 @@ class UniformSampler(Sampler):
|
|||||||
num_samples = num_samples or self.num_samples
|
num_samples = num_samples or self.num_samples
|
||||||
num_rays = ray_bundle.origins.shape[0]
|
num_rays = ray_bundle.origins.shape[0]
|
||||||
|
|
||||||
bins = torch.linspace(0.0, 1.0, num_samples + 1).to(ray_bundle.origins.device) # shape (num_samples+1,)
|
bins = torch.linspace(0.0, 1.0, num_samples + 1).to(ray_bundle.origins.device) # shape (num_samples+1)
|
||||||
bins = ray_bundle.nears[:, None] + bins[None, :] * (
|
bins = ray_bundle.nears[:, None] + bins[None, :] * (
|
||||||
ray_bundle.fars[:, None] - ray_bundle.nears[:, None]
|
ray_bundle.fars[:, None] - ray_bundle.nears[:, None]
|
||||||
) # shape (num_rays, num_samples+1)
|
) # shape (num_rays, num_samples+1)
|
||||||
|
|
||||||
if self.train_stratified and self.training:
|
if self.train_stratified and self.training:
|
||||||
t_rand = torch.rand((num_rays, num_samples), dtype=bins.dtype, device=bins.device)
|
t_rand = torch.rand((num_rays, num_samples + 1), dtype=bins.dtype, device=bins.device)
|
||||||
ts = bins[:, :-1] + t_rand * (bins[:, 1:] - bins[:, :-1]) # shape (num_rays, num_samples)
|
bin_centers = (bins[..., 1:] + bins[..., :-1]) / 2.0
|
||||||
else:
|
bin_upper = torch.cat([bin_centers, bins[..., -1:]], -1)
|
||||||
ts = (bins[:, 1:] + bins[:, :-1]) / 2
|
bin_lower = torch.cat([bins[..., :1], bin_centers], -1)
|
||||||
|
bins = bin_lower + (bin_upper - bin_lower) * t_rand
|
||||||
|
|
||||||
ray_samples = ray_bundle.get_ray_samples(ts)
|
ray_samples = ray_bundle.get_ray_samples(bins)
|
||||||
|
|
||||||
return ray_samples
|
return ray_samples
|
||||||
|
|
||||||
@@ -171,21 +172,23 @@ class PDFSampler(Sampler):
|
|||||||
indicies_g = torch.stack([below, above], -1)
|
indicies_g = torch.stack([below, above], -1)
|
||||||
matched_shape = (indicies_g.shape[0], indicies_g.shape[1], cdf.shape[-1])
|
matched_shape = (indicies_g.shape[0], indicies_g.shape[1], cdf.shape[-1])
|
||||||
cdf_g = torch.gather(cdf.unsqueeze(1).expand(matched_shape), dim=2, index=indicies_g)
|
cdf_g = torch.gather(cdf.unsqueeze(1).expand(matched_shape), dim=2, index=indicies_g)
|
||||||
bins_g = torch.gather(ray_samples.ts.unsqueeze(1).expand(matched_shape), dim=2, index=indicies_g)
|
# TODO tancik (Fix bin samples)
|
||||||
|
steps = (ray_samples.bins[:, :-1] + ray_samples.bins[:, 1:]) / 2
|
||||||
|
bins_g = torch.gather(steps.unsqueeze(1).expand(matched_shape), dim=2, index=indicies_g)
|
||||||
|
|
||||||
denom = cdf_g[..., 1] - cdf_g[..., 0]
|
denom = cdf_g[..., 1] - cdf_g[..., 0]
|
||||||
denom = torch.where(denom < eps, torch.ones_like(denom), denom)
|
denom = torch.where(denom < eps, torch.ones_like(denom), denom)
|
||||||
t = (u - cdf_g[..., 0]) / denom
|
t = (u - cdf_g[..., 0]) / denom
|
||||||
ts = bins_g[..., 0] + t * (bins_g[..., 1] - bins_g[..., 0])
|
bins = bins_g[..., 0] + t * (bins_g[..., 1] - bins_g[..., 0])
|
||||||
|
|
||||||
if self.include_original:
|
if self.include_original:
|
||||||
ts, _ = torch.sort(torch.cat([ray_samples.ts, ts], -1), -1)
|
bins, _ = torch.sort(torch.cat([ray_samples.bins, bins], -1), -1)
|
||||||
else:
|
else:
|
||||||
ts, _ = torch.sort(ts, -1)
|
bins, _ = torch.sort(bins, -1)
|
||||||
|
|
||||||
# Stop gradients
|
# Stop gradients
|
||||||
ts = ts.detach()
|
bins = bins.detach()
|
||||||
|
|
||||||
ray_samples = ray_bundle.get_ray_samples(ts)
|
ray_samples = ray_bundle.get_ray_samples(bins)
|
||||||
|
|
||||||
return ray_samples
|
return ray_samples
|
||||||
@@ -152,13 +152,13 @@ class DepthRenderer(nn.Module):
|
|||||||
self.method = method
|
self.method = method
|
||||||
|
|
||||||
def forward(
|
def forward(
|
||||||
self, weights: TensorType[..., "num_samples"], ts: TensorType[..., "num_samples"]
|
self, weights: TensorType[..., "num_samples"], bins: TensorType[..., "num_samples+1"]
|
||||||
) -> TensorType[..., 1]:
|
) -> TensorType[..., 1]:
|
||||||
"""Composite samples along ray and calculate disparities.
|
"""Composite samples along ray and calculate disparities.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
weights (TensorType[..., "num_samples"]): Weights for each sample
|
weights (TensorType[..., "num_samples"]): Weights for each sample
|
||||||
ts (TensorType[..., "num_samples"]): Sample locations along rays
|
bins (TensorType[..., "num_samples+1"]): Bins along ray
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
TensorType[..., 1]: Outputs of depth values.
|
TensorType[..., 1]: Outputs of depth values.
|
||||||
@@ -166,9 +166,10 @@ class DepthRenderer(nn.Module):
|
|||||||
|
|
||||||
if self.method == "expected":
|
if self.method == "expected":
|
||||||
eps = 1e-10
|
eps = 1e-10
|
||||||
depth = torch.sum(weights * ts, dim=-1) / (torch.sum(weights, -1) + eps)
|
steps = (bins[..., :-1] + bins[..., 1:]) / 2
|
||||||
|
depth = torch.sum(weights * steps, dim=-1) / (torch.sum(weights, -1) + eps)
|
||||||
|
|
||||||
depth = torch.clip(depth, ts[..., 0], ts[..., -1])
|
depth = torch.clip(depth, steps[..., 0], steps[..., -1])
|
||||||
|
|
||||||
return depth[..., None]
|
return depth[..., None]
|
||||||
|
|
||||||
|
|||||||
+57
-20
@@ -83,15 +83,15 @@ class Camera:
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def generate_rays(
|
def generate_rays(
|
||||||
cls,
|
cls,
|
||||||
intrinsics: TensorType["num_rays", "num_intrinsics_params"],
|
intrinsics: TensorType[..., "num_intrinsics_params"],
|
||||||
camera_to_world: TensorType["num_rays", 3, 4],
|
camera_to_world: TensorType[..., 3, 4],
|
||||||
coords: TensorType["image_height", "image_width", 2],
|
coords: TensorType[..., 2],
|
||||||
) -> RayBundle:
|
) -> RayBundle:
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
intrinsics (TensorType["num_rays", "num_intrinsics_params"]): Camera intrinsics
|
intrinsics (TensorType[..., "num_intrinsics_params"]): Camera intrinsics
|
||||||
camera_to_world (TensorType["num_rays", 3, 4]): Camera to world transformation matrix
|
camera_to_world (TensorType[..., 3, 4]): Camera to world transformation matrix
|
||||||
coords (TensorType["image_height", "image_width", 2]): Image grid coordinates
|
coords (TensorType[..., 2]): Image grid coordinates
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
RayBundle: A bundle of rays for each grid coordinate.
|
RayBundle: A bundle of rays for each grid coordinate.
|
||||||
@@ -193,7 +193,17 @@ class PinholeCamera(Camera):
|
|||||||
) # (..., 1, 3) * (..., 3, 3) -> (..., 3)
|
) # (..., 1, 3) * (..., 3, 3) -> (..., 3)
|
||||||
directions = normalize(directions, dim=-1)
|
directions = normalize(directions, dim=-1)
|
||||||
origins = camera_to_world[..., :3, 3] # (..., 3)
|
origins = camera_to_world[..., :3, 3] # (..., 3)
|
||||||
return RayBundle(origins=origins, directions=directions)
|
|
||||||
|
## Calculate pixel area directly
|
||||||
|
dirx_min = normalize(torch.cat([(x - cx - 0.5) / fx, -(y - cy) / fy, -torch.ones_like(x)], -1), dim=-1)
|
||||||
|
dirx_max = normalize(torch.cat([(x - cx + 0.5) / fx, -(y - cy) / fy, -torch.ones_like(x)], -1), dim=-1)
|
||||||
|
diry_min = normalize(torch.cat([(x - cx) / fx, -(y - cy - 0.5) / fy, -torch.ones_like(x)], -1), dim=-1)
|
||||||
|
diry_max = normalize(torch.cat([(x - cx) / fx, -(y - cy + 0.5) / fy, -torch.ones_like(x)], -1), dim=-1)
|
||||||
|
dx = torch.sqrt(torch.sum((dirx_max - dirx_min) ** 2, dim=-1))
|
||||||
|
dy = torch.sqrt(torch.sum((diry_max - diry_min) ** 2, dim=-1))
|
||||||
|
pixel_area = dx * dy
|
||||||
|
|
||||||
|
return RayBundle(origins=origins, directions=directions, pixel_area=pixel_area[..., None])
|
||||||
|
|
||||||
|
|
||||||
class SimplePinholeCamera(PinholeCamera):
|
class SimplePinholeCamera(PinholeCamera):
|
||||||
@@ -234,25 +244,52 @@ class EquirectangularCamera(Camera):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def generate_rays(
|
def generate_rays(
|
||||||
cls,
|
cls,
|
||||||
intrinsics: TensorType["num_rays", 2],
|
intrinsics: TensorType[..., 2],
|
||||||
camera_to_world: TensorType["num_rays", 3, 4],
|
camera_to_world: TensorType[..., 3, 4],
|
||||||
coords: TensorType["num_rays", 2],
|
coords: TensorType[..., 2],
|
||||||
) -> RayBundle:
|
) -> RayBundle:
|
||||||
|
|
||||||
phi = coords[:, 0:1] # (num_rays, 1)
|
y = coords[..., 0:1] # (num_rays, 1)
|
||||||
theta = coords[:, 1:2] # (num_rays, 1)
|
x = coords[..., 1:2] # (num_rays, 1)
|
||||||
|
|
||||||
height = intrinsics[:, 0:1]
|
height = intrinsics[..., 0:1]
|
||||||
width = intrinsics[:, 1:2]
|
width = intrinsics[..., 1:2]
|
||||||
|
|
||||||
phi = phi / height * torch.pi
|
phi = y / height * torch.pi
|
||||||
theta = -theta / width * 2 * torch.pi
|
theta = -x / width * 2 * torch.pi
|
||||||
|
|
||||||
directions = torch.stack(
|
d_phi_min = (y + 0.5) / height * torch.pi
|
||||||
[torch.cos(theta) * torch.sin(phi), torch.sin(theta) * torch.sin(phi), torch.cos(phi)], dim=-1
|
d_phi_max = (y - 0.5) / height * torch.pi
|
||||||
|
d_theta_min = -(x - 0.5) / width * 2 * torch.pi
|
||||||
|
d_theta_max = -(x + 0.5) / width * 2 * torch.pi
|
||||||
|
|
||||||
|
s_phi = torch.sin(phi)
|
||||||
|
c_phi = torch.cos(phi)
|
||||||
|
s_theta = torch.sin(theta)
|
||||||
|
c_theta = torch.cos(theta)
|
||||||
|
|
||||||
|
directions = torch.cat([c_theta * s_phi, s_theta * s_phi, c_phi], dim=-1)
|
||||||
|
origins = camera_to_world[..., :3, 3] # (num_rays, 3)
|
||||||
|
|
||||||
|
## Calculate area directly
|
||||||
|
dirx_min = normalize(
|
||||||
|
torch.cat([torch.cos(d_theta_min) * s_phi, torch.sin(d_theta_min) * s_phi, c_phi], -1), dim=-1
|
||||||
)
|
)
|
||||||
origins = camera_to_world[:, :3, 3] # (num_rays, 3)
|
dirx_max = normalize(
|
||||||
return RayBundle(origins=origins, directions=directions)
|
torch.cat([torch.cos(d_theta_max) * s_phi, torch.sin(d_theta_max) * s_phi, c_phi], -1), dim=-1
|
||||||
|
)
|
||||||
|
diry_min = normalize(
|
||||||
|
torch.cat([c_theta * torch.sin(d_phi_min), s_theta * torch.sin(d_phi_min), torch.cos(d_phi_min)], -1),
|
||||||
|
dim=-1,
|
||||||
|
)
|
||||||
|
diry_max = normalize(
|
||||||
|
torch.cat([c_theta * torch.sin(d_phi_max), s_theta * torch.sin(d_phi_max), torch.cos(d_phi_max)], -1),
|
||||||
|
dim=-1,
|
||||||
|
)
|
||||||
|
dx = torch.sqrt(torch.sum((dirx_max - dirx_min) ** 2, dim=-1))
|
||||||
|
dy = torch.sqrt(torch.sum((diry_max - diry_min) ** 2, dim=-1))
|
||||||
|
pixel_area = dx * dy
|
||||||
|
return RayBundle(origins=origins, directions=directions, pixel_area=pixel_area)
|
||||||
|
|
||||||
|
|
||||||
def get_camera_model(num_intrinsics_params: int) -> Type[Camera]:
|
def get_camera_model(num_intrinsics_params: int) -> Type[Camera]:
|
||||||
|
|||||||
+58
-31
@@ -13,12 +13,40 @@ from pyrad.utils.misc import is_not_none
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Frustums:
|
class Frustums:
|
||||||
|
"""Describes region of space as a frustum.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
origins (TensorType[..., 3]): xyz coordinate for ray origin.
|
||||||
|
directions (TensorType[..., 3]): Direction of ray.
|
||||||
|
frustum_starts (TensorType[..., 1]): Where the frustum starts along a ray.
|
||||||
|
frustum_ends (TensorType[..., 3]): Where the frustim ends along a ray.
|
||||||
|
pixel_area (TensorType[..., 1]): Projected area of pixel a distance 1 away from origin.
|
||||||
|
"""
|
||||||
|
|
||||||
origins: TensorType[..., 3]
|
origins: TensorType[..., 3]
|
||||||
directions: TensorType[..., 3]
|
directions: TensorType[..., 3]
|
||||||
frustum_starts: TensorType[..., 1]
|
frustum_starts: TensorType[..., 1]
|
||||||
frustum_ends: TensorType[..., 1]
|
frustum_ends: TensorType[..., 1]
|
||||||
radius: TensorType[..., 1]
|
pixel_area: TensorType[..., 1]
|
||||||
|
|
||||||
|
def get_positions(self) -> TensorType[..., 3]:
|
||||||
|
"""Returns "center" position of frustum. Not weighted by mass."""
|
||||||
|
return self.origins + self.directions * (self.frustum_starts + self.frustum_ends) / 2
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_mock_frustum(cls) -> "Frustums":
|
||||||
|
"""Helper function to generate a placeholder frustum.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Frustums: A size 1 frustum with meaningless values.
|
||||||
|
"""
|
||||||
|
return Frustums(
|
||||||
|
origins=torch.ones((1, 3)),
|
||||||
|
directions=torch.ones((1, 3)),
|
||||||
|
frustum_starts=torch.ones((1, 1)),
|
||||||
|
frustum_ends=torch.ones((1, 1)) + 1,
|
||||||
|
pixel_area=torch.ones((1, 1)),
|
||||||
|
)
|
||||||
|
|
||||||
def apply_masks(self, mask: TensorType) -> "Frustums":
|
def apply_masks(self, mask: TensorType) -> "Frustums":
|
||||||
"""Use valid_mask to mask samples.
|
"""Use valid_mask to mask samples.
|
||||||
@@ -34,7 +62,7 @@ class Frustums:
|
|||||||
directions=self.directions[mask],
|
directions=self.directions[mask],
|
||||||
frustum_starts=self.frustum_starts[mask],
|
frustum_starts=self.frustum_starts[mask],
|
||||||
frustum_ends=self.frustum_ends[mask],
|
frustum_ends=self.frustum_ends[mask],
|
||||||
radius=self.radius[mask],
|
pixel_area=self.pixel_area[mask],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -43,10 +71,10 @@ class PointSamples:
|
|||||||
"""Samples in space.
|
"""Samples in space.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
positions (TensorType[..., 3]): XYZ locations
|
frustims (Frustums): Frustums along ray.
|
||||||
directions (TensorType[..., 3]): Unit direction vector
|
directions (TensorType[..., 3]): Unit direction vector.
|
||||||
camera_indices (TensorType[..., 1]): Camera index
|
camera_indices (TensorType[..., 1]): Camera index.
|
||||||
valid_mask (TensorType[...]): Rays that are valid
|
valid_mask (TensorType[...]): Rays that are valid.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
frustums: Frustums
|
frustums: Frustums
|
||||||
@@ -79,18 +107,17 @@ class RaySamples:
|
|||||||
"""Samples along a ray
|
"""Samples along a ray
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
positions (TensorType[..., 3]): XYZ locations
|
frustums (Frustums): Frustums along ray.
|
||||||
directions (TensorType[..., 3]): Unit direction vector
|
camera_indices (TensorType[..., 1]): Camera index.
|
||||||
camera_indices (TensorType[..., 1]): Camera index
|
valid_mask (TensorType[...]): Rays that are valid.
|
||||||
valid_mask (TensorType[...]): Rays that are valid
|
bins (TensorType[..., 1]): frustum bins along ray.
|
||||||
ts (TensorType[..., 1]): "time steps", distances along ray
|
deltas )TensorType[..., 1]): "width" of each sample.
|
||||||
deltas )TensorType[..., 1]): "width" of each sample
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
frustums: TensorType[..., 3]
|
frustums: TensorType[..., 3]
|
||||||
camera_indices: TensorType[..., 1] = None
|
camera_indices: TensorType[..., 1] = None
|
||||||
valid_mask: TensorType[...] = None
|
valid_mask: TensorType[...] = None
|
||||||
ts: TensorType[..., 1] = None
|
bins: TensorType[..., 1] = None
|
||||||
deltas: TensorType[..., 1] = None
|
deltas: TensorType[..., 1] = None
|
||||||
|
|
||||||
def to_point_samples(self) -> PointSamples:
|
def to_point_samples(self) -> PointSamples:
|
||||||
@@ -144,6 +171,7 @@ class RayBundle:
|
|||||||
Args:
|
Args:
|
||||||
origins (TensorType[..., 3]): Ray origins (XYZ)
|
origins (TensorType[..., 3]): Ray origins (XYZ)
|
||||||
directions (TensorType[..., 3]): Unit ray direction vector
|
directions (TensorType[..., 3]): Unit ray direction vector
|
||||||
|
pixel_area (TensorType[..., 1]): Projected area of pixel a distance 1 away from origin.
|
||||||
camera_indices (TensorType[..., 1]): Camera indices
|
camera_indices (TensorType[..., 1]): Camera indices
|
||||||
nears (TensorType[..., 1]): Distance along ray to start sampling
|
nears (TensorType[..., 1]): Distance along ray to start sampling
|
||||||
fars (TensorType[..., 1]): Rays Distance along ray to stop sampling
|
fars (TensorType[..., 1]): Rays Distance along ray to stop sampling
|
||||||
@@ -152,7 +180,7 @@ class RayBundle:
|
|||||||
|
|
||||||
origins: TensorType["num_rays", 3]
|
origins: TensorType["num_rays", 3]
|
||||||
directions: TensorType["num_rays", 3]
|
directions: TensorType["num_rays", 3]
|
||||||
radius: TensorType["num_rays", 1]
|
pixel_area: TensorType["num_rays", 1]
|
||||||
camera_indices: Optional[TensorType["num_rays", 1]] = None
|
camera_indices: Optional[TensorType["num_rays", 1]] = None
|
||||||
nears: Optional[TensorType["num_rays"]] = None
|
nears: Optional[TensorType["num_rays"]] = None
|
||||||
fars: Optional[TensorType["num_rays"]] = None
|
fars: Optional[TensorType["num_rays"]] = None
|
||||||
@@ -195,7 +223,7 @@ class RayBundle:
|
|||||||
return RayBundle(
|
return RayBundle(
|
||||||
origins=self.origins[indices],
|
origins=self.origins[indices],
|
||||||
directions=self.directions[indices],
|
directions=self.directions[indices],
|
||||||
radius=self.radius[indices],
|
pixel_area=self.pixel_area[indices],
|
||||||
camera_indices=self.camera_indices[indices],
|
camera_indices=self.camera_indices[indices],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -211,7 +239,7 @@ class RayBundle:
|
|||||||
return RayBundle(
|
return RayBundle(
|
||||||
origins=self.origins[valid_mask],
|
origins=self.origins[valid_mask],
|
||||||
directions=self.directions[valid_mask],
|
directions=self.directions[valid_mask],
|
||||||
radius=self.radius[valid_mask],
|
pixel_area=self.pixel_area[valid_mask],
|
||||||
camera_indices=self.camera_indices[valid_mask] if is_not_none(self.camera_indices) else None,
|
camera_indices=self.camera_indices[valid_mask] if is_not_none(self.camera_indices) else None,
|
||||||
nears=self.nears[valid_mask] if is_not_none(self.nears) else None,
|
nears=self.nears[valid_mask] if is_not_none(self.nears) else None,
|
||||||
fars=self.fars[valid_mask] if is_not_none(self.fars) else None,
|
fars=self.fars[valid_mask] if is_not_none(self.fars) else None,
|
||||||
@@ -235,46 +263,45 @@ class RayBundle:
|
|||||||
return RayBundle(
|
return RayBundle(
|
||||||
origins=self.origins.view(-1, 3)[start_idx:end_idx],
|
origins=self.origins.view(-1, 3)[start_idx:end_idx],
|
||||||
directions=self.directions.view(-1, 3)[start_idx:end_idx],
|
directions=self.directions.view(-1, 3)[start_idx:end_idx],
|
||||||
radius=self.radius.view(-1, 1)[start_idx:end_idx],
|
pixel_area=self.pixel_area.view(-1, 1)[start_idx:end_idx],
|
||||||
camera_indices=camera_indices,
|
camera_indices=camera_indices,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_ray_samples(self, ts: TensorType[..., "num_samples"]) -> RaySamples:
|
def get_ray_samples(self, bins: TensorType["num_rays", "num_samples+1"]) -> RaySamples:
|
||||||
"""Produces samples for each ray by projection points along the ray direction.
|
"""Produces samples for each ray by projection points along the ray direction.
|
||||||
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
ts (TensorType[..., "num_samples"]): Distance from origin of sample points.
|
bins (TensorType["num_rays", "num_samples+1"]): Distance from origin of sample points.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
RaySamples: Samples projected along ray.
|
RaySamples: Samples projected along ray.
|
||||||
"""
|
"""
|
||||||
positions = self.origins[:, None] + ts[:, :, None] * self.directions[:, None]
|
num_samples = bins.shape[-1] - 1
|
||||||
|
|
||||||
valid_mask = torch.ones_like(ts, dtype=torch.bool)
|
valid_mask = torch.ones((bins.shape[0], num_samples), dtype=torch.bool, device=bins.device)
|
||||||
|
|
||||||
dists = ts[..., 1:] - ts[..., :-1]
|
dists = bins[:, 1:] - bins[:, :-1] # [N_rays, N_samples]
|
||||||
dists = torch.cat([dists, dists[..., -1:]], -1) # [N_rays, N_samples]
|
deltas = dists * torch.norm(self.directions[:, None, :], dim=-1)
|
||||||
deltas = dists * torch.norm(self.directions[..., None, :], dim=-1)
|
|
||||||
|
|
||||||
if is_not_none(self.camera_indices):
|
if is_not_none(self.camera_indices):
|
||||||
camera_indices = self.camera_indices.unsqueeze(1).repeat(1, positions.shape[1])
|
camera_indices = self.camera_indices.unsqueeze(1).repeat(1, num_samples)
|
||||||
else:
|
else:
|
||||||
camera_indices = None
|
camera_indices = None
|
||||||
|
|
||||||
frustums = Frustums(
|
frustums = Frustums(
|
||||||
origins=self.origins,
|
origins=self.origins.unsqueeze(1).repeat(1, num_samples, 1),
|
||||||
directions=self.directions.unsqueeze(1).repeat(1, positions.shape[1], 1),
|
directions=self.directions.unsqueeze(1).repeat(1, num_samples, 1),
|
||||||
frustum_starts=ts[:, :-1, None],
|
frustum_starts=bins[:, :-1, None],
|
||||||
frustum_ends=ts[:, :-1, None],
|
frustum_ends=bins[:, 1:, None],
|
||||||
radius=self.radius,
|
pixel_area=self.pixel_area.unsqueeze(1).repeat(1, num_samples, 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
ray_samples = RaySamples(
|
ray_samples = RaySamples(
|
||||||
frustums=frustums,
|
frustums=frustums,
|
||||||
camera_indices=camera_indices,
|
camera_indices=camera_indices,
|
||||||
valid_mask=valid_mask,
|
valid_mask=valid_mask,
|
||||||
ts=ts,
|
bins=bins,
|
||||||
deltas=deltas,
|
deltas=deltas,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import torch
|
|||||||
|
|
||||||
from pyrad.nerf.field_modules.field_heads import FieldHeadNames
|
from pyrad.nerf.field_modules.field_heads import FieldHeadNames
|
||||||
from pyrad.nerf.fields.instant_ngp_field import TCNNInstantNGPField
|
from pyrad.nerf.fields.instant_ngp_field import TCNNInstantNGPField
|
||||||
from pyrad.structures.rays import PointSamples
|
from pyrad.structures.rays import Frustums, PointSamples
|
||||||
|
|
||||||
|
|
||||||
def test_tcnn_instant_ngp_field():
|
def test_tcnn_instant_ngp_field():
|
||||||
@@ -28,7 +28,14 @@ def test_tcnn_instant_ngp_field():
|
|||||||
num_samples = 256
|
num_samples = 256
|
||||||
positions = torch.rand((num_rays, num_samples, 3), dtype=torch.float32, device=device)
|
positions = torch.rand((num_rays, num_samples, 3), dtype=torch.float32, device=device)
|
||||||
directions = torch.rand_like(positions)
|
directions = torch.rand_like(positions)
|
||||||
point_samples = PointSamples(positions=positions, directions=directions)
|
frustums = Frustums(
|
||||||
|
origins=positions,
|
||||||
|
directions=directions,
|
||||||
|
frustum_starts=torch.zeros((*directions.shape[:-1], 1)),
|
||||||
|
frustum_ends=torch.zeros((*directions.shape[:-1], 1)),
|
||||||
|
pixel_area=torch.ones((*directions.shape[:-1], 1)),
|
||||||
|
)
|
||||||
|
point_samples = PointSamples(frustums=frustums)
|
||||||
field_outputs = field.forward(point_samples)
|
field_outputs = field.forward(point_samples)
|
||||||
|
|
||||||
positions_dtype = positions.dtype
|
positions_dtype = positions.dtype
|
||||||
|
|||||||
@@ -62,12 +62,12 @@ def test_depth_renderer():
|
|||||||
weights = torch.ones((3, num_samples))
|
weights = torch.ones((3, num_samples))
|
||||||
weights /= torch.sum(weights, axis=-1, keepdim=True)
|
weights /= torch.sum(weights, axis=-1, keepdim=True)
|
||||||
|
|
||||||
ts = torch.linspace(0, 100, num_samples)
|
bins = torch.linspace(0, 100, num_samples + 1)
|
||||||
ts = torch.stack([ts, ts, ts], dim=0)
|
bins = torch.stack([bins, bins, bins], dim=0)
|
||||||
|
|
||||||
depth_renderer = renderers.DepthRenderer()
|
depth_renderer = renderers.DepthRenderer()
|
||||||
|
|
||||||
depth = depth_renderer(weights=weights, ts=ts)
|
depth = depth_renderer(weights=weights, bins=bins)
|
||||||
assert torch.min(depth) > 0
|
assert torch.min(depth) > 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,14 @@ def test_uniform_sampler():
|
|||||||
|
|
||||||
origins = torch.zeros((10, 3))
|
origins = torch.zeros((10, 3))
|
||||||
directions = torch.ones_like(origins)
|
directions = torch.ones_like(origins)
|
||||||
ray_bundle = RayBundle(origins=origins, directions=directions)
|
radius = torch.ones((10, 1))
|
||||||
|
ray_bundle = RayBundle(origins=origins, directions=directions, pixel_area=radius)
|
||||||
collider = NearFarCollider(near_plane, far_plane)
|
collider = NearFarCollider(near_plane, far_plane)
|
||||||
ray_bundle = collider(ray_bundle)
|
ray_bundle = collider(ray_bundle)
|
||||||
|
|
||||||
ray_samples = sampler(ray_bundle)
|
ray_samples = sampler(ray_bundle)
|
||||||
|
|
||||||
assert ray_samples.positions.shape[-2] == num_samples
|
assert ray_samples.frustums.get_positions().shape[-2] == num_samples
|
||||||
|
|
||||||
# TODO Tancik: Add more precise tests
|
# TODO Tancik: Add more precise tests
|
||||||
|
|
||||||
@@ -36,7 +37,8 @@ def test_pdf_sampler():
|
|||||||
|
|
||||||
origins = torch.zeros((10, 3))
|
origins = torch.zeros((10, 3))
|
||||||
directions = torch.ones_like(origins)
|
directions = torch.ones_like(origins)
|
||||||
ray_bundle = RayBundle(origins=origins, directions=directions)
|
radius = torch.ones((10, 1))
|
||||||
|
ray_bundle = RayBundle(origins=origins, directions=directions, pixel_area=radius)
|
||||||
collider = NearFarCollider(near_plane, far_plane)
|
collider = NearFarCollider(near_plane, far_plane)
|
||||||
ray_bundle = collider(ray_bundle)
|
ray_bundle = collider(ray_bundle)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Test the camera classes.
|
|||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from pyrad.structures.cameras import PinholeCamera
|
from pyrad.structures.cameras import EquirectangularCamera, PinholeCamera
|
||||||
from pyrad.structures.rays import RayBundle
|
from pyrad.structures.rays import RayBundle
|
||||||
|
|
||||||
|
|
||||||
@@ -14,3 +14,30 @@ def test_pinhole_camera():
|
|||||||
camera_ray_bundle = pinhole_camera.generate_camera_rays()
|
camera_ray_bundle = pinhole_camera.generate_camera_rays()
|
||||||
assert isinstance(camera_ray_bundle, RayBundle)
|
assert isinstance(camera_ray_bundle, RayBundle)
|
||||||
assert torch.allclose(camera_ray_bundle.origins[0], torch.tensor([0.0, 0.0, 0.0]))
|
assert torch.allclose(camera_ray_bundle.origins[0], torch.tensor([0.0, 0.0, 0.0]))
|
||||||
|
|
||||||
|
# Test generate rays on 1D input
|
||||||
|
num_rays = 10
|
||||||
|
intrinsics = torch.ones(num_rays, 4) # (num_rays, num_intrinsics_params)
|
||||||
|
camera_to_world = torch.ones(num_rays, 3, 4) # (num_rays, 3, 4)
|
||||||
|
coords = torch.ones(num_rays, 2)
|
||||||
|
pinhole_camera.generate_rays(intrinsics, camera_to_world, coords)
|
||||||
|
|
||||||
|
|
||||||
|
def test_equirectangular_camera():
|
||||||
|
"""Test that the equirectangular camera model works."""
|
||||||
|
equirectangular_camera = EquirectangularCamera(height=400, width=400)
|
||||||
|
camera_ray_bundle = equirectangular_camera.generate_camera_rays()
|
||||||
|
assert isinstance(camera_ray_bundle, RayBundle)
|
||||||
|
assert torch.allclose(camera_ray_bundle.origins[0], torch.tensor([0.0, 0.0, 0.0]))
|
||||||
|
|
||||||
|
# Test generate rays on 1D input
|
||||||
|
num_rays = 10
|
||||||
|
intrinsics = torch.ones(num_rays, 2) * 20 # (num_rays, num_intrinsics_params)
|
||||||
|
camera_to_world = torch.ones(num_rays, 3, 4) # (num_rays, 3, 4)
|
||||||
|
coords = torch.ones(num_rays, 2)
|
||||||
|
equirectangular_camera.generate_rays(intrinsics, camera_to_world, coords)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_pinhole_camera()
|
||||||
|
test_equirectangular_camera()
|
||||||
@@ -14,5 +14,6 @@ def test_run_train():
|
|||||||
conf = compose("test_dryrun.yaml")
|
conf = compose("test_dryrun.yaml")
|
||||||
main(conf)
|
main(conf)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_run_train()
|
test_run_train()
|
||||||
Reference in new issue
Block a user