Skip to content

[Bug] Inference tab renders normalized tensors without inverse normalization. #524

Description

@NANDA2726

The Inference tab in tabs/inference.py displays the normalized image tensor directly without applying inverse normalization before rendering:

img_to_draw = transforms.ToPILImage()(sample_tensor[0])

This causes the output image to appear with distorted, psychedelic colors instead of the original image, making the inference visualization incorrect and misleading. The image tensor should be de-normalized before display so the output image appears correctly with original colours.

Proposed Fix

Add a denormalize helper function in tabs/inference.py and apply it before rendering:

def denormalize(tensor, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]):
    mean = torch.tensor(mean).view(3, 1, 1)
    std = torch.tensor(std).view(3, 1, 1)
    return torch.clamp(tensor.cpu() * std + mean, 0, 1)

denormalized = denormalize(sample_tensor[0])
img_to_draw = transforms.ToPILImage()(denormalized)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions