Skip to content

Commit

Permalink
Merge pull request isikdogan#4 from elbeejay/padfix-nanfix
Browse files Browse the repository at this point in the history
handle 0 padding and set nans/infty to 0
  • Loading branch information
isikdogan authored Jun 4, 2021
2 parents 333381a + c550aa4 commit f02bd76
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ def main(checkpoint_path, image_path, save_path):
pad_r = find_padding(image.shape[0])
pad_c = find_padding(image.shape[1])
image = np.pad(image, ((pad_r[0], pad_r[1]), (pad_c[0], pad_c[1]), (0, 0)), 'reflect')

# solve no-pad index issue after inference
if pad_r[1] == 0:
pad_r = (pad_r[0], 1)
if pad_c[1] == 0:
pad_c = (pad_c[0], 1)

image = image.astype(np.float32)

# remove nans (and infinity) - replace with 0s
image = np.nan_to_num(image, copy=False, nan=0.0, posinf=0.0, neginf=0.0)

image = image - np.min(image)
image = image / np.maximum(np.max(image), 1)

Expand Down

0 comments on commit f02bd76

Please sign in to comment.