| 226 | |
| 227 | |
| 228 | def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray: |
| 229 | if isinstance(arry, str): |
| 230 | # local_path = "/home/patrick_huggingface_co/" |
| 231 | if local_path is not None: |
| 232 | # local_path can be passed to correct images of tests |
| 233 | return os.path.join(local_path, "/".join([arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]])) |
| 234 | elif arry.startswith("http://") or arry.startswith("https://"): |
| 235 | response = requests.get(arry) |
| 236 | response.raise_for_status() |
| 237 | arry = np.load(BytesIO(response.content)) |
| 238 | elif os.path.isfile(arry): |
| 239 | arry = np.load(arry) |
| 240 | else: |
| 241 | raise ValueError( |
| 242 | f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path" |
| 243 | ) |
| 244 | elif isinstance(arry, np.ndarray): |
| 245 | pass |
| 246 | else: |
| 247 | raise ValueError( |
| 248 | "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a" |
| 249 | " ndarray." |
| 250 | ) |
| 251 | |
| 252 | return arry |
| 253 | |
| 254 | |
| 255 | def load_pt(url: str): |