[source]
class Run(object)
[source]
The run object corresponds to a single execution of your script, typically this is an ML experiment. Create a run with wandb.init().
In distributed training, use wandb.init() to create a run for each process, and set the group argument to organize runs into a larger experiment.
Currently there is a parallel Run object in the wandb.Api. Eventually these two objects will be merged.
Attributes:
history
History
- Time series values, created with wandb.log().
History can contain scalar values, rich media, or even custom plots
across multiple steps.
summary
Summary
- Single values set for each wandb.log() key. By
default, summary is set to the last value logged. You can manually
set summary to the best value, like max accuracy, instead of the
final value.
dir
| @property| dir()
[source]
str: The directory where all of the files associated with the run are placed.
config
| @property| config()
[source]
(Config
): A config object (similar to a nested dict) of key value pairs associated with the hyperparameters of the run.
name
| @property| name()
[source]
str: the display name of the run. It does not need to be unique and ideally is descriptive.
notes
| @property| notes()
[source]
str: notes associated with the run. Notes can be a multiline string and can also use markdown and latex equations inside $$ like $\{x}
tags
| @property| tags() -> Optional[Tuple]
[source]
Tuple[str]: tags associated with the run
id
| @property| id()
[source]
str: the run_id associated with the run
sweep_id
| @property| sweep_id()
[source]
(str, optional): the sweep id associated with the run or None
path
| @property| path()
[source]
str: the path to the run [entity]/[project]/[run_id]
start_time
| @property| start_time()
[source]
int: the unix time stamp in seconds when the run started
starting_step
| @property| starting_step()
[source]
int: the first step of the run
resumed
| @property| resumed()
[source]
bool: whether or not the run was resumed
step
| @property| step()
[source]
int: step counter
Every time you call wandb.log() it will by default increment the step counter.
mode
| @property| mode()
[source]
For compatibility with 0.9.x and earlier, deprecate eventually.
group
| @property| group()
[source]
str: name of W&B group associated with run.
Setting a group helps the W&B UI organize runs in a sensible way.
If you are doing a distributed training you should give all of the runs in the training the same group. If you are doing crossvalidation you should give all the crossvalidation folds the same group.
project
| @property| project()
[source]
str: name of W&B project associated with run.
get_url
| get_url()
[source]
Returns: (str, optional): URL for the W&B run or None if the run is offline
get_project_url
| get_project_url()
[source]
Returns: (str, optional): URL for the W&B project associated with the run or None if the run is offline
get_sweep_url
| get_sweep_url()
[source]
Returns: (str, optional): URL for the sweep associated with the run or None if there is no associated sweep or the run is offline.
url
| @property| url()
[source]
str: name of W&B URL associated with run.
entity
| @property| entity()
[source]
str: name of W&B entity associated with run. Entity is either a user name or an organization name.
log
| log(data, step=None, commit=None, sync=None)
[source]
Log a dict to the global run's history.
wandb.log can be used to log everything from scalars to histograms, media and matplotlib plots.
The most basic usage is wandb.log({'train-loss': 0.5, 'accuracy': 0.9}). This will save a history row associated with the run with train-loss=0.5 and accuracy=0.9. The history values can be plotted on app.wandb.ai or on a local server. The history values can also be downloaded through the wandb API.
Logging a value will update the summary values for any metrics logged. The summary values will appear in the run table at app.wandb.ai or a local server. If a summary value is manually set with for example wandb.run.summary["accuracy"] = 0.9 wandb.log will no longer automatically update the run's accuracy.
Logging values don't have to be scalars. Logging any wandb object is supported. For example wandb.log({"example": wandb.Image("myimage.jpg")}) will log an example image which will be displayed nicely in the wandb UI. See https://docs.wandb.com/library/reference/data_types for all of the different supported types.
Logging nested metrics is encouraged and is supported in the wandb API, so you could log multiple accuracy values with wandb.log({'dataset-1': {'acc': 0.9, 'loss': 0.3} ,'dataset-2': {'acc': 0.8, 'loss': 0.2}}) and the metrics will be organized in the wandb UI.
W&B keeps track of a global step so logging related metrics together is encouraged, so by default each time wandb.log is called a global step is incremented. If it's inconvenient to log related metrics together calling wandb.log({'train-loss': 0.5, commit=False}) and then wandb.log({'accuracy': 0.9}) is equivalent to calling wandb.log({'train-loss': 0.5, 'accuracy': 0.9})
wandb.log is not intended to be called more than a few times per second. If you want to log more frequently than that it's better to aggregate the data on the client side or you may get degraded performance.
Arguments:
row
dict, optional - A dict of serializable python objects i.e str,
ints, floats, Tensors, dicts, or wandb.data_types
commit
boolean, optional - Save the metrics dict to the wandb server
and increment the step. If false wandb.log just updates the current
metrics dict with the row argument and metrics won't be saved until
wandb.log is called with commit=True.
step
integer, optional - The global step in processing. This persists
any non-committed earlier steps but defaults to not committing the
specified step.
sync
boolean, True - This argument is deprecated and currently doesn't
change the behaviour of wandb.log
Examples:
Basic usage
- `wandb.log({'accuracy'` - 0.9, 'epoch': 5})
Incremental logging
- `wandb.log({'loss'` - 0.2}, commit=False)# Somewhere else when I'm ready to report this step:- `wandb.log({'accuracy'` - 0.8})
Histogram
- `wandb.log({"gradients"` - wandb.Histogram(numpy_array_or_sequence)})
Image
- `wandb.log({"examples"` - [wandb.Image(numpy_array_or_pil, caption="Label")]})
Video
- `wandb.log({"video"` - wandb.Video(numpy_array_or_video_path, fps=4,format="gif")})
Matplotlib Plot
- `wandb.log({"chart"` - plt})
PR Curve
- `wandb.log({'pr'` - wandb.plots.precision_recall(y_test, y_probas, labels)})
3D Object
wandb.log({"generated_samples":[wandb.Object3D(open("sample.obj")),wandb.Object3D(open("sample.gltf")),wandb.Object3D(open("sample.glb"))]})
For more examples, see https://docs.wandb.com/library/log
Raises:
wandb.Error - if called before wandb.init ValueError - if invalid data is passed
save
| save(glob_str: Optional[str] = None, base_path: Optional[str] = None, policy: str = "live")
[source]
Ensure all files matching glob_str are synced to wandb with the policy specified.
Arguments:
glob_str
string - a relative or absolute path to a unix glob or
regular path. If this isn't specified the method is a noop.
base_path
string - the base path to run the glob relative to
policy
string - on of "live", "now", or "end"
live
- upload the file as it changes, overwriting the previous
version now: upload the file once now
end
- only upload file when the run ends
finish
| finish(exit_code=None)
[source]
Marks a run as finished, and finishes uploading all data. This is used when creating multiple runs in the same process. We automatically call this method when your script exits.
join
| join(exit_code=None)
[source]
Deprecated alias for finish() - please use finish
plot_table
| plot_table(vega_spec_name, data_table, fields, string_fields=None)
[source]
Creates a custom plot on a table.
Arguments:
vega_spec_name
- the name of the spec for the plot
table_key
- the key used to log the data table
data_table
- a wandb.Table object containing the data to
be used on the visualization
fields
- a dict mapping from table keys to fields that the custom
visualization needs
string_fields
- a dict that provides values for any string constants
the custom visualization needs
use_artifact
| use_artifact(artifact_or_name, type=None, aliases=None)
[source]
Declare an artifact as an input to a run, call download
or file
on the returned object to get the contents locally.
Arguments:
artifact_or_name
str or Artifact - An artifact name.
May be prefixed with entity/project. Valid names
can be in the following forms:
name:version
name:alias
digest
You can also pass an Artifact object created by calling wandb.Artifact
type
str, optional - The type of artifact to use.
aliases
list, optional - Aliases to apply to this artifact
Returns:
A Artifact
object.
log_artifact
| log_artifact(artifact_or_path, name=None, type=None, aliases=None)
[source]
Declare an artifact as output of a run.
Arguments:
artifact_or_path
str or Artifact - A path to the contents of this artifact,
can be in the following forms:
/local/directory
/local/directory/file.txt
s3://bucket/path
You can also pass an Artifact object created by calling
wandb.Artifact
.
name
str, optional - An artifact name. May be prefixed with entity/project.
Valid names can be in the following forms:
name:version
name:alias
digest
This will default to the basename of the path prepended with the current
run id if not specified.
type
str - The type of artifact to log, examples include "dataset", "model"
aliases
list, optional - Aliases to apply to this artifact,
defaults to ["latest"]
Returns:
A Artifact
object.
alert
| alert(title, text, level=None, wait_duration=None)
[source]
Launch an alert with the given title and text.
Arguments:
title
str - The title of the alert, must be less than 64 characters long
text
str - The text body of the alert
level
str or wandb.AlertLevel, optional - The alert level to use, either: "INFO", "WARN", or "ERROR"
wait_duration
int, float, or timedelta, optional - The time to wait (in seconds) before sending another alert
with this title