-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce public
summary
. Remove "no step" / "step" logic from plot…
…s. (#331) It was initially introduced for supporting different logging format between step and not step updates. For `live.log_image`, "step" mode now overwrites the path instead of creating subfolder by step. For `live.log`, the "no step" was meant to not generate the `.tsv` file but only the `.json`. Added a public property `summary` so "no step" scenarios can work as follows: ``` live = Live() live.summary["foo"] = 1 live.make_summary() ``` Closes #326 Apply suggestions from code review Co-authored-by: Paweł Redzyński <[email protected]> Co-authored-by: Paweł Redzyński <[email protected]>
- Loading branch information
Showing
25 changed files
with
255 additions
and
377 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 3 additions & 9 deletions
12
src/dvclive/data/__init__.py → src/dvclive/plots/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
from .image import Image | ||
from .metric import Metric | ||
from .sklearn_plot import ( | ||
Calibration, | ||
ConfusionMatrix, | ||
Det, | ||
PrecisionRecall, | ||
Roc, | ||
) | ||
from .sklearn import Calibration, ConfusionMatrix, Det, PrecisionRecall, Roc | ||
from .utils import NumpyEncoder # noqa: F401 | ||
|
||
PLOTS = { | ||
SKLEARN_PLOTS = { | ||
"calibration": Calibration, | ||
"confusion_matrix": ConfusionMatrix, | ||
"det": Det, | ||
"precision_recall": PrecisionRecall, | ||
"roc": Roc, | ||
} | ||
DATA_TYPES = (*PLOTS.values(), Metric, Image) | ||
PLOT_TYPES = (*SKLEARN_PLOTS.values(), Metric, Image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import abc | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from dvclive.error import DataAlreadyLoggedError | ||
|
||
|
||
class Data(abc.ABC): | ||
def __init__(self, name: str, output_folder: str) -> None: | ||
self.name = name | ||
self.output_folder: Path = Path(output_folder) / self.subfolder | ||
self._step: Optional[int] = None | ||
|
||
@property | ||
def step(self) -> Optional[int]: | ||
return self._step | ||
|
||
@step.setter | ||
def step(self, val: int) -> None: | ||
if val == self._step: | ||
raise DataAlreadyLoggedError(self.name, val) | ||
self._step = val | ||
|
||
@property | ||
@abc.abstractmethod | ||
def output_path(self) -> Path: | ||
pass | ||
|
||
@property | ||
@abc.abstractmethod | ||
def subfolder(self): | ||
pass | ||
|
||
@staticmethod | ||
@abc.abstractmethod | ||
def could_log(val) -> bool: | ||
pass | ||
|
||
@abc.abstractmethod | ||
def dump(self, val, **kwargs): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pathlib import Path | ||
|
||
from .base import Data | ||
|
||
|
||
class Image(Data): | ||
suffixes = [".jpg", ".jpeg", ".gif", ".png"] | ||
subfolder = "images" | ||
|
||
@property | ||
def output_path(self) -> Path: | ||
_path = self.output_folder / self.name | ||
_path.parent.mkdir(exist_ok=True, parents=True) | ||
return _path | ||
|
||
@staticmethod | ||
def could_log(val: object) -> bool: | ||
if val.__class__.__module__ == "PIL.Image": | ||
return True | ||
if val.__class__.__module__ == "numpy": | ||
return True | ||
return False | ||
|
||
def dump(self, val, **kwargs) -> None: | ||
if val.__class__.__module__ == "numpy": | ||
from PIL import Image as ImagePIL | ||
|
||
pil_image = ImagePIL.fromarray(val) | ||
else: | ||
pil_image = val | ||
pil_image.save(self.output_path) |
Oops, something went wrong.