Skip to main content

深度学习实验记录工具

Project description

Experiment 类文档

概述

Experiment 类是实验跟踪系统的核心类,用于管理整个实验的全局配置和环境信息。

功能特性

1. 初始化方法

def __init__(self,
             name: str = "未命名实验",
             description: Optional[str] = None,
             stage_description: Optional[str] = None,
             auto_save: bool = True,
             auto_save_path: Optional[Path] = None,
             env_dependency: bool = False,
             verbose: bool = False):

参数说明:

  • name: 实验名称
  • description: 实验描述
  • stage_description: 阶段描述
  • auto_save: 是否自动保存
  • auto_save_path: 自定义保存路径
  • env_dependency: 是否收集依赖信息
  • verbose: 是否显示详细日志

2. 训练配置设置

def set_training_config(self,
                       dataset=None,
                       dataloader=None,
                       model=None,
                       optimizer=None,
                       criterion=None,
                       scheduler=None,
                       dataset_info: Optional[Dict[str, Any]] = None,
                       model_info: Optional[Dict[str, Any]] = None,
                       optimizer_info: Optional[Dict[str, Any]] = None,
                       criterion_info: Optional[Dict[str, Any]] = None,
                       scheduler_info: Optional[Dict[str, Any]] = None,
                       hyperparameters: Optional[Dict[str, Any]] = None,
                       training_parameters: Optional[Dict[str, Any]] = None,
                       **kwargs):

3. 日志记录方法

记录训练轮次
def log_epoch(self, epoch: int,
             train_metrics: Optional[Dict[str, float]] = None,
             val_metrics: Optional[Dict[str, float]] = None,
             dataset_info: Optional[Dict[str, Any]] = None,
             model_path: Optional[str] = None,
             message: Optional[str] = None,
             **kwargs) -> Round:

记录训练批次
def log_batch(self, epoch: int, batch: int,
             metrics: Optional[Dict[str, float]] = None,
             images: Optional[Dict[str, str]] = None,
             message: Optional[str] = None,
             **kwargs) -> Entry:

记录指标
def log_metric(self, name: str, value: float, epoch: int,
              batch: Optional[int] = None, message: Optional[str] = None) -> Entry:

记录图像
def log_image(self, name: str, path: str, epoch: int,
             batch: Optional[int] = None, message: Optional[str] = None) -> Entry:

4. 序列化方法

转换为字典
def to_dict(self) -> dict:

从字典创建实例
@classmethod
def from_dict(cls, data: dict) -> "Experiment":

从YAML文件加载
@classmethod
def load_experiment_from_yaml(cls, yaml_path: Path):

使用示例

基础用法

from experiment_tracker.experiment import Experiment

初始化实验
exp = Experiment(name="MNIST分类实验", description="测试不同模型在MNIST上的表现")

设置训练配置
exp.set_training_config(
    dataset=train_dataset,
    dataloader=train_loader,
    model=model,
    optimizer=optimizer,
    criterion=criterion
)

记录训练过程
for epoch in range(epochs):
    # ... 训练代码 ...
    exp.log_epoch(
        epoch=epoch,
        train_metrics={"loss": train_loss, "accuracy": train_acc},
        val_metrics={"val_loss": val_loss, "val_accuracy": val_acc}
    )

数据存储结构

experiment_records/
    ├── 实验名称_哈希ID/
    │   ├── stage_主阶段ID/
    │   │   ├── 时间戳.yaml
    │   │   └── ...
    │   └── ...
    └── ...

注意事项

  1. 自动保存功能默认开启
  2. 实验ID基于实验名称生成

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlexprecords-0.0.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlexprecords-0.0.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file mlexprecords-0.0.1.tar.gz.

File metadata

  • Download URL: mlexprecords-0.0.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.0

File hashes

Hashes for mlexprecords-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f9bb7780860de75b81a580c7508d3094f5d0ee4fe100d1ae370ba7c1967fec0d
MD5 4cfa7cc852b8118bd04392f12a019e53
BLAKE2b-256 dd4b7abb20a7448bd21f4a2885fe128380a00e3a611ef7f2c550ed34f4ee1b14

See more details on using hashes here.

File details

Details for the file mlexprecords-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mlexprecords-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 190fadb8c6c4e6ae1dcc8c7946f0ee3fee3aa6a8769835aea377d679e55fc1e5
MD5 d4ffd875a617e9791f490a7e2ca2cb88
BLAKE2b-256 05da2631e6fe4561ae9c292f9f8cbc8ad89f21404c6b64fadf6ccc776fb19c1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page