fix error with RealESRGAN model failing to upscale fp32 image

This commit is contained in:
AUTOMATIC1111 2023-12-30 22:41:53 +03:00
parent c2fd7c0344
commit 8100e901ab
1 changed files with 5 additions and 1 deletions

View File

@ -16,9 +16,13 @@ def upscale_without_tiling(model, img: Image.Image):
img = img[:, :, ::-1]
img = np.ascontiguousarray(np.transpose(img, (2, 0, 1))) / 255
img = torch.from_numpy(img).float()
img = img.unsqueeze(0).to(devices.device_esrgan)
model_weight = next(iter(model.parameters()))
img = img.unsqueeze(0).to(device=model_weight.device, dtype=model_weight.dtype)
with torch.no_grad():
output = model(img)
output = output.squeeze().float().cpu().clamp_(0, 1).numpy()
output = 255. * np.moveaxis(output, 0, 2)
output = output.astype(np.uint8)