Skip to content

Commit

Permalink
Fixed step formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Nov 8, 2021
1 parent 1cb1883 commit 69beabc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dvclive/data/image_pil.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def output_path(self) -> Path:
f"Invalid image suffix '{Path(self.name).suffix}'"
f" Must be one of {self.suffixes}"
)
return self.output_folder / self.name
return self.output_folder / "{step}" / self.name

def dump(self, val, step) -> None:
super().dump(val, step)
Expand Down
19 changes: 8 additions & 11 deletions tests/test_data/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def test_PIL(tmp_dir):
img = Image.new("RGB", (500, 500), (250, 250, 250))
dvclive.log("image.png", img)

assert (tmp_dir / dvclive.dir / "image.png").exists()
assert (tmp_dir / dvclive.dir / "0" / "image.png").exists()
summary = _parse_json("dvclive.json")

assert summary["image.png"] == os.path.join(dvclive.dir, "image.png")
assert summary["image.png"] == os.path.join(dvclive.dir, "0", "image.png")


def test_invalid_extension(tmp_dir):
Expand All @@ -33,24 +33,21 @@ def test_numpy(tmp_dir, shape):
img = np.ones(shape, np.uint8) * 255
dvclive.log("image.png", img)

assert (tmp_dir / dvclive.dir / "image.png").exists()
assert (tmp_dir / dvclive.dir / "0" / "image.png").exists()


@pytest.mark.parametrize(
"pattern", ["image_{step}.png", str(os.path.join("{step}", "image.png"))]
)
def test_step_formatting(tmp_dir, pattern):
def test_step_formatting(tmp_dir):
dvclive = Live()
img = np.ones((500, 500, 3), np.uint8)
for _ in range(3):
dvclive.log(pattern, img)
dvclive.log("image.png", img)
dvclive.next_step()

for step in range(3):
assert (tmp_dir / dvclive.dir / pattern.format(step=step)).exists()
assert (tmp_dir / dvclive.dir / str(step) / "image.png").exists()

summary = _parse_json("dvclive.json")

assert summary[pattern] == os.path.join(
dvclive.dir, pattern.format(step=step)
assert summary["image.png"] == os.path.join(
dvclive.dir, str(step), "image.png"
)

0 comments on commit 69beabc

Please sign in to comment.