JdeRobot / JdeRobot/PerceptionMetrics

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

Open
#524 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
112
Forks
109
PR merge metrics
No merged PRs in 30d

Description

The Inference tab in `tabs/inference.py` displays the normalized image tensor directly without applying inverse normalization before rendering:
```python
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:
```python
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)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.