This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Data Types

This module defines Data Types for logging interactive visualizations to W&B. Data types include common media types, like images, audio, and videos, flexible containers for information, like tables and HTML, and more. All of these special data types are subclasses of WBValue. All the data types serialize to JSON, since that is what wandb uses to save the objects locally and upload them to the W&B server.

For more on logging media, see our guide. For more on logging structured data for interactive dataset and model analysis, see to W&B Tables.

1 - Audio

class Audio

W&B class for audio clips.

Attributes:

  • data_or_path (string or numpy array): A path to an audio file or a numpy array of audio data.
  • sample_rate (int): Sample rate, required when passing in raw numpy array of audio data.
  • caption (string): Caption to display with audio.

method Audio.__init__

__init__(data_or_path, sample_rate=None, caption=None)

Accept a path to an audio file or a numpy array of audio data.


2 - box3d

function box3d

box3d(
    center: 'npt.ArrayLike',
    size: 'npt.ArrayLike',
    orientation: 'npt.ArrayLike',
    color: 'RGBColor',
    label: 'Optional[str]' = None,
    score: 'Optional[numeric]' = None
)  Box3D

Returns a Box3D.

Args:

  • center: The center point of the box as a length-3 ndarray.
  • size: The box’s X, Y and Z dimensions as a length-3 ndarray.
  • orientation: The rotation transforming global XYZ coordinates into the box’s local XYZ coordinates, given as a length-4 ndarray [r, x, y, z] corresponding to the non-zero quaternion r + xi + yj + zk.
  • color: The box’s color as an (r, g, b) tuple with 0 <= r,g,b <= 1.
  • label: An optional label for the box.
  • score: An optional score for the box.

3 - Graph

class Graph

W&B class for graphs.

This class is typically used for saving and displaying neural net models. It represents the graph as an array of nodes and edges. The nodes can have labels that can be visualized by wandb.

Attributes:

  • format (string): Format to help wandb display the graph nicely.
  • nodes ([wandb.Node]): List of wandb.Nodes.
  • nodes_by_id (dict): dict of ids -> nodes
  • edges ([(wandb.Node, wandb.Node)]): List of pairs of nodes interpreted as edges.
  • loaded (boolean): Flag to tell whether the graph is completely loaded.
  • root (wandb.Node): Root node of the graph.

Examples: Import a keras model.

import wandb

wandb.Graph.from_keras(keras_model)

method Graph.__init__

__init__(format='keras')

4 - Histogram

class Histogram

W&B class for histograms.

This object works just like numpy’s histogram function https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html

Args:

  • sequence: Input data for histogram.
  • np_histogram: Alternative input of a precomputed histogram.
  • num_bins: Number of bins for the histogram. The default number of bins is 64. The maximum number of bins is 512.

Attributes:

  • bins ([float]): Edges of bins
  • histogram ([int]): Number of elements falling in each bin.

Examples: Generate histogram from a sequence.

import wandb

wandb.Histogram([1, 2, 3])

Efficiently initialize from np.histogram.

import numpy as np
import wandb

hist = np.histogram(data)
wandb.Histogram(np_histogram=hist)

method Histogram.__init__

__init__(
    sequence: Optional[Sequence] = None,
    np_histogram: Optional[ForwardRef('NumpyHistogram')] = None,
    num_bins: int = 64
)  None

5 - Html

class Html

W&B class for arbitrary html.

Args:

  • data: HTML to display in wandb
  • inject: Add a stylesheet to the HTML object. If set to False the HTML will pass through unchanged.

method Html.__init__

__init__(data: Union[str, ForwardRef('TextIO')], inject: bool = True)  None

6 - Image

class Image

Format images for logging to W&B.

See https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes for more information on modes.

Args:

  • data_or_path: Accepts numpy array of image data, or a PIL image. The class attempts to infer the data format and converts it.
  • mode: The PIL mode for an image. Most common are “L”, “RGB”, “RGBA”.
  • caption: Label for display of image.

