ClementPinard / SfmLearner-Pytorch

Pytorch version of SfmLearner from Tinghui Zhou et al.
MIT License
1.01k stars 224 forks source link

imread during inference load the image as uint8 #142

Closed ZhenghaoFei closed 1 year ago

ZhenghaoFei commented 1 year ago

Hi Clement,

Thank you for your code and nice implementation!

I caught a small bug here. Using the downloaded pretrained model to run run_inference.py on resized (416*128) test data, I got bad disparity results.

image

Running inference of the same model on original image (full res) was totally fine.

The bug is clearly related to the imread() on line 58 and resize() on line 62 https://github.com/ClementPinard/SfmLearner-Pytorch/blob/master/run_inference.py, the imread() loads image as uint8 (0-255) and the resize will normalize the image pixel value into (0-1), thats why using the full res image was fine. But when the images are already resized, the resize() function will be skiped and uint8 image is going to feed in the net and get bad results.

I added img = img/255.0 after imread and fixed the problem.

image

I am not sure why this bug did not affect you and others (might due to my system environment?, python 3.88).

Best, Zhenghao

ZhenghaoFei commented 1 year ago

Related to #136 and #125

ClementPinard commented 1 year ago

Hello, you are right, there have been multiple issues related to image loading, resizing and normalizing for this script.

I think you are right in your assumption. Actually, the docs itself says that resize normalizes the image with skimaghe.util.img_as_float before actually resizing.

A very quick fix is then not to divide by 255, but simply call this function before anything else when the image is loaded.

I will push a fix for that, thanks for finding the bug that has been here for multiple years !

ClementPinard commented 1 year ago

If you confirm the fix works for you, I'll merge it and the bug will be fixed.

Thanks for you help !

ZhenghaoFei commented 1 year ago

Hi Clement,

I tested your fix of using:

 img = img_as_float(imread(file))

It works for me, thanks!