Spaces:
Running on Zero
Running on Zero
Download src/misc/LocalLogger.py from ACOM7/Just_For_PLC_Test: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/ACOM7/Just_For_PLC_Test/resolve/main/src/misc/LocalLogger.py
- Command line
-
hf download hf://spaces/ACOM7/Just_For_PLC_Test/src/misc/LocalLogger.py
-
curl -L -o LocalLogger.py https://huggingface.co/spaces/ACOM7/Just_For_PLC_Test/resolve/main/src/misc/LocalLogger.py
1.23 kB
| import os | |
| from pathlib import Path | |
| from typing import Any, Optional | |
| from lightning.pytorch.loggers.logger import Logger | |
| from lightning.pytorch.utilities import rank_zero_only | |
| from PIL import Image | |
| LOG_PATH = Path("outputs/local") | |
| class LocalLogger(Logger): | |
| def __init__(self) -> None: | |
| super().__init__() | |
| self.experiment = None | |
| os.system(f"rm -r {LOG_PATH}") | |
| def name(self): | |
| return "LocalLogger" | |
| def version(self): | |
| return 0 | |
| def log_hyperparams(self, params): | |
| pass | |
| def log_metrics(self, metrics, step): | |
| pass | |
| def log_image( | |
| self, | |
| key: str, | |
| images: list[Any], | |
| step: Optional[int] = None, | |
| **kwargs, | |
| ): | |
| # The function signature is the same as the wandb logger's, but the step is | |
| # actually required. | |
| assert step is not None | |
| for index, image in enumerate(images): | |
| path = LOG_PATH / f"{key}/{index:0>2}_{step:0>6}.jpg" | |
| path.parent.mkdir(exist_ok=True, parents=True) | |
| Image.fromarray(image).save(path) | |