isl-org / DPT

Dense Prediction Transformers
MIT License
1.96k stars 254 forks source link

fix: overflow issue on write_depth function in utils/io.py #65

Closed ishtos closed 2 years ago

ishtos commented 2 years ago

Sometimes multiplication max_val and (depth - depth_min) causes overflow when bits=1 because of ndarray dtype np.float16. To deal with this issue, I changed the order of multiplication. (Or we can use np.float32) This change has small impact on the output value.

original = max_val * (depth - depth_min) / (depth_max - depth_min)
suggestion = (depth - depth_min) / (depth_max - depth_min) * max_val 
original != suggestion