Skip to main content

layer.log

log()

  • Parameters

    • data (Dict[str, Union[str, float, bool, int, pandas.DataFrame, PIL.Image.Image, matplotlib.figure.Figure, module, pathlib.Path]]) -- A dictionary in which each key is a string tag (i.e. name/id). The value can have different types. See examples below for more details.
    • step (Optional[int**]) -- An optional integer that associates data with a particular step (epoch). This only takes effect it the logged data is to be associated with a model train (and not with a dataset build) and the data is a number.
  • Returns

    None

  • Return type

    None

Logs arbitrary data associated with a model train or a dataset build into Layer backend.

This function can only be run inside functions decorated with @model or @dataset. The logged data can then be discovered and analyzed through the Layer UI.

We support Python primitives, images, tables and plots to enable better experiment tracking and version comparison.

Python Primitives

You can log Python primitive types for your model train parameters, metrics or KPIs

Accepted Types: str, float, bool, int

Images

You can log images to track inputs, outputs, detections, activations and more. We support JPEG and PNG formats.

Accepted Types: PIL.Image.Image, path.Path

Charts

You can track your metrics in detail with charts

Accepted Types: matplotlib.figure.Figure, matplotlib.pyplot, ModuleType (only for the matplotlib module, for convenience)

Tables

You can log dataframes to display and analyze your tabular data.

Accepted Types: pandas.DataFrame

import matplotlib.pyplot as plt
import pandas as pd
from layer
from layer.decorators import dataset, model

# Define a new function for dataset generation
@dataset("my_dataset_name")
def create_my_dataset():
data = [[1, "product1", 15], [2, "product2", 20], [3, "product3", 10]]
dataframe = pd.DataFrame(data, columns=["Id", "Product", "Price"])

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()

layer.log({
"my-str-tag": "any text",
"my-int-tag": 123, # any number
"foo-bool": True,
"some-sample-dataframe-tag": ..., # Pandas data frame
"some-local-image-file: Path.home() / "images/foo.png",
"some-matplot-lib-figure": fig, # You could alternatively just passed plt as well, and Layer would just get the current/active figure.
})

layer.log({
"another-tag": "you can call layer.log multiple times"
})

return dataframe

@model("my_model")
def create_my_model():
# everything that can be logged for a dataset (as shown above), can also be logged for a model too.

# In addition to those, if you have a multi-step (i.e. multi-epoch) algorithm, you can associate a metric with the step.
# These will be rendered on a graph inside the Layer UI.
for i in range(1000):
some_result, accuracy = some_algo(some_result)
layer.log({
"Model accuracy": accuracy,
}, step=i)

create_my_dataset()
create_my_model()