Thanduriel / wandb-cpp

C++ visualizing and tracking library built on the wandb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WandB-CPP

Installation

wandb-cpp works by wrapping the Weight & Biases.So, you need to install wandb according to this procedure first.

The required Python packages are listed in the requirements.txt file.

Usage

Basic Usage

#include <cmath>
#include <iostream>

#include "wandbcpp.hpp"

int main() {
  wandbcpp::init({.project = "example_wandb_cpp", .tags = {"basic"}});

  int N = 100;

  wandbcpp::add_config({{"N", N}, {"mode", "abc"}});

  for (int i = 0; i < N; i++) {
    double t = M_PI * i / N;
    double x = std::sin(M_PI * i / N);
    double y = std::cos(M_PI * i / N);
    wandbcpp::log({{"t", t}, {"x", x}, {"y", y}});
    std::cout << "i : " << i << std::endl;
  }

  wandbcpp::finish();
}

Save File

#include "wandbcpp.hpp"

int main() {
  wandbcpp::init({.project = "example_wandb_cpp", .tags = {"save file"}});
  wandbcpp::save(__FILE__);  // save this source code
  wandbcpp::finish();
}

wandb.Table

  • use add_data

    #include <cmath>
    
    #include "wandbcpp.hpp"
    
    int main() {
      wandbcpp::init({.project = "example_wandb_cpp", .tags = {"table"}});
      int I = 10;
      int J = 100;
    
      for (int i = 0; i < I; i++) {
        wandbcpp::Table table({"x", "y"});
        for (int j = 0; j < J; j++) {
          double x = (i + 1) * std::sin(M_PI * j / J);
          double y = (i + 1) * std::cos(M_PI * j / J);
          table.add_data({x, y});
        }
        wandbcpp::log({{"mytable", table}});
      }
      wandbcpp::finish();
    }
  • use add_column

    #include "wandbcpp.hpp"
    
    int main() {
      wandbcpp::init({.project = "example_wandb_cpp", .tags = {"table"}});
      wandbcpp::Table table;
      std::vector<double> x = {1.0, 2.0, 3.0};
      std::vector<int> y = {4, 5, 6};
      table.add_column("x", {x.begin(), x.end()});
      table.add_column("y", {y.begin(), y.end()});
      wandbcpp::log({{"table", table}});
      wandbcpp::finish();
    }
  • passing data in the constructor

    #include "wandbcpp.hpp"
    
    int main() {
      wandbcpp::init({.project = "example_wandb_cpp", .tags = {"table"}});
      int I = 10;
      for (int i = 0; i < I; i++) {
        wandbcpp::Table table({"x", "y"}, {{"poyo", i}, {"hoge", i + 1}});
        wandbcpp::log({{"table", table}});
      }
      wandbcpp::finish();
    }

wandb.Object3D

  • plot pointcloud

    #include <array>
    #include <random>
    
    #include "wandbcpp.hpp"
    
    std::array<double, 3> gen_random_point() {
      static std::random_device seed_gen;
      static std::mt19937 engine(seed_gen());
      static std::uniform_real_distribution<> dist(-1.0, 1.0);
      return {dist(engine), dist(engine), dist(engine)};
    }
    
    int main(int argc, char const* argv[]) {
      namespace np = wandbcpp::numpy;
    
      wandbcpp::init({.project = "example_wandb_cpp", .tags = {"object3d"}});
    
      int num_points = 300;
    
      std::vector<std::array<double, 3>> point_cloud(num_points);
    
      std::generate(point_cloud.begin(), point_cloud.end(), &gen_random_point);
    
      auto lst = wandbcpp::topylist(point_cloud.begin(), point_cloud.end());
    
      wandbcpp::log({{"obj3d", wandbcpp::Object3D{np::ndarray{lst}}}});
    
      wandbcpp::finish();
    
      return 0;
    }

Build examples

mkdir build && cd build
cmake -D BUILD_WANDBCPP_EXE=ON ..
make

Implementation & Performance

This library executes most of its operations in multi-threaded mode. Therefore, this library should have little impact on the performance of the main processing.

About

C++ visualizing and tracking library built on the wandb

License:MIT License


Languages

Language:C++ 97.5%Language:CMake 2.5%