When logging a torch.Tensor as a wandb.Image, images are normalized. If you do not want to normalize your images, convert your tensors to a PIL Image.

Examples:

# Create a wandb.Image from a numpy array
import numpy as np
import wandb

with wandb.init() as run:
   examples = []
   for i in range(3):
        pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
        image = wandb.Image(pixels, caption=f"random field {i}")
        examples.append(image)
   run.log({"examples": examples})
# Create a wandb.Image from a PILImage
import numpy as np
from PIL import Image as PILImage
import wandb

with wandb.init() as run:
    examples = []
    for i in range(3):
         pixels = np.random.randint(
             low=0, high=256, size=(100, 100, 3), dtype=np.uint8
         )
         pil_image = PILImage.fromarray(pixels, mode="RGB")
         image = wandb.Image(pil_image, caption=f"random field {i}")
         examples.append(image)
    run.log({"examples": examples})
# log .jpg rather than .png (default)
import numpy as np
import wandb

with wandb.init() as run:
    examples = []
    for i in range(3):
         pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
         image = wandb.Image(pixels, caption=f"random field {i}", file_type="jpg")
         examples.append(image)
    run.log({"examples": examples})

method Image.__init__

__init__(
    data_or_path: 'ImageDataOrPathType',
    mode: Optional[str] = None,
    caption: Optional[str] = None,
    grouping: Optional[int] = None,
    classes: Optional[ForwardRef('Classes'), Sequence[dict]] = None,
    boxes: Optional[Dict[str, ForwardRef('BoundingBoxes2D')], Dict[str, dict]] = None,
    masks: Optional[Dict[str, ForwardRef('ImageMask')], Dict[str, dict]] = None,
    file_type: Optional[str] = None
)  None

7 - Molecule

class Molecule

W&B class for 3D Molecular data.

Args:

  • data_or_path: Molecule can be initialized from a file name or an io object.
  • caption: Caption associated with the molecule for display.

method Molecule.__init__

__init__(
    data_or_path: Union[str, ForwardRef('TextIO')],
    caption: Optional[str] = None,
    **kwargs: str
)  None

8 - Object3D

class Object3D

W&B class for 3D point clouds.

Args:

  • data_or_path: Object3D can be initialized from a file or a NumPy array. You can pass a path to a file or an io object and a file_type which must be one of SUPPORTED_TYPES.

Examples: The shape of the numpy array must be one of either

[[x y z],       ...] nx3
[[x y z c],     ...] nx4 where c is a category with supported range [1, 14]
[[x y z r g b], ...] nx6 where is rgb is color

method Object3D.__init__

__init__(
    data_or_path: Union[ForwardRef('np.ndarray'), str, ForwardRef('TextIO'), dict],
    **kwargs: Optional[str, ForwardRef('FileFormat3D')]
)  None

9 - Plotly

class Plotly

W&B class for Plotly plots.

Args:

  • val: Matplotlib or Plotly figure.

method Plotly.__init__

__init__(
    val: Union[ForwardRef('plotly.Figure'), ForwardRef('matplotlib.artist.Artist')]
)

classmethod Plotly.get_media_subdir

get_media_subdir()  str

classmethod Plotly.make_plot_media

make_plot_media(
    val: Union[ForwardRef('plotly.Figure'), ForwardRef('matplotlib.artist.Artist')]
)  Union[wandb.sdk.data_types.image.Image, ForwardRef('Plotly')]

method Plotly.to_json

to_json(
    run_or_artifact: Union[ForwardRef('LocalRun'), ForwardRef('Artifact')]
)  dict

10 - Table

class Table

The Table class used to display and analyze tabular data.

Unlike traditional spreadsheets, Tables support numerous types of data: scalar values, strings, numpy arrays, and most subclasses of wandb.data_types.Media. This means you can embed Images, Video, Audio, and other sorts of rich, annotated media directly in Tables, alongside other traditional scalar values.

This class is the primary class used to generate the Table Visualizer in the UI: https://docs.wandb.ai/guides/data-vis/tables.

Attributes:

  • columns (List[str]): Names of the columns in the table. Defaults to [“Input”, “Output”, “Expected”].
  • data: (List[List[any]]) 2D row-oriented array of values.
  • dataframe (pandas.DataFrame): DataFrame object used to create the table. When set, data and columns arguments are ignored.
  • optional (Union[bool,List[bool]]): Determines if None values are allowed. Default to True. - If a singular bool value, then the optionality is enforced for all columns specified at construction time. - If a list of bool values, then the optionality is applied to each column - should be the same length as columns. applies to all columns. A list of bool values applies to each respective column.
  • allow_mixed_types (bool): Determines if columns are allowed to have mixed types (disables type validation). Defaults to False.

method Table.__init__

__init__(
    columns=None,
    data=None,
    rows=None,
    dataframe=None,
    dtype=None,
    optional=True,
    allow_mixed_types=False
)

Initializes a Table object.

The rows is available for legacy reasons and should not be used. The Table class uses data to mimic the Pandas API.


method Table.add_column

add_column(name, data, optional=False)

Adds a column of data to the table.

Args:

  • name: (str) - the unique name of the column
  • data: (list | np.array) - a column of homogeneous data
  • optional: (bool) - if null-like values are permitted

method Table.add_computed_columns

add_computed_columns(fn)

Adds one or more computed columns based on existing data.

Args:

  • fn: A function which accepts one or two parameters, ndx (int) and row (dict), which is expected to return a dict representing new columns for that row, keyed by the new column names.

ndx is an integer representing the index of the row. Only included if include_ndx is set to True.

row is a dictionary keyed by existing columns


method Table.add_data

add_data(*data)

Adds a new row of data to the table.

The maximum amount ofrows in a table is determined by wandb.Table.MAX_ARTIFACT_ROWS.

The length of the data should match the length of the table column.


method Table.add_row

add_row(*row)

Deprecated; use add_data instead.


method Table.cast

cast(col_name, dtype, optional=False)

Casts a column to a specific data type.

This can be one of the normal python classes, an internal W&B type, or an example object, like an instance of wandb.Image or wandb.Classes.

Args:

  • col_name (str): The name of the column to cast.
  • dtype (class, wandb.wandb_sdk.interface._dtypes.Type, any): The target dtype.
  • optional (bool): If the column should allow Nones.

method Table.get_column

get_column(name, convert_to=None)

Retrieves a column from the table and optionally converts it to a NumPy object.

Args:

  • name: (str) - the name of the column
  • convert_to: (str, optional) - “numpy”: will convert the underlying data to numpy object

method Table.get_dataframe

get_dataframe()

Returns a pandas.DataFrame of the table.


method Table.get_index

get_index()

Returns an array of row indexes for use in other tables to create links.


11 - Video

class Video

Format a video for logging to W&B.

Args:

  • data_or_path: Video can be initialized with a path to a file or an io object. The format must be “gif”, “mp4”, “webm” or “ogg”. The format must be specified with the format argument. Video can be initialized with a numpy tensor. The numpy tensor must be either 4 dimensional or 5 dimensional. Channels should be (time, channel, height, width) or (batch, time, channel, height width)
  • caption: Caption associated with the video for display.
  • fps: The frame rate to use when encoding raw video frames. Default value is 4. This parameter has no effect when data_or_path is a string, or bytes.
  • format: Format of video, necessary if initializing with path or io object.

Examples:

Log a numpy array as a video

import numpy as np
import wandb

run = wandb.init()
# axes are (time, channel, height, width)
frames = np.random.randint(low=0, high=256, size=(10, 3, 100, 100), dtype=np.uint8)
run.log({"video": wandb.Video(frames, fps=4)})

method Video.__init__

__init__(
    data_or_path: Union[ForwardRef('np.ndarray'), str, ForwardRef('TextIO'), ForwardRef('BytesIO')],
    caption: Optional[str] = None,
    fps: Optional[int] = None,
    format: Optional[str] = None
)