(image_info, lhs, rhs, iter=None, sample_idx=None)
| 213 | |
| 214 | |
| 215 | def dump_as_core_artifacts(image_info, lhs, rhs, iter=None, sample_idx=None): |
| 216 | import_numpy() |
| 217 | import_pil() |
| 218 | |
| 219 | from pathlib import Path |
| 220 | |
| 221 | path = ( |
| 222 | "/opt/dali" |
| 223 | if os.path.exists("/opt/dali") and os.access("/opt/dali", os.W_OK) |
| 224 | else os.getcwd() |
| 225 | ) |
| 226 | Path(f"{path}/core_artifacts").mkdir(parents=True, exist_ok=True) |
| 227 | |
| 228 | image_info = image_info.replace("/", "_") |
| 229 | image_info = image_info.replace(" ", "_") |
| 230 | if iter is not None: |
| 231 | image_info = image_info + f"_iter{iter}" |
| 232 | if sample_idx is not None: |
| 233 | image_info = image_info + f"_sample_idx{sample_idx}" |
| 234 | |
| 235 | try: |
| 236 | save_image(lhs, f"{path}/core_artifacts/{image_info}.lhs.png") |
| 237 | save_image(rhs, f"{path}/core_artifacts/{image_info}.rhs.png") |
| 238 | except Exception as e: |
| 239 | print(f"Tried to save images but got an error: {e}") |
| 240 | |
| 241 | try: |
| 242 | # save arrays on artifact folder |
| 243 | import numpy as np |
| 244 | |
| 245 | np.save(f"{path}/core_artifacts/{image_info}.lhs.npy", lhs) |
| 246 | np.save(f"{path}/core_artifacts/{image_info}.rhs.npy", rhs) |
| 247 | except Exception as e: |
| 248 | print(f"Tried to save arrays but got an error: {e}") |
| 249 | |
| 250 | |
| 251 | # If the `max_allowed_error` is not None, it's checked instead of comparing mean error with `eps`. |
no test coverage detected