Apply transform on `batch` and `output`. If `batch` and `output` are dictionaries, temporarily combine them for the transform, otherwise, apply the transform for `output` data only.
(batch: Any, output: Any, transform: Callable[..., dict])
| 323 | |
| 324 | |
| 325 | def engine_apply_transform(batch: Any, output: Any, transform: Callable[..., dict]) -> tuple[Any, Any]: |
| 326 | """ |
| 327 | Apply transform on `batch` and `output`. |
| 328 | If `batch` and `output` are dictionaries, temporarily combine them for the transform, |
| 329 | otherwise, apply the transform for `output` data only. |
| 330 | |
| 331 | """ |
| 332 | if isinstance(batch, dict) and isinstance(output, dict): |
| 333 | data = dict(batch) |
| 334 | data.update(output) |
| 335 | transformed_data = apply_transform(transform, data) |
| 336 | |
| 337 | if not isinstance(transformed_data, dict): |
| 338 | raise AssertionError("With a dict supplied to apply_transform a single dict return is expected.") |
| 339 | |
| 340 | for k, v in transformed_data.items(): |
| 341 | # split the output data of post transforms into `output` and `batch`, |
| 342 | # `batch` should be read-only, so save the generated key-value into `output` |
| 343 | if k in output or k not in batch: |
| 344 | output[k] = v |
| 345 | else: |
| 346 | batch[k] = v |
| 347 | else: |
| 348 | output = apply_transform(transform, output) |
| 349 | |
| 350 | return batch, output |
| 351 | |
| 352 | |
| 353 | def default_metric_cmp_fn(current_metric: float, prev_best: float) -> bool: |
no test coverage detected
searching dependent graphs…