photosynthesis-team / piq

Measures and metrics for image2image tasks. PyTorch.
Apache License 2.0
1.38k stars 116 forks source link

Problem with BRISQUE scores #353

Closed ercanburak closed 1 year ago

ercanburak commented 1 year ago

Bug Description The current implementation of BRISQUE seems erroneous. I encounter negative BRISQUE scores with my data. Upon inspection, I discovered that this behavior is due to #313. When I change the code to use F.interpolate instead of imresize (to revert the change from #313), I no longer encounter negative BRISQUE scores.

To Reproduce Here I share an example image and example codes to reproduce the issue.

img = cv2.imread("brisque_test_img.png", -1) # Read grayscale image img = img / 255.0 # Convert from 0-255 to 0-1 img_tensor = torch.tensor(img) # Convert to torch tensor img_tensor = torch.unsqueeze(img_tensor, 0) # Add third dimension (channel dimension) img_tensor = torch.unsqueeze(img_tensor, 0) # Add fourth dimension (batch dimension) score = brisque(img_tensor)

print("BRISQUE score for the image is {:.4f}".format(score))


- A minimal MATLAB code:
```matlab
img = imread('brisque_test_img.png');
score = brisque(img);
fprintf('BRISQUE score for the image is %0.4f.\n', score)

Here I share the outputs I got:

Expected behavior Generate non-negative BRISQUE scores, preferably the same scores as MATLAB.

zakajd commented 1 year ago

Thanks for finding this. @denproc can you take a look? I believe you were the one how implemented BRISQUE and #313

denproc commented 1 year ago

Hi @ercanburak and @zakajd, Thank you for the feedback, good catch! I was able to reproduce the bug. I'll let you know as I gather more information about his weird behaviour.

ercanburak commented 1 year ago

Hi @denproc, do you have any updates on this?

denproc commented 1 year ago

Hi @ercanburak,

Yep, I was just about to write what is going on. Let me first point out, that BRISQUE computes the NSS features, which are used to evaluate the final score by a pre-trained SVR model. While the computation of the NSS features is fixed and does not change across the implementation, the SVR model parameters may vary as one could retrain the SVR model (fitbrisque using built-in matlab function).

Currently, there are two matlab-based implementations, which produce different scores.

These two implementations use different SVR parameters

Considering your case, the original matlab code from the authors produces the same negative value estimated by PIQ implementation (see screenshot). It means that our code works as expected, delivering the same results as reported in the original work. However, I see a potential improvement here adding optional weights to be used for SVR, which allow a user to use custom model parameters and match other implementations if needed.

image

denproc commented 1 year ago

Hi @ercanburak,

After further inspection, we found out that the built-in MATLAB implementation has several dissimilarities compared to the original author's implementation. MATLAB's implementation:

As a result, supplying custom parameters for SVM is not enough to match the MATLAB implementation. While access to several implementations might be a sweet feature to have, we focus to deliver reliable implementations, which follow the original methods proposed by authors. Therefore, I'm closing this issue with this message for now. However, you are more than welcome to contribute to the package with a new enhancement issue and/or PR. Also, feel free to reopen the current issue in case of any new updates.

Cheers!

ercanburak commented 1 year ago

Hi @denproc, thank you very much for the detailed explanations!