Closed samraul closed 9 months ago
I don't know what you are expecting. What is the artifact?
Can you paste an image of the mesh, e.g. with plotly_vis, so we can see what it is?
Thanks, @bottler.
Certainly, let me clarify:
Generated image | Computed mask | Expected mask |
---|---|---|
mask = np.any(
[np.all(generated_image == color[category], axis=-1) for category in [C1, C2, C2]],
axis=0,
)
Both these pixels should be [80, 40, 60] , however the one on the right shows [79, 39, 59] |
Good color | Bad color |
---|---|---|
It looks like a precision issue, perhaps converting from normalized color to uint8. But I have never observed this before despite having used it in different meshes.
Ah, it definitely looks like a precision issue. I removed all planes except one, expecting only 4 unique values (3 values + 0.0), however:
print(torch.unique(images))
print(torch.unique(images * 255))
as_np = images.cpu().squeeze().numpy()
print(np.unique(as_np))
print(np.unique(as_np * 255))
tensor([0.0000, 0.1569, 0.1569, 0.1569, 0.1569, 0.1569, 0.1569, 0.2353, 0.2353,
0.2353, 0.2353, 0.2353, 0.2353, 0.2353, 0.3137, 0.3137, 0.3137, 0.3137,
0.3137, 0.3137, 1.0000], device='cuda:0')
tensor([ 0.0000, 40.0000, 40.0000, 40.0000, 40.0000, 40.0000, 40.0000,
60.0000, 60.0000, 60.0000, 60.0000, 60.0000, 60.0000, 60.0000,
80.0000, 80.0000, 80.0000, 80.0000, 80.0000, 80.0000, 255.0000],
device='cuda:0')
[0. 0.15686272 0.15686274 0.15686275 0.15686277 0.15686278
0.1568628 0.23529409 0.2352941 0.23529412 0.23529413 0.23529415
0.23529416 0.23529418 0.31372544 0.31372547 0.3137255 0.31372553
0.31372556 0.3137256 1. ]
[ 0. 39.999992 39.999996 40. 40.000004 40.000008
40.00001 59.999992 59.999996 60. 60.000004 60.000008
60.00001 60.000015 79.999985 79.99999 80. 80.00001
80.000015 80.00002 255. ]
Adding a small epsilon before conversion solves the issue.
print("-" * 20)
print(torch.unique(images))
print(torch.unique(images * 255))
print("-" * 20)
epsilon = 0.0001
as_np = images.cpu().squeeze().numpy()
as_np_rounded_8 = np.round(as_np * 255 + epsilon).astype(np.uint8)
print(np.unique(as_np_rounded_8))
--------------------
tensor([0.0000, 0.1569, 0.1569, 0.1569, 0.1569, 0.1569, 0.1569, 0.2353, 0.2353,
0.2353, 0.2353, 0.2353, 0.2353, 0.2353, 0.3137, 0.3137, 0.3137, 0.3137,
0.3137, 0.3137, 1.0000], device='cuda:0')
tensor([ 0.0000, 40.0000, 40.0000, 40.0000, 40.0000, 40.0000, 40.0000,
60.0000, 60.0000, 60.0000, 60.0000, 60.0000, 60.0000, 60.0000,
80.0000, 80.0000, 80.0000, 80.0000, 80.0000, 80.0000, 255.0000],
device='cuda:0')
--------------------
[ 0 40 60 80 255]
If anyone has a better way, please let me know, otherwise we can close the issue, since this is just inherent to python type conversions.
I think you've got a solution as good as any.
👍 Will close and leave here in case someone runs into similar artifacts. Thank you, @bottler.
🐛 Bugs / Unexpected behaviors
I have color artifacts rendering with a fixed color shader.
UnlitColorShader
to render withhard_rgb_blend
which I have successfully used previously (no artifacts).blur_radius=0.00001
,bin_size=0
andfaces_per_pixel=1
, as responses in similar issues suggested, but the problem persists.(Images are with perspective camera. Code below with orthographic camera has the same issue).
Instructions To Reproduce the Issue:
Any changes you made (
git diff
) or code you wroteI have successfully used similar code with similar parameters before, so I am unsure what can cause the given artifacts. I am using
pytorch3d==0.7.3
.Any hints would be appreciated.
Thank you!