Commit 9c6ea538 authored by AUTOMATIC1111's avatar AUTOMATIC1111 Committed by GitHub

Merge pull request #14504 from akx/you-spin-me-round

torch_bgr_to_pil_image: round, don't truncate
parents e4dcdcc9 7ad6899b
...@@ -30,7 +30,7 @@ def torch_bgr_to_pil_image(tensor: torch.Tensor) -> Image.Image: ...@@ -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? # TODO: is `tensor.float().cpu()...numpy()` the most efficient idiom?
arr = tensor.float().cpu().clamp_(0, 1).numpy() # clamp arr = tensor.float().cpu().clamp_(0, 1).numpy() # clamp
arr = 255.0 * np.moveaxis(arr, 0, 2) # CHW to HWC, rescale 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 arr = arr[:, :, ::-1] # flip BGR to RGB
return Image.fromarray(arr, "RGB") return Image.fromarray(arr, "RGB")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment