def test_cleanup(tmp_dir): dvclive = Live() img = np.ones((500, 500, 3), np.uint8) dvclive.log_image("image.png", img) assert (tmp_dir / dvclive.dir / LiveImage.subfolder / "image.png").exists() Live() assert not (tmp_dir / dvclive.dir / LiveImage.subfolder).exists()
def test_step_formatting(tmp_dir): dvclive = Live() img = np.ones((500, 500, 3), np.uint8) for _ in range(3): dvclive.log_image("image.png", img) dvclive.next_step() for step in range(3): assert (tmp_dir / dvclive.dir / LiveImage.subfolder / str(step) / "image.png").exists()
def test_step_rename(tmp_dir, mocker): from pathlib import Path rename = mocker.spy(Path, "rename") dvclive = Live() img = np.ones((500, 500, 3), np.uint8) dvclive.log_image("image.png", img) assert (tmp_dir / dvclive.dir / LiveImage.subfolder / "image.png").exists() dvclive.next_step() assert not (tmp_dir / dvclive.dir / LiveImage.subfolder / "image.png").exists() assert (tmp_dir / dvclive.dir / LiveImage.subfolder / "0" / "image.png").exists() rename.assert_called_once_with( Path(dvclive.dir) / LiveImage.subfolder / "image.png", Path(dvclive.dir) / LiveImage.subfolder / "0" / "image.png", )
def test_get_renderers(tmp_dir, mocker): live = Live() for i in range(2): live.log("foo", i) img = Image.new("RGB", (10, 10), (i, i, i)) live.log_image("image.png", img) live.next_step() live.set_step(None) live.log_plot("confusion_matrix", [0, 0, 1, 1], [1, 0, 0, 1]) image_renderers = get_image_renderers(tmp_dir / live.dir / LiveImage.subfolder) assert len(image_renderers) == 2 image_renderers = sorted(image_renderers, key=lambda x: x.datapoints[0]["rev"]) for n, renderer in enumerate(image_renderers): assert renderer.datapoints == [{ "src": mocker.ANY, "rev": os.path.join(str(n), "image.png") }] scalar_renderers = get_scalar_renderers(tmp_dir / live.dir / Scalar.subfolder) assert len(scalar_renderers) == 1 assert scalar_renderers[0].datapoints == [ { "foo": "0", "rev": "workspace", "step": "0", "timestamp": mocker.ANY }, { "foo": "1", "rev": "workspace", "step": "1", "timestamp": mocker.ANY }, ] plot_renderers = get_plot_renderers(tmp_dir / live.dir / Plot.subfolder) assert len(plot_renderers) == 1 assert plot_renderers[0].datapoints == [ { "actual": "0", "rev": "workspace", "predicted": "1" }, { "actual": "0", "rev": "workspace", "predicted": "0" }, { "actual": "1", "rev": "workspace", "predicted": "0" }, { "actual": "1", "rev": "workspace", "predicted": "1" }, ] assert plot_renderers[0].properties == ConfusionMatrix.get_properties()
def test_PIL(tmp_dir): dvclive = Live() img = Image.new("RGB", (500, 500), (250, 250, 250)) dvclive.log_image("image.png", img) assert (tmp_dir / dvclive.dir / LiveImage.subfolder / "image.png").exists()
def test_numpy(tmp_dir, shape): dvclive = Live() img = np.ones(shape, np.uint8) * 255 dvclive.log_image("image.png", img) assert (tmp_dir / dvclive.dir / LiveImage.subfolder / "image.png").exists()
def test_invalid_extension(tmp_dir): dvclive = Live() img = Image.new("RGB", (500, 500), (250, 250, 250)) with pytest.raises(ValueError): dvclive.log_image("image.foo", img)