[Bug] Incorrect dimension index in loadCam prevents Alpha Mask from being loaded
Issue Description:
Describe the bug
The current implementation of Alpha Mask loading in utils/camera_utils.py uses an incorrect dimension index to check for the number of channels. It checks resized_image_rgb.shape[1] == 4, where shape[1] corresponds to the height of the image in PyTorch's (C, H, W) format, rather than the number of channels. As a result, the mask loading logic is never triggered unless the image height is exactly 4 pixels.
To Reproduce
- Prepare a dataset with 4-channel RGBA PNG images (with transparency).
- Run training with any script.
- Observe that the background (Alpha = 0 area) is still being trained/rendered, or add a print statement in
loadCamto check ifloaded_maskis ever assigned.
Code Snippet causing the issue:
In utils/camera_utils.py, line 39 (approx.):
# Current incorrect code
if resized_image_rgb.shape[1] == 4:
loaded_mask = resized_image_rgb[3:4, ...]
Expected behavior
The code should check shape[0] for the channel count, as PILtoTorch returns a tensor in (Channels, Height, Width) format.
Screenshots/Log (Optional)
If debugging, the tensor shape typically looks like: torch.Size([4, 1600, 1600]).
shape[0]is 4 (RGBA).shape[1]is 1600 (Height).
Proposed Fix
Change the index from 1 to 0:
# Fixed code
if resized_image_rgb.shape[0] == 4:
loaded_mask = resized_image_rgb[3:4, ...]
Environment:
- FastGS Version: Latest Main
- OS: Linux/Ubuntu (WSL)
- PyTorch Version: 1.12.1 (Standard for FastGS)
Hello! Thank you very much for your enthusiastic help! As you pointed out, resized_image_rgb.shape[1] corresponds to the image height, so this line of code does not affect our experiments, since none of the datasets we use contain images with a height of 4 pixels. In fact, this code was inherited from the original version of 3DGS (which you can obtain via this link). In the current version of 3DGS, the relevant code has been modified and the alpha_mask no longer affects the gt_image. I will update this part of the code in a future revision. Thanks again!