Documentation
Search…
Working with CSV
Importing and logging data into W&B

Converting your CSV of Experiments into a W&B Dashboard

The below table becomes this Weights & Biases Dashboard after conversion
Experiment
Model Name
Notes
Tags
Num Layers
Final Train Acc
Final Val Acc
Training Losses
Experiment 1
mnist-300-layers
Overfit way too much on training data
[latest]
300
0.99
0.90
[0.55, 0.45, 0.44, 0.42, 0.40, 0.39]
Experiment 2
mnist-250-layers
Current best model
[prod, best]
250
0.95
0.96
[0.55, 0.45, 0.44, 0.42, 0.40, 0.39]
Experiment 3
mnist-200-layers
Did worse than the baseline model. Need to debug
[debug]
200
0.76
0.70
[0.55, 0.45, 0.44, 0.42, 0.40, 0.39]
...
...
...
...
...
...
...
Experiment N
mnist-X-layers
NOTES
...
...
...
...
[..., ...]
In some cases, you may have your experiment details in a CSV file. W&B can take this CSV and easily convert it into an experiment run. That may include:
  • A name for the experiment run
  • Initial notes
  • Tags to differentiate the experiments
  • Configurations needed for your experiment (with the added benefit of being able to utilize our Sweeps Hyperparameter Tuning)
You can log this data a wandb.init() command:
1
run = wandb.init(project=PROJECT_NAME, name=run_name, tags=tags, notes=notes, config=config)
Copied!
As an experiment runs, you'll want to log every instance of your metrics so they are available to view, query, and analyze with W&B. This is done via a run.log() command:
1
run.log({key: val})
Copied!
Once an experiment reaches the end, you may want to log final summary metrics to define the outcome of the run. This can be done with W&B using define_metric, but in this example case, we will be directly adding the summary metrics to our run with run.summary.update():
1
run.summary.update(summaries)
Copied!
Below is the full example script that will turn the above table into a W&B Dashboard:
1
FILENAME = "experiments.csv"
2
loaded_experiment_df = pd.read_csv(FILENAME)
3
4
PROJECT_NAME = "Converted Experiments"
5
6
EXPERIMENT_NAME_COL = "Experiment"
7
NOTES_COL = "Notes"
8
TAGS_COL = "Tags"
9
CONFIG_COLS = ["Num Layers"]
10
SUMMARY_COLS = ["Final Train Acc", "Final Val Acc"]
11
METRIC_COLS = ["Training Losses"]
12
pyth
13
for i, row in loaded_experiment_df.iterrows():
14
15
run_name = row[EXPERIMENT_NAME_COL]
16
notes = row[NOTES_COL]
17
tags = row[TAGS_COL]
18
19
config = {}
20
for config_col in CONFIG_COLS:
21
config[config_col] = row[config_col]
22
23
metrics = {}
24
for metric_col in METRIC_COLS:
25
metrics[metric_col] = row[metric_col]
26
27
summaries = {}
28
for summary_col in SUMMARY_COLS:
29
summaries[summary_col] = row[summary_col]
30
31
32
run = wandb.init(project=PROJECT_NAME, name=run_name,\
33
tags=tags, notes=notes, config=config)
34
35
for key, val in metrics.items():
36
if isinstance(val, list):
37
for _val in val:
38
run.log({key: _val})
39
else:
40
run.log({key: val})
41
42
run.summary.update(summaries)
43
run.finish()
Copied!

Logging your CSV for Visualization and Reuse

You can also convert CSVs into interactive wandb.Table format fit for a W&B Dashboard.
Using Artifacts we can also directly log our .csv file to W&B for reuse across projects and experiments:
1
# Read our CSV into a new DataFrame
2
new_iris_dataframe = pd.read_csv("iris_dataframe.csv")
3
4
# Convert the DataFrame into a W&B Table
5
# NOTE: Tables will have a row limit of 10000 but...
6
iris_table = wandb.Table(dataframe=new_iris_dataframe)
7
8
# Add the table to an Artifact to increase the row limit to 200000 and make it easier to reuse!
9
iris_table_artifact = wandb.Artifact("iris_artifact", type="dataset")
10
iris_table_artifact.add(iris_table, "iris_table")
11
12
# We will also log the raw csv file within an artifact to preserve our data
13
iris_table_artifact.add_file("iris_dataframe.csv")
14
15
# Start a W&B run to log data
16
run = wandb.init(project="Tables-Quickstart")
17
18
# Log the table to visualize with a run...
19
run.log({"iris": iris_table})
20
21
# and Log as an Artifact to increase the available row limit!
22
run.log_artifact(iris_table_artifact)
23
24
# Finish the run (useful in notebooks)
25
run.finish()
Copied!