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

Unsigned Overflow in Python kernelP() #15

Open
Arya-Fgmain opened this issue Aug 6, 2024 · 0 comments
Open

Unsigned Overflow in Python kernelP() #15

Arya-Fgmain opened this issue Aug 6, 2024 · 0 comments

Comments

@Arya-Fgmain
Copy link

Hi there!

For starters, thank you & congratulations for your amazing work on this paper. It is incredibly insightful and helpful.

I found an issue in one of the scripts, utils.kernelP(), where the input image tensor has dtype np.uint8. The feature transformations in this function lead to unsigned overflow, especially the last 8 elements of each transformed data point (excluding the 1 at the end). The reason for this is mentioned in this page in the NumPy docs, which mentions that their numerical types are fixed-width. Below are the first pixels of 00-02.JPG before & after feature transformation, with their respective dtypes:

With Overflow:

(00.JPG) [ 66 25 131] uint8 , [ 66 25 131 114 198 203 4 113 9 86 1] int64
(01.JPG) [139 188 246] uint8 , [139 188 246 20 146 168 121 16 100 56 1] int64
(02.JPG) [215 252 254] uint8 , [215 252 254 164 82 8 145 16 4 184 1] int64

Without Overflow:

(00.JPG) [ 66 25 131] int64 , [ 66 25 131 1650 8646 3275 4356 625 17161 216150 1] int64
(01.JPG) [139 188 246] int64 , [ 139 188 246 26132 34194 46248 19321 35344 60516 6428472 1] int64
(02.JPG) [215 252 254] int64 , [ 215 252 254 54180 54610 64008 46225 63504 64516 13761720 1] int64

To fix the overflow issue, I added I = I.astype(np.int64) to the function.

I compared the output on the example_images directory with & without overflow. Find a summary of the respective MSE & MAE measures, as well as their averages, below. These metrics are to show how different the values are with and without overflow.

(MSE, MAE) for 00_AWB.png: (36.63265609741211, 4.617997646331787)
(MSE, MAE) for 00_T.png: (27.950292587280273, 4.0814528465271)
(MSE, MAE) for 00_S.png: (54.84620666503906, 5.604139804840088)
(MSE, MAE) for 01_AWB.png: (34.73400115966797, 4.047080039978027)
(MSE, MAE) for 01_T.png: (1.7762006521224976, 0.9251388907432556)
(MSE, MAE) for 01_S.png: (34.41278076171875, 4.021535396575928)
(MSE, MAE) for 02_AWB.png: (34.76441192626953, 4.017171382904053)
(MSE, MAE) for 02_T.png: (34.98468780517578, 3.8246243000030518)
(MSE, MAE) for 02_S.png: (32.551353454589844, 3.45462703704834)
(MSE, MAE) for 03_AWB.png: (6.443303108215332, 1.6022756099700928)
(MSE, MAE) for 03_T.png: (25.568115234375, 3.4743590354919434)
(MSE, MAE) for 03_S.png: (8.789534568786621, 1.9237173795700073)
(MSE, MAE) for 04_AWB.png: (19.582639694213867, 2.3370769023895264)
(MSE, MAE) for 04_T.png: (93.58589935302734, 5.58164119720459)
(MSE, MAE) for 04_S.png: (75.77192687988281, 4.169919013977051)
(MSE, MAE) for 05_AWB.png: (12.317625045776367, 2.122532606124878)
(MSE, MAE) for 05_T.png: (15.938911437988281, 2.534762382507324)
(MSE, MAE) for 05_S.png: (19.560606002807617, 2.326895236968994)
(MSE, MAE) for 06_AWB.png: (80.50083923339844, 6.207443714141846)
(MSE, MAE) for 06_T.png: (69.91217041015625, 6.178401470184326)
(MSE, MAE) for 06_S.png: (82.06550598144531, 6.34844446182251)
(MSE, MAE) for 07_AWB.png: (44.33774948120117, 4.364473342895508)
(MSE, MAE) for 07_T.png: (1.0995233058929443, 0.6863966584205627)
(MSE, MAE) for 07_S.png: (52.520164489746094, 4.696540832519531)
(MSE, MAE) for 08_AWB.png: (8.38996696472168, 1.8781654834747314)
(MSE, MAE) for 08_T.png: (11.96456241607666, 2.202268362045288)
(MSE, MAE) for 08_S.png: (27.575592041015625, 3.3244056701660156)
(MSE, MAE) for 09_AWB.png: (19.39771270751953, 2.680612564086914)
(MSE, MAE) for 09_T.png: (38.685218811035156, 3.597625732421875)
(MSE, MAE) for 09_S.png: (32.00599670410156, 3.630540132522583)
(MSE, MAE) for 10_AWB.png: (8.063882827758789, 1.7296009063720703)
(MSE, MAE) for 10_T.png: (13.180949211120605, 2.331162929534912)
(MSE, MAE) for 10_S.png: (10.85296630859375, 1.9405498504638672)
(MSE, MAE) for 11_AWB.png: (3.2594854831695557, 1.08352792263031)
(MSE, MAE) for 11_T.png: (98.14730834960938, 6.926990509033203)
(MSE, MAE) for 11_S.png: (9.633447647094727, 2.008676052093506)
(MSE, MAE) for 12_AWB.png: (4.093111515045166, 1.3582937717437744)
(MSE, MAE) for 12_T.png: (7.315742492675781, 1.7758421897888184)
(MSE, MAE) for 12_S.png: (7.722217559814453, 1.7602105140686035)

Mean MSE: 30.79321196
Mean MAE: 3.26607999

Please let me know what you think! I'd love to hear your POV.

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

1 participant