Data Types in the W&B Python SDK for logging media and structured data
Data Types in W&B are classes that wrap media and structured data for logging to runs. They include visualization components in the W&B UI and handle data serialization, storage, and retrieval.
import wandbimport matplotlib.pyplot as plt# Generate an image for demonstration purposespath_to_img = "/path/to/cafe.png"im = plt.imread(path_to_img)# Initialize a new runwith wandb.init(project="awesome-project") as run: # Log the image run.log({"img": [wandb.Image(im, caption="Cafe")]})
This example uses a Table to log a table with mixed text and labels:
import wandb# Initialize a new runwith wandb.init(project="visualize-predictions", name="tables") as run: # Create tabular data, using a list of lists data = [["Cat", "1", "1"],["Dog", "0", "-1"]] run.log({"Table 1": wandb.Table(data=data, columns=["Text", "Predicted Label", "True Label"])}) # Create tabular data, using `wandb.Table.add_data()` method table = wandb.Table(columns=["Text", "Predicted Label", "True Label"]) table.add_data("Cat", "1", "1") table.add_data("Dog", "0", "-1") run.log({"Table 2": table})