I put the op into the for loop, and it does have problem. I used the following code
import torch
import numpy as np
from operate import check_isfinite


def main():
    while True:
        in_img = torch.randint(0, 255, [512, 512, 3])
        output = cv2.resize(np.asarray(in_img, dtype=np.float), (256, 256), interpolation=cv2.INTER_LINEAR)
        output = torch.from_numpy(output)
        max_output = torch.max(output)
        check_isfinite("max_output", max_output)
        assert torch.isfinite(max_output)


if __name__ == "__main__":
    main()


I also found that the error occurs randomly enen though I add torch.random.manual_seed(0). It’s so strange
and the part of the output is:
params name: max_output, is_finite: True
tensor(247.5000, dtype=torch.float64)
params name: max_output, is_finite: True
tensor(245., dtype=torch.float64)
params name: max_output, is_finite: True
tensor(inf, dtype=torch.float64)
params name: max_output, is_finite: False
Traceback (most recent call last):
File “/home/jhyan/Scripts/PYTHON_PROJECT/FPN/test_opencv.py”, line 17, in 
main()
File “/home/jhyan/Scripts/PYTHON_PROJECT/FPN/test_opencv.py”, line 13, in main
assert torch.isfinite(max_output)
AssertionError