Journaliser un fichier CSV sous forme de tableau
"""
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
# Lire le fichier CSV sous forme d’objet DataFrame (pandas)
dataframe = pd.read_csv("<name>.csv")
# Convertir le DataFrame en tableau W&B (W&B Table)
table = wandb.Table(dataframe=dataframe)
# Démarrer un run W&B pour journaliser les données
with wandb.init(project="<project>") as run:
# Journaliser le tableau pour le visualiser dans l’interface W&B
run.log({"<table_name>": table})
Journaliser une métrique de synthèse personnalisée
"""
Log a custom summary metric to W&B.
"""
import wandb
import random
with wandb.init(project="<project>") as run:
# Journaliser une métrique de synthèse personnalisée ayant pour valeur un entier aléatoire compris entre 1 et 10
run.summary["<metric_name>"] = random.randint(1, 10)
Journaliser une métrique de synthèse personnalisée
"""
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:
# Valeurs de synthèse de metric_name_a selon summary_function_a et 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)
Télécharger et journaliser un artifact existant depuis une collection de registre
"""
Download and log an existing artifact from a registry collection.
Replace the placeholders with actual registry, collection names, entity,
project, and version.
"""
import wandb
# Construire le nom complet de l’artifact avec sa version
registry_name = "<registry_name>" # Indiquer le nom du registre
collection_name = "<collection_name>" # Indiquer le nom de la collection
version = 0 # Indiquer la version de l’artifact à utiliser
artifact_name_registry = f"wandb-registry-{registry_name}/{collection_name}:v{version}"
# Initialiser un run W&B dans l’autre équipe et l’autre projet
with wandb.init(entity="<entity>", project="<project>") as run:
# Utiliser l’artifact de modèle issu du registre
registry_model = run.use_artifact(artifact_or_name=artifact_name_registry)
# Télécharger le modèle dans un répertoire local
local_model_path = registry_model.download()
Journaliser un histogramme
"""
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
# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
# Créer un tableau contenant les colonnes à tracer
table = wandb.Table(data=[[1, 2], [2, 3]] , columns=["<a_column>", "<b_column>"])
# Utiliser le tableau pour alimenter différents graphiques personnalisés
histogram = wandb.plot.histogram(table, value='<b_column>', title='Histogram')
# Journaliser des tableaux personnalisés, qui apparaîtront sous forme de graphiques personnalisables dans l’interface utilisateur
run.log({'histogram_1': histogram})
Initialiser un run et journaliser les hyperparamètres
"""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:
# Placez ici le code d’entraînement et de journalisation
pass
Journaliser un graphique en courbes
"""
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
# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
# Créer un tableau contenant les colonnes à représenter
table = wandb.Table(data=[[1, 2], [2, 3]], columns=["<column_a>", "<column_b>"])
# Utiliser le tableau pour alimenter divers graphiques personnalisés
line_plot = wandb.plot.line(table, x='<column_a>', y='<column_b>', title='<title>')
# Journaliser des tableaux personnalisés, qui apparaîtront sous forme de graphiques personnalisables dans l’interface utilisateur
run.log({'<line_plot>': line_plot})
Initialiser un run et journaliser une métrique
"""Initializes a W&B run and logs a metric."""
import wandb
with wandb.init(project="<project>") as run:
# Placez ici le code d’entraînement et de journalisation
# Exemple de journalisation d’une métrique
run.log({"accuracy": 0.95})
Journaliser un nuage de points
"""
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
# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
# Créer un tableau contenant les colonnes à représenter
table = wandb.Table(data=[[1, 2], [2, 3]], columns=["<a_column>", "<b_column>"])
# Utiliser le tableau pour alimenter divers graphiques personnalisés
scatter = wandb.plot.scatter(table, x='<a_column>', y='<b_column>', title='<title>')
# Journaliser des tableaux personnalisés, qui apparaîtront sous forme de graphiques personnalisables dans l’interface utilisateur
run.log({'scatter_1': scatter})
Journaliser explicitement une métrique de synthèse
"""
Explicitly log a summary metric to W&B.
"""
import wandb
import random
with wandb.init(project="<project>") as run:
# Journaliser une métrique de synthèse personnalisée dont la valeur est un entier aléatoire compris entre 1 et 10
run.summary["<metric_name>"] = random.randint(1, 10)
Journaliser un tableau
"""
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
# Créer un objet tableau contenant deux colonnes et deux lignes de données
my_table = wandb.Table(
columns=["<a_column>", "<b_column>"],
data=[[1, 2], [2, 3]],
log_mode="<log_mode>"
)
# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
# Journaliser le tableau dans W&B
run.log({"<table_name>": my_table})