Skip to content

Unused sliced variables batch_dict_i and alpha_dict_i passed to obtain_depth in nbp.utils.py #9

Description

@YbjFJ

Hi there,

While reviewing the code in nbp.utils.py, I noticed a potential bug in the loop where depth maps are generated for the interpolated frames.

The code iterates through the batch and meticulously slices the tensors to create single-frame dictionaries (batch_dict_i and alpha_dict_i). However, when calling the obtain_depth() function inside the loop, the original full batches (batch_dict and alpha_dict) are passed as arguments instead of the sliced ones.

for i in range(batch_dict['images'].shape[0]):
    # Variables are properly sliced here
    batch_dict_i = {}
    batch_dict_i['images'] = batch_dict['images'][i:i + 1]
    # ... (other keys sliced) ...
    
    alpha_dict_i = {}
    alpha_dict_i['images'] = alpha_dict['images'][i:i + 1]
    # ... (other keys sliced) ...

    with torch.no_grad():
        # BUG: The full batch_dict and alpha_dict are passed instead of the _i variants
        depth_i, mask_i, error_mask_i, _, _ = obtain_depth(params=params,
                                                        batch_dict=batch_dict,  # <--- Should this be batch_dict_i?
                                                        alpha_dict=alpha_dict,  # <--- Should this be alpha_dict_i?
                                                        device=device,
                                                        use_perfect_depth=params.use_perfect_depth)

Expected Behavior:
It seems the intention was to process each frame individually within the loop. The function call should likely be:

        depth_i, mask_i, error_mask_i, _, _ = obtain_depth(params=params,
                                                        batch_dict=batch_dict_i,
                                                        alpha_dict=alpha_dict_i,
                                                        ...)

Potential Impact:
If left as is, this might lead to redundant computations (processing the entire batch multiple times in the loop) or cause tensor dimension mismatches when appending to the depth, mask, and error_mask lists later on.

Could you please confirm if this is a typo or if passing the full batch was intentional?

Thanks for your time and the great work on this project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions