(arry: str | np.ndarray, local_path: str | None = None)
| 680 | |
| 681 | |
| 682 | def load_numpy(arry: str | np.ndarray, local_path: str | None = None) -> np.ndarray: |
| 683 | if isinstance(arry, str): |
| 684 | if local_path is not None: |
| 685 | # local_path can be passed to correct images of tests |
| 686 | return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix() |
| 687 | elif arry.startswith("http://") or arry.startswith("https://"): |
| 688 | response = requests.get(arry, timeout=DIFFUSERS_REQUEST_TIMEOUT) |
| 689 | response.raise_for_status() |
| 690 | arry = np.load(BytesIO(response.content)) |
| 691 | elif os.path.isfile(arry): |
| 692 | arry = np.load(arry) |
| 693 | else: |
| 694 | raise ValueError( |
| 695 | f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path" |
| 696 | ) |
| 697 | elif isinstance(arry, np.ndarray): |
| 698 | pass |
| 699 | else: |
| 700 | raise ValueError( |
| 701 | "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a" |
| 702 | " ndarray." |
| 703 | ) |
| 704 | |
| 705 | return arry |
| 706 | |
| 707 | |
| 708 | def load_pt(url: str, map_location: str | None = None, weights_only: bool | None = True): |
no test coverage detected
searching dependent graphs…