Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid [0,1] data range check seems failed without eps considered for float datatype #240

Open
ziyannchen opened this issue Jan 11, 2025 · 2 comments

Comments

@ziyannchen
Copy link

ziyannchen commented Jan 11, 2025

The error output

File "/root/anaconda3/envs/xxxx/lib/python3.8/site-packages/pyiqa/models/inference_model.py", line 79, in is_valid_input                                
    assert x.min() >= 0 and x.max() <= 1, f'Input must be normalized to [0, 1], but got min={x.min():.4f}, max={x.max():.4f}'                                
AssertionError: Input must be normalized to [0, 1], but got min=0.0000, max=1.0000

The source code

def is_valid_input(self, x):
        if x is not None:
            assert isinstance(x, torch.Tensor), 'Input must be a torch.Tensor'
            assert x.dim() == 4, 'Input must be 4D tensor (B, C, H, W)'
            assert x.shape[1] in [1, 3], 'Input must be RGB or gray image'
        
            if self.check_input_range:
                assert x.min() >= 0 and x.max() <= 1, f'Input must be normalized to [0, 1], but got min={x.min():.4f}, max={x.max():.4f}'

I checked the source code, it seems there is a problem when float datatype is given without eps considered.

@chaofengc
Copy link
Owner

Thank you so much for help. I will fix it in next update.

@chaofengc
Copy link
Owner

eps=1e-6 has been added to the range check code.

if self.check_input_range:
assert x.min() > -self.eps and x.max() < 1 + self.eps, f'Input must be normalized to [0, 1], but got min={x.min():.4f}, max={x.max():.4f}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants