mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-01-31 02:32:57 +08:00
torch_bgr_to_pil_image: round, don't truncate
This matches what `realesrgan` does.
This commit is contained in:
parent
7c3ab416ad
commit
7ad6899bf9
@ -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")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user