Add utility to inspect a model's parameters (to get dtype/device)

This commit is contained in:
Aarni Koskela
2023-12-31 00:20:30 +02:00
parent a84e842189
commit 5768afc776
8 changed files with 53 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import tqdm
from PIL import Image
from modules import images, shared
from modules.torch_utils import get_param
logger = logging.getLogger(__name__)
@@ -17,8 +18,8 @@ def upscale_without_tiling(model, img: Image.Image):
img = np.ascontiguousarray(np.transpose(img, (2, 0, 1))) / 255
img = torch.from_numpy(img).float()
model_weight = next(iter(model.model.parameters()))
img = img.unsqueeze(0).to(device=model_weight.device, dtype=model_weight.dtype)
param = get_param(model)
img = img.unsqueeze(0).to(device=param.device, dtype=param.dtype)
with torch.no_grad():
output = model(img)