Artifacts の description 、 metadata 、および alias を更新するには、希望する値を渡します。次に save() メソッドを呼び出して、 W&B サーバー上の Artifacts を更新します。 Artifacts の更新は、 W&B Run の実行中、または Run の外から行うことができます。
Artifact.save() と wandb.Run.log_artifact() の使い分け
- 既存の Artifacts を新しい Run を作成せずに更新する場合は、
Artifact.save() を使用してください。
- 新しい Artifacts を作成し、それを特定の Run に関連付ける場合は、
wandb.Run.log_artifact() を使用してください。
Run の外で Artifacts を更新するには、 W&B Public API (wandb.Api) を使用します。 Run の実行中に Artifacts を更新するには、 Artifact API (wandb.Artifact) を使用します。
Model Registry 内のモデルにリンクされている Artifacts の エイリアス を更新することはできません。
Run の実行中
Run の外から
コレクションを使用する場合
次のコード例は、 wandb.Artifact API を使用して Artifacts の説明(description)を更新する方法を示しています。import wandb
# プロジェクト名を指定して Run を開始
with wandb.init(project="<example>") as run:
# 使用する Artifacts を取得
artifact = run.use_artifact("<artifact-name>:<alias>")
# 説明を更新
artifact.description = "<description>"
# 変更を保存
artifact.save()
次のコード例は、 wandb.Api API を使用して Artifacts の説明を更新する方法を示しています。import wandb
api = wandb.Api()
# アーティファクトを取得
artifact = api.artifact("entity/project/artifact:alias")
# 説明(description)を更新
artifact.description = "My new description"
# メタデータの特定のキーを更新
artifact.metadata["oldKey"] = "new value"
# メタデータを完全に置き換え
artifact.metadata = {"newKey": "new value"}
# エイリアスを追加
artifact.aliases.append("best")
# エイリアスを削除
artifact.aliases.remove("latest")
# エイリアスを完全に置き換え
artifact.aliases = ["replaced"]
# すべてのアーティファクトの変更を永続化
artifact.save()
詳細については、 Weights & Biases の Artifact API を参照してください。 Artifact コレクションも、単体の Artifacts と同様の方法で更新できます。import wandb
with wandb.init(project="<example>") as run:
api = wandb.Api()
# アーティファクトコレクションを取得
artifact = api.artifact_collection(type="<type-name>", collection="<collection-name>")
# コレクション名を更新
artifact.name = "<new-collection-name>"
# コレクションの説明を更新
artifact.description = "<This is where you'd describe the purpose of your collection.>"
# 変更を保存
artifact.save()
詳細については、 Artifacts Collection のリファレンスを参照してください。