Skip to content

Commit

Permalink
torch_bgr_to_pil_image: round, don't truncate
Browse files Browse the repository at this point in the history
This matches what `realesrgan` does.
  • Loading branch information
akx committed Jan 2, 2024
1 parent 7c3ab41 commit 7ad6899
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion modules/upscaler_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def torch_bgr_to_pil_image(tensor: torch.Tensor) -> Image.Image:
# TODO: is `tensor.float().cpu()...numpy()` the most efficient idiom?
arr = tensor.float().cpu().clamp_(0, 1).numpy() # clamp
arr = 255.0 * np.moveaxis(arr, 0, 2) # CHW to HWC, rescale
arr = arr.astype(np.uint8)
arr = arr.round().astype(np.uint8)
arr = arr[:, :, ::-1] # flip BGR to RGB
return Image.fromarray(arr, "RGB")

Expand Down

0 comments on commit 7ad6899

Please sign in to comment.