Documentation
Search…
Log Tables
Use wandb.Table to log data to visualize and query with W&B. In this guide, learn how to:
  1. 2.
    Add Data
  2. 4.

Create Tables

To define a Table, specify the columns you want to see for each row of data. Each row might be a single item in your training dataset, a particular step or epoch during training, a prediction made by your model on a test item, an object generated by your model, etc. Each column has a fixed type: numeric, text, boolean, image, video, audio, etc. You don't need to specify the type in advance—simply give each column a name, and make sure to only pass data of that type into that column index. For a more detailed example, see this report.
Use the wandb.Table constructor in one of two ways:
  1. 1.
    List of Rows: Log named columns and rows of data. For example: wandb.Table(columns=["a", "b", "c"], data=[["1a", "1b", "1c"], ["2a", "2b", "2c"]]) generates a table with two rows and three columns.
  2. 2.
    Pandas DataFrame: Log a DataFrame using wandb.Table(dataframe=my_df). Column names will be extracted from the DataFrame.

From an existing array or dataframe

1
# assume a model has returned predictions on four images
2
# with the following fields available:
3
# - the image id
4
# - the image pixels, wrapped in a wandb.Image()
5
# - the model's predicted label
6
# - the ground truth label
7
my_data = [
8
[0, wandb.Image("img_0.jpg"), 0, 0],
9
[1, wandb.Image("img_1.jpg"), 8, 0],
10
[2, wandb.Image("img_2.jpg"), 7, 1],
11
[3, wandb.Image("img_3.jpg"), 1, 1]
12
]
13
14
# create a wandb.Table() with corresponding columns
15
columns=["id", "image", "prediction", "truth"]
16
test_table = wandb.Table(data=my_data, columns=columns)
Copied!

Add Data

Tables are mutable, and as your script executes you can add more data to your table, up to 200,000 rows. There are two ways to add data to a table:
  1. 1.
    Add a Row: table.add_data("3a", "3b", "3c") . Note that the new row is not represented as a list. If your row is in list format, use star notation to expand the list to positional arguments: table.add_data(*my_row_list) . The row must contain the same number of entries as there are columns in the table.
  2. 2.
    Add a Column: table.add_column(name="col_name", data=col_data). Note that the length of col_data must be equal to the table's current number of rows. Here, col_data can be a list data, or a Numpy NDArray.

Adding data incrementally

1
# create a Table with the same columns as above,
2
# plus confidence scores for all labels
3
columns=["id", "image", "guess", "truth"]
4
for digit in range(10):
5
columns.append("score_" + str(digit))
6
test_table = wandb.Table(columns=columns)
7
8
# run inference on every image, assuming my_model returns the
9
# predicted label, and the ground truth labels are available
10
for img_id, img in enumerate(mnist_test_data):
11
true_label = mnist_test_data_labels[img_id]
12
guess_label = my_model.predict(img)
13
test_table.add_data(img_id, wandb.Image(img), \
14
guess_label, true_label)
Copied!

Retrieve Data

Once data is in a Table, access it by column or by row:
  1. 1.
    Row Iterator: Users can use the row iterator of Table such as for ndx, row in table.iterrows(): ... to efficiently iterate over the data's rows.
  2. 2.
    Get a Column: Users can retrieve a column of data using table.get_column("col_name") . As a convenience, users can pass convert_to="numpy" to convert the column to a Numpy NDArray of primitives. This is useful if your column contains media types such as wandb.Image so that you can access the underlying data directly.

Save Tables

After you generate a table of data in your script, for example a table of model predictions, save it to W&B to visualize the results live. If you'd like to save and version larger datasets check out Artifact Tables.

Log a table to a run

Use wandb.log() to save your table to the run, like so:
1
run = wandb.init()
2
my_table = wandb.Table(columns=["a", "b"], data=[["1a", "1b"], ["2a", "2b"]])
3
run.log({"table_key": my_table})
Copied!
Each time a table is logged to the same key, a new version of the table is created and stored in the backend. This means you can log the same table across multiple training steps to see how model predictions improve over time, or compare tables across different runs, as long as they're logged to the same key. You can log up to 200,000 rows.
To log more than 200,000 rows, you can override the limit with:
wandb.Table.MAX_ROWS = X
However, this would likely cause performance issues, such as slower queries, in the UI.

Access tables programmatically

In the backend, Tables are persisted as Artifacts. If you are interested in accessing a specific version, you can do so via the artifact API:
1
with wandb.init() as run:
2
my_table = run.use_artifact("run-<run-id>-<table-name>:<tag>").get("<table-name>")
Copied!

Visualize tables

Any table logged this way will show up in your Workspace on both the Run Page and the Project Page.

Advanced: Artifact Tables

Use artifact.add() to log tables to the Artifacts section of your run instead of the workspace. This could be useful if you have a dataset that you want to log once and then reference for future runs. Refer to this Colab for a detailed example of artifact.add() with image data → and this Report for an example of how to use Artifacts and Tables to version control and deduplicate tabular data →.
1
run = wandb.init(project="my_project")
2
# create a wandb Artifact for each meaningful step
3
test_predictions = wandb.Artifact("mnist_test_preds",
4
type="predictions")
5

6
# [build up your predictions data as above]
7
test_table = wandb.Table(data=data, columns=columns)
8
test_predictions.add(test_table, "my_test_key")
9
run.log_artifact(test_predictions)
Copied!

Join Artifact Tables

You can join tables you've locally constructed or tables you've retrieved from other artifacts using wandb.JoinedTable(table_1, table_2, join_key).
Args
Description
table_1
(str, wandb.Table, ArtifactEntry) the path to a wandb.Table in an artifact, the table object, or ArtifactEntry
table_2
(str, wandb.Table, ArtifactEntry) the path to a wandb.Table in an artifact, the table object, or ArtifactEntry
join_key
(str, [str, str]) key or keys on which to perform the join
To join two Tables you've logged previously in an artifact context, fetch them from the artifact and join the result into a new Table. For example, read one Table of original songs and another Table of synthesized versions of the same songs, join on "song_id", and upload a new Table to explore (live example → ).
1
run = wandb.init(project="my_project")
2
3
# fetch original songs table
4
orig_songs = run.use_artifact('original_songs:latest')
5
orig_table = orig_songs.get("original_samples")
6
7
# fetch synthesized songs table
8
synth_songs = run.use_artifact('synth_songs:latest')
9
synth_table = synth_songs.get("synth_samples")
10
11
# join tables on "song_id"
12
join_table = wandb.JoinedTable(orig_table, synth_table "song_id")
13
join_at = wandb.Artifact("synth_summary", "analysis")
14
15
# add table to artifact and log to W&B
16
join_at.add(join_table, "synth_explore")
17
run.log_artifact(join_at)
Copied!