Skip to main content



  • Parameters

    • data (Mapping[str, Union[str, float, bool, int, List[Any], np.ndarray[Any, Any], Dict[str, Any], pandas.DataFrame, PIL.Image.Image, matplotlib.figure.Figure, matplotlib.axes._subplots.AxesSubplot, Image, module, Path, Markdown]**]) -- 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 non-negative integer that associates data with a particular step (epoch). This only takes effect if the logged data is either a number, an image, or a video.
    • category (Optional[str**]) -- An optional string that associates data with a particular category. This category is used for grouping in the web UI.
    • group_tag (Optional[str**]) -- An optional string that helps group data in the web UI into a single chart.
  • Returns


  • Return type


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

List Types

These are converted into string and stored as text.

list np.ndarray (i.e. a normal NumPy array)


You can put markdown syntax and it will be rendered in the web UI accordingly.

Accepted Types: layer.Markdown


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

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


We support MP4, WebM, Ogg file formats or pytorch.Tensor (with BNTCHW+NTCHW shape) through layer.Video.

Accepted Types: path.Path layer.Video

Files and Directories

Directories and files (that do not have an image or video extension, as documented above) can also be logged.

If a directory is passed, it is compressed and logged as a single file.

Accepted Types: path.Path


You can track your metrics in detail with charts. Metrics logged with the same layer.log(...) call will be grouped and visualized together in the web UI.

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


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

Accepted Types: pandas.DataFrame dict (the key should be a string. The value either needs to be a primitive type or it will be converted to str)

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

# Define a new function for dataset generation
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()

"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 pass plt as well, and Layer would just get the current/active figure.

"another-tag": "you can call layer.log multiple times"

return dataframe

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)
"Model accuracy": accuracy,
}, step=i)