MCPcopy Create free account
hub / github.com/IceClear/StableSR / _img2tensor

Function _img2tensor

scripts/util_image.py:288–295  ·  view source on GitHub ↗
(img)

Source from the content-addressed store, hash-verified

286 """
287
288 def _img2tensor(img):
289 if img.ndim == 2:
290 tensor = torch.from_numpy(img[None, None,]).type(out_type)
291 elif img.ndim == 3:
292 tensor = torch.from_numpy(rearrange(img, 'h w c -> c h w')).type(out_type).unsqueeze(0)
293 else:
294 raise TypeError(f'2D or 3D numpy array expected, got{img.ndim}D array')
295 return tensor
296
297 if not (isinstance(imgs, np.ndarray) or (isinstance(imgs, list) and all(isinstance(t, np.ndarray) for t in imgs))):
298 raise TypeError(f'Numpy array or list of numpy array expected, got {type(imgs)}')

Callers 1

img2tensorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected