a formula for bin size for images over 64x64 (#90)

Summary:
Signed-off-by: Michele Sanna <sanna@arrival.com>

fixes the bin_size calculation with a formula for any image_size > 64. Matches the values chosen so far.

simple test:

```
import numpy as np
import matplotlib.pyplot as plt

image_size = np.arange(64, 2048)
bin_size = np.where(image_size <= 64, 8, (2 ** np.maximum(np.ceil(np.log2(image_size)) - 4, 4)).astype(int))

print(image_size)
print(bin_size)

for ims, bins in zip(image_size, bin_size):
    if ims <= 64:
        assert bins == 8
    elif ims <= 256:
        assert bins == 16
    elif ims <= 512:
        assert bins == 32
    elif ims <= 1024:
        assert bins == 64
    elif ims <= 2048:
        assert bins == 128

    assert (ims + bins - 1) // bins < 22

plt.plot(image_size, bin_size)
plt.grid()
plt.show()
```

![img](https://user-images.githubusercontent.com/54891577/75464693-795bcf00-597f-11ea-9061-26440211691c.png)
Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/90

Reviewed By: jcjohnson

Differential Revision: D21160372

Pulled By: nikhilaravi

fbshipit-source-id: 660cf5832f4ca5be243c435a6bed969596fc0188
This commit is contained in:
Michele Sanna
2020-04-24 14:53:59 -07:00
committed by Facebook GitHub Bot
parent c3d636dc8c
commit f8acecb6b3
6 changed files with 52 additions and 7 deletions

View File

@@ -382,6 +382,13 @@ class TestRasterizeMeshes(TestCaseMixin, unittest.TestCase):
args = ()
self._compare_impls(fn1, fn2, args, args, verts1, verts2, compare_grads=True)
def test_bin_size_error(self):
meshes = ico_sphere(2)
image_size = 1024
bin_size = 16
with self.assertRaisesRegex(ValueError, "bin_size too small"):
rasterize_meshes(meshes, image_size, 0.0, 2, bin_size)
def _test_back_face_culling(self, rasterize_meshes_fn, device, bin_size):
# Square based pyramid mesh.
# fmt: off

View File

@@ -212,6 +212,13 @@ class TestRasterizePoints(TestCaseMixin, unittest.TestCase):
if compare_grads:
self.assertClose(grad_points1, grad_points2, atol=2e-6)
def test_bin_size_error(self):
points = Pointclouds(points=torch.rand(5, 100, 3))
image_size = 1024
bin_size = 16
with self.assertRaisesRegex(ValueError, "bin_size too small"):
rasterize_points(points, image_size, 0.0, 2, bin_size=bin_size)
def _test_behind_camera(self, rasterize_points_fn, device, bin_size=None):
# Test case where all points are behind the camera -- nothing should
# get rasterized