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
This commit is contained in:
Dave Greenwood 2020-02-24 13:42:02 -08:00 committed by Facebook Github Bot
parent 4233c32887
commit a0f3dc2d63
2 changed files with 11 additions and 2 deletions

View File

@ -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:

View File

@ -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))