(arry: Union[str, np.ndarray], local_path: Optional[str] = None)
| 334 | |
| 335 | |
| 336 | def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray: |
| 337 | if isinstance(arry, str): |
| 338 | if local_path is not None: |
| 339 | # local_path can be passed to correct images of tests |
| 340 | return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix() |
| 341 | elif arry.startswith("http://") or arry.startswith("https://"): |
| 342 | response = requests.get(arry) |
| 343 | response.raise_for_status() |
| 344 | arry = np.load(BytesIO(response.content)) |
| 345 | elif os.path.isfile(arry): |
| 346 | arry = np.load(arry) |
| 347 | else: |
| 348 | raise ValueError( |
| 349 | f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path" |
| 350 | ) |
| 351 | elif isinstance(arry, np.ndarray): |
| 352 | pass |
| 353 | else: |
| 354 | raise ValueError( |
| 355 | "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a" |
| 356 | " ndarray." |
| 357 | ) |
| 358 | |
| 359 | return arry |
| 360 | |
| 361 | |
| 362 | def load_pt(url: str): |
no test coverage detected