Log in to W&B
Import the W&B library and log in to W&B. If you haven’t done so already, sign up for a free W&B account.Initialize a run
Usewandb.init() to initialize a run. This generates a background process to sync and log data. Provide a project name and a job type:
Create an artifact object
Create an artifact object withwandb.Artifact(). Provide a name for the artifact and a description of the file type for the name and type parameters, respectively.
For example, the following code snippet demonstrates how to create an artifact called 'bicycle-dataset' with a 'dataset' label:
Add the dataset to the artifact
Add a file to the artifact. Common file types include models and datasets. The following example adds a dataset nameddataset.h5 that is saved locally on your machine to the artifact:
dataset.h5 in the previous code snippet with the path to the file you want to add to the artifact.
Log the dataset
Use the W&B run object’swandb.Run.log_artifact() method to both save your artifact version and declare the artifact as an output of the run.
'latest' alias by default. For more information about artifact aliases and versions, see Create a custom alias and Create new artifact versions, respectively.
Putting this together, your script so far should look like this:
Download and use the artifact
Now that the dataset is logged as an artifact, you can pull it into other runs as a tracked input. The following code example demonstrates the steps you can take to use an artifact you’ve logged and saved to the W&B servers:- Initialize a new run object with
wandb.init(). - Use the run object’s
wandb.Run.use_artifact()method to specify which artifact to use. This returns an artifact object. - Use the artifact’s
wandb.Artifact.download()method to download the contents of the artifact.
wandb.Api) to export or update data already saved in W&B outside of a run. For more information, see Track external files.
You now have a versioned dataset artifact logged to W&B and consumed by a downstream run. The artifact graph tracks both the upload and the download.