/SwanLab

🧐SwanLab: track and visualize all the pieces of your machine learning pipeline. Join our WeChat ⬇️

Primary LanguagePythonApache License 2.0Apache-2.0

SwanLab Library

Track and visualize all the pieces of your machine learning pipeline

/ license license / pypi Download Github Discussion

👋 Join our WeChat

English | 中文

Table of Contents


Changelog

[24/01/25] 😄 We supported a new Config/Summary table component that supports parameter search. Additionally, we've used new fonts and color schemes.

[24/01/23] 🚨 We use SQLite database and Peewee to replace the previous basic configuration information reading and writing solution by #114. It's a major change that is highly beneficial for the future of the project, but the drawback is that it's not compatible with old versions (swanlab<=v0.1.4) of log data files. Therefore, if you need to visualize log files generated by older versions, please use transfer script

Additionally, we supported export the experiment list as CSV, new environment record items Run path and logdir, added interactive quick copy function, and new API swanlab.config.

[24/01/14] 🔥 We supported a new UI, tracking additional environment information, including command, git commit/branch and memory. Additionally, we've added a logdir API, allowing developers to set the directory for log files.

Full Changelog


Key Function

  • 🧪 Experiments GridView: compare your key metrics for inspiration faster
  • 📊 Charts: visualize your entire training process
  • ⚡️ Track machine-learning pipeline: Hyperparameters, Config, Metric, Terminal logging, Environment Information auto save

  • 🥔 Offline Support: SwanLab can run entirely offile, ithout requiring any access to the Internet. For instance, this may be on your local machine, behind a corporate firewall, or in a datacenter

Note

See the SwanLab Documentaion and Examples for a full description of the SwanLab.


Installation

with pip

Requirement:Python 3.8+.

Use pip to install our stable release version. The installation command is as follows:

pip install -U swanlab

with source code

If you need the bleeding edge of the code and can't wait for a new release, you must install the library from source


Getting Started

  1. First, install the SwanLab SDK with pip:
pip install -U swanlab
  1. Second, Use the example code snippet below as a template to integrate SwanLab to your Python script:
import swanlab

# Start a SwanLab Run with swanlab.init
swanlab.init(
  # save model inputs and hyperparameters in a swanlab.config object
  config={'learning_rate': 0.01},
)

# Model training code here...

# Log metrics over time for visualizing performance with swanlab.log
for epoch in range(1, 20):
    swanlab.log({"loss": loss})
  1. Third, Run a Dashboard:
$ swanlab watch

That's it! Open http://127.0.0.1:5092 to view a dashboard of your first SwanLab Experiment.


Use Case

Learn how to use SwanLab more effectively by following these use cases:

Code Cases Description
Hello World Getting Started
MNIST Handwriting recognition based on a plain net and MNIST dataset with pytroch, swanlab.
Image Classification Cat and dog classification based on ResNet50 with pytorch, swanlab and gradio. Tutorial.
Text Generation Text generation based on Word_language_model (RNN/LSTM/GRU/Transformer)

More Tips

🏄‍♀️ Experiment Dashboard:

Set a log directory save path and run the Dashboard using it

Set a log directory save path, such as ./logs:

import swanlab 

swanlab.init(
  logdir="./logs"
)

Run the Dashboard using it:

$ swanlab watch --logdir ./logs_path
Set the Host and Port for the Dashboard
$ swanlab watch --host 0.0.0.0 --port 8080
Remotely access Dashboard

⚙️ Other:

argparse init swanlab.config

swanlab.config supports directly passing variables of type argparse.Namespace, such as:

import argparse
import swanlab

parser = argparse.ArgumentParser()
···
args = parser.parse_args()


swanlab.init(
    config=args
)

LICENSE

This project is currently licensed under Apache 2.0 License.