From a0f3dc2d63901b2363f633fd9fa82c08d9fb4855 Mon Sep 17 00:00:00 2001 From: Dave Greenwood Date: Mon, 24 Feb 2020 13:42:02 -0800 Subject: [PATCH] allow changes to background_color in BlendParams (#64) Summary: BlendParams background_color is immutable , type hint as a sequence allows setting new values in constructor. Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/64 Reviewed By: bottler Differential Revision: D20068911 Pulled By: nikhilaravi fbshipit-source-id: c580a7654dca25629218513841aa16d9d1055588 --- pytorch3d/renderer/blending.py | 4 ++-- tests/test_blending.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pytorch3d/renderer/blending.py b/pytorch3d/renderer/blending.py index 1816e767..0865547a 100644 --- a/pytorch3d/renderer/blending.py +++ b/pytorch3d/renderer/blending.py @@ -3,7 +3,7 @@ import numpy as np -from typing import NamedTuple +from typing import NamedTuple, Sequence import torch # Example functions for blending the top K colors per pixel using the outputs @@ -15,7 +15,7 @@ import torch class BlendParams(NamedTuple): sigma: float = 1e-4 gamma: float = 1e-4 - background_color = (1.0, 1.0, 1.0) + background_color: Sequence = (1.0, 1.0, 1.0) def hard_rgb_blend(colors, fragments) -> torch.Tensor: diff --git a/tests/test_blending.py b/tests/test_blending.py index 81f7516c..87efad60 100644 --- a/tests/test_blending.py +++ b/tests/test_blending.py @@ -234,3 +234,12 @@ class TestBlending(unittest.TestCase): self.assertTrue(torch.allclose(dists1.grad, dists2.grad, atol=2e-5)) self.assertTrue(torch.allclose(zbuf1.grad, zbuf2.grad, atol=2e-5)) + + def test_blend_params(self): + """Test colour parameter of BlendParams(). + Assert passed value overrides default value. + """ + bp_default = BlendParams() + bp_new = BlendParams(background_color=(0.5, 0.5, 0.5)) + self.assertEqual(bp_new.background_color, (0.5, 0.5, 0.5)) + self.assertEqual(bp_default.background_color, (1.0, 1.0, 1.0))