CSV ファイルを表としてログする
"""
Log a CSV file to W&B as a table.
Replace:
- values enclosed in angle brackets with your own
- <name>.csv in pd.read_csv() with the name of your CSV file
"""
import wandb
import pandas as pd
# CSV を(pandas の)DataFrame オブジェクトとして読み込みます
dataframe = pd.read_csv("<name>.csv")
# DataFrame を W&B 表に変換します
table = wandb.Table(dataframe=dataframe)
# データをログするための W&B run を開始します
with wandb.init(project="<project>") as run:
# 表をログして W&B UI で可視化します
run.log({"<table_name>": table})
カスタム サマリー メトリクスをログする
"""
Log a custom summary metric to W&B.
"""
import wandb
import random
with wandb.init(project="<project>") as run:
# 1 から 10 までのランダムな整数値をカスタム サマリー メトリクスとしてログします
run.summary["<metric_name>"] = random.randint(1, 10)
カスタム サマリー メトリクスをログする
"""
Log a custom summary metric to W&B.
Replace:
- values enclosed in angle brackets with your own
- <summary_function_a> and <summary_function_b> in run.define_metric() with
one of "max", "min", "last", "mean", "best", or "none".
"""
import wandb
import random
with wandb.init() as run:
# metric_name_a に対して summary_function_a と summary_function_b のサマリー値を定義します
run.define_metric(name="<metric_name_a>", summary="<summary_function_a>")
run.define_metric(name="<metric_name_a>", summary="<summary_function_b>")
for i in range(10):
log_dict = {
"metric_name_a": random.uniform(0, 1 / (i + 1)),
}
run.log(log_dict)
レジストリコレクションから既存のアーティファクトをダウンロードしてログする
"""
Download and log an existing artifact from a registry collection.
Replace the placeholders with actual registry, collection names, entity,
project, and version.
"""
import wandb
# バージョンを含む完全なアーティファクト名を作成します
registry_name = "<registry_name>" # レジストリ名を指定します
collection_name = "<collection_name>" # コレクション名を指定します
version = 0 # 使用するアーティファクトのバージョンを指定します
artifact_name_registry = f"wandb-registry-{registry_name}/{collection_name}:v{version}"
# 別のチームと project で W&B run を初期化します
with wandb.init(entity="<entity>", project="<project>") as run:
# レジストリにあるモデル アーティファクトを使用します
registry_model = run.use_artifact(artifact_or_name=artifact_name_registry)
# モデルをローカル ディレクトリにダウンロードします
local_model_path = registry_model.download()
ヒストグラムプロットをログする
"""
Log a histogram plot to W&B.
Replace:
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to plot
Pass a 2D row-oriented array of values to data (wandb.Table(data=)), with
column names specified in the `columns` parameter.
"""
import wandb
# 新しい run を開始します
with wandb.init(entity="<entity>", project="<project>") as run:
# プロットする列を含む表を作成します
table = wandb.Table(data=[[1, 2], [2, 3]] , columns=["<a_column>", "<b_column>"])
# 表のデータを使用してさまざまなカスタム チャートを作成します
histogram = wandb.plot.histogram(table, value='<b_column>', title='Histogram')
# カスタム表をログします。ログした表は UI 上のカスタマイズ可能なチャートに表示されます
run.log({'histogram_1': histogram})
run を初期化してハイパーパラメーターをログする
"""Initializes a W&B run and logs hyperparameters."""
import wandb
config = {
"learning_rate": 0.01,
"batch_size": 32,
"optimizer": "adam",
}
with wandb.init(project="<project>", config=config) as run:
# ここにトレーニングとログするコードを記述します
pass
折れ線グラフをログする
"""
Log a line plot to W&B.
Replace:
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to plot
Pass a 2D row-oriented array of values to data (wandb.Table(data=)), with
column names specified in the `columns` parameter.
Column names must match the x and y parameters in the `wandb.plot.line()` plotting function.
"""
import wandb
# 新しい run を開始します
with wandb.init(entity="<entity>", project="<project>") as run:
# プロットする列を含む表を作成します
table = wandb.Table(data=[[1, 2], [2, 3]], columns=["<column_a>", "<column_b>"])
# 表を使用して、さまざまなカスタム チャートにデータを設定します
line_plot = wandb.plot.line(table, x='<column_a>', y='<column_b>', title='<title>')
# カスタムの表をログします。ログした表は UI 上のカスタマイズ可能なチャートに表示されます
run.log({'<line_plot>': line_plot})
run を初期化してメトリクスをログする
"""Initializes a W&B run and logs a metric."""
import wandb
with wandb.init(project="<project>") as run:
# トレーニングとログのためのコードをここに記述します
# メトリクスをログする例
run.log({"accuracy": 0.95})
散布図をログする
"""
Log a scatter plot to W&B.
Replace:
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to plot
Pass a 2D row-oriented array of values to data (wandb.Table(data=)), with
column names specified in the `columns` parameter.
Column names must match the x and y parameters in the `wandb.plot.scatter()` plotting function.
"""
import wandb
# 新しい run を開始します
with wandb.init(entity="<entity>", project="<project>") as run:
# プロット対象の列を持つ表を作成します
table = wandb.Table(data=[[1, 2], [2, 3]], columns=["<a_column>", "<b_column>"])
# 表のデータをさまざまなカスタム チャートに使用します
scatter = wandb.plot.scatter(table, x='<a_column>', y='<b_column>', title='<title>')
# カスタム表をログします。ログした表は UI 上のカスタマイズ可能なチャートに表示されます
run.log({'scatter_1': scatter})
サマリー メトリクスを明示的にログする
"""
Explicitly log a summary metric to W&B.
"""
import wandb
import random
with wandb.init(project="<project>") as run:
# 1から10の間のランダムな整数値を持つカスタム サマリー メトリクスをログする
run.summary["<metric_name>"] = random.randint(1, 10)
表をログする
"""
Log a table to W&B.
Replace:
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to log
"""
import wandb
# 2 列 2 行のデータを含む表オブジェクトを作成します
my_table = wandb.Table(
columns=["<a_column>", "<b_column>"],
data=[[1, 2], [2, 3]],
log_mode="<log_mode>"
)
# 新しい run を開始します
with wandb.init(entity="<entity>", project="<project>") as run:
# 表を W&B にログします
run.log({"<table_name>": my_table})