From 0d805e3ed7607231eed3140fff02dce8eb24a63a Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Mon, 11 Dec 2023 10:22:53 -0500 Subject: [PATCH] fix tensor conversion --- CHANGELOG.md | 1 + modules/processing.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36f49e282..d0487a719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ - improve handling of long filenames and filenames during batch processing - do not set preview samples when using via api - avoid unnecessary resizes in img2img and inpaint + - updated `cli/simple-txt2img.py` and `cli/simple-img2img.py` scripts - update built-in log monitor in ui, thanks @midcoastal ## Update for 2023-12-04 diff --git a/modules/processing.py b/modules/processing.py index 4b1965386..65982615c 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -757,7 +757,13 @@ def validate_sample(tensor): return tensor if tensor.dtype == torch.bfloat16: # numpy does not support bf16 tensor = tensor.to(torch.float16) - sample = tensor.detach().cpu().numpy() if isinstance(tensor, torch.Tensor) and hasattr(tensor, 'detach') else tensor.cpu().numpy() + print('HERE', isinstance(tensor, np.ndarray), isinstance(tensor, torch.Tensor)) + if isinstance(tensor, torch.Tensor) and hasattr(tensor, 'detach'): + sample = tensor.detach().cpu().numpy() + elif isinstance(tensor, np.ndarray): + sample = tensor + else: + shared.log.warning(f'Unknown sample type: {type(tensor)}') sample = 255.0 * np.moveaxis(sample, 0, 2) if shared.backend == shared.Backend.ORIGINAL else 255.0 * sample with warnings.catch_warnings(record=True) as w: cast = sample.astype(np.uint8)