MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / load_numpy

Function load_numpy

diffusers/src/diffusers/utils/testing_utils.py:434–457  ·  view source on GitHub ↗
(arry: Union[str, np.ndarray], local_path: Optional[str] = None)

Source from the content-addressed store, hash-verified

432
433
434def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray:
435 if isinstance(arry, str):
436 if local_path is not None:
437 # local_path can be passed to correct images of tests
438 return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix()
439 elif arry.startswith("http://") or arry.startswith("https://"):
440 response = requests.get(arry)
441 response.raise_for_status()
442 arry = np.load(BytesIO(response.content))
443 elif os.path.isfile(arry):
444 arry = np.load(arry)
445 else:
446 raise ValueError(
447 f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path"
448 )
449 elif isinstance(arry, np.ndarray):
450 pass
451 else:
452 raise ValueError(
453 "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a"
454 " ndarray."
455 )
456
457 return arry
458
459
460def load_pt(url: str):

Calls 1

loadMethod · 0.45

Tested by

no test coverage detected