Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depth supervision for nerfacto #1173

Merged
merged 21 commits into from
Jan 2, 2023

Conversation

mpmisko
Copy link
Member

@mpmisko mpmisko commented Dec 26, 2022

Implements depth-supervised Nerfacto based on with depth losses from Depth-supervised NeRF and Urban Radiance Fields. I found the Depth-supervised NeRF loss to perform better for my dataset, however, Urban Radiance Fields reports it is SOTA, so it may work better for other use cases. I set the Depth-supervised NeRF loss as default with some reasonable initial hyperparameters.

I tested the method in an indoor livingroom scene. The additional depth loss helps with depths (see depth_mse), however slightly hurts other eval metrics:

Screen Shot 2023-01-01 at 10 42 22 PM

Example depth colormaps (left is nerfacto & right is nerfacto with depth supervision, left image is ground truth depth in both cases).

Screen Shot 2023-01-01 at 10 44 33 PM

I generally find that the additional depth supervision removes floaters or makes the floaters more diffuse in the worst case. However, it seems to me that nerfacto is slightly sharper around objects, which could be explained by noise in depth measurements. Depth supervision will be probably be helpful on a case-by-case basis.

@mpmisko mpmisko marked this pull request as draft December 26, 2022 15:43
@mpmisko mpmisko changed the title Depth supervision for nerfacto [WIP] Depth supervision for nerfacto Dec 26, 2022
Copy link
Contributor

@tancik tancik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I added a few comments, mostly on missing documentation. Two additional things, 1. can you provide some example results in this PR, ie a scene trained with and without DS to verify that it is working as expected. 2. Can you add some documentation with respect to the expected format of the depth images. This can be added to some of the docstrings, but also it would make sense to add it to this page - https://github.com/nerfstudio-project/nerfstudio/blob/main/docs/quickstart/data_conventions.md
Specifics such as, num channels, data format (uint8 vs 16 bit), is it "distance" vs "depth", what resolution it should be, how to account for sparsity (from lidar), how to specify path in json.

nerfstudio/cameras/camera_utils.py Outdated Show resolved Hide resolved
nerfstudio/data/dataparsers/nerfstudio_dataparser.py Outdated Show resolved Hide resolved
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Depth data parser."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is following the same format at the nerfstudio data, what are your thoughts on adding a if "depth_file_path" in frame logic to the nerfstudio-dataparser (similar to what we do with masks)

Copy link
Member Author

@mpmisko mpmisko Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Went with this approach instead.

nerfstudio/data/datasets/depth_dataset.py Show resolved Hide resolved
nerfstudio/data/utils/data_utils.py Outdated Show resolved Hide resolved
) -> torch.Tensor:
"""Loads, rescales and resizes depth images. Assumes Record3D depth format."""
image = cv2.imread(str(filepath.absolute()), cv2.IMREAD_ANYDEPTH)
image = image.astype(np.float64) * _MILLIMETER_TO_METER_SCALE_FACTOR * scene_scale_factor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this scale factor be a variable? If not, it should be well documented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I made it a variable instead in the NerfstudioDataParserConfig.

nerfstudio/model_components/losses.py Outdated Show resolved Hide resolved
nerfstudio/model_components/losses.py Show resolved Hide resolved
@mpmisko
Copy link
Member Author

mpmisko commented Jan 1, 2023

Thanks for the review @tancik!

I believe I addressed all of the comments. Please take a look when you can.

I also added some results to the PR description and updated the docs. Happy to elaborate more if you have some comments.

Copy link
Contributor

@tancik tancik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for making the changes

@mpmisko mpmisko marked this pull request as ready for review January 2, 2023 08:05
@mpmisko mpmisko changed the title [WIP] Depth supervision for nerfacto Depth supervision for nerfacto Jan 2, 2023
@mpmisko mpmisko merged commit 3da8770 into nerfstudio-project:main Jan 2, 2023
@mpmisko mpmisko deleted the depth_supervision branch January 2, 2023 09:13
tancik pushed a commit to dozeri83/nerfstudio that referenced this pull request Jan 20, 2023
* Implement depth supervision

* Fixes

* Change normalize dtype

* refactor

* Change depth weight

* Small refactor

* Change docstring

* Removu unused import

* Add assumption to depth comment

* Implement URF loss

* Remove default depth loss type param

* URF fixes

* Fix depth loss scale

* Visualize gt depths

* Fixes & documentation

* Documentation and formatting

* Fix formatting problems

* Fix linter problems

* Fix tests

* Fix tests
lucasthahn pushed a commit to tne-ai/nerfstudio that referenced this pull request Jan 26, 2023
* Implement depth supervision

* Fixes

* Change normalize dtype

* refactor

* Change depth weight

* Small refactor

* Change docstring

* Removu unused import

* Add assumption to depth comment

* Implement URF loss

* Remove default depth loss type param

* URF fixes

* Fix depth loss scale

* Visualize gt depths

* Fixes & documentation

* Documentation and formatting

* Fix formatting problems

* Fix linter problems

* Fix tests

* Fix tests
@YueYin27
Copy link

YueYin27 commented Apr 1, 2023

@mpmisko Hi, I was trying depth-nerfacto with my blender dataset, but it raises errors. Does depth-nerfacto only support the nerfstudio dataset? Thank you!

@tancik
Copy link
Contributor

tancik commented Apr 3, 2023

depth-nerfacto supports datasets with depth, ie nerfstudio, arkitscenes, scannet, sdfstudio

chris838 pushed a commit to chris838/nerfstudio that referenced this pull request Apr 22, 2023
* Implement depth supervision

* Fixes

* Change normalize dtype

* refactor

* Change depth weight

* Small refactor

* Change docstring

* Removu unused import

* Add assumption to depth comment

* Implement URF loss

* Remove default depth loss type param

* URF fixes

* Fix depth loss scale

* Visualize gt depths

* Fixes & documentation

* Documentation and formatting

* Fix formatting problems

* Fix linter problems

* Fix tests

* Fix tests
alexsax added a commit to alexsax/nerfstudio that referenced this pull request Aug 1, 2023
Depth supervision for `depth-nerfacto` was added in nerfstudio-project#1173. This patch extends that support to `sdfstudio` datasets ([as originally intended](nerfstudio-project#1173 (comment))) by adding `depth_unit_scale_factor` to `sdfstudio` metadata.
tancik pushed a commit that referenced this pull request Aug 1, 2023
Depth supervision for `depth-nerfacto` was added in #1173. This patch extends that support to `sdfstudio` datasets ([as originally intended](#1173 (comment))) by adding `depth_unit_scale_factor` to `sdfstudio` metadata.
@pushkalkatara
Copy link

Hi @mpmisko , Thanks for the amazing contribution.

Could you please provide the dataset/scene you used for evaluation?

In my case, I'm using a scene from Scannet:

depth loss increases, depth visualizations look okay, but not great.
holes seem to fill but the depth scale doesnt seem right. [bluish tint]

image

Unprojections: left [using nerf depth] , right [sensor depth]
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants