Giter Site home page Giter Site logo

wandb-cpp's Introduction



WandB-CPP

Unofficial C++ binding for Weight & Biases.

Installation

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

pip install wandb

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

Usage

Basic Usage

Execution result is here!

#include <cmath>
#include <iostream>

#include "wandbcpp.hpp"

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

  int N = 100;

  wandbcpp::update_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();
}

result

Upload Image

Execution result is here!

#include <opencv2/opencv.hpp>
#include "wandbcpp.hpp"

int main()
{
  wandbcpp::init({.project = "example_wandb_cpp", .tags = {"image"}});
  cv::Mat img = cv::imread("examples/data/lena.png");
  wandbcpp::log({{"image_from_array", wandbcpp::Image(img)}});
  wandbcpp::log(
      {{"image_from_path", wandbcpp::Image("examples/data/lena.png")}});
  wandbcpp::finish();
}

result

Upload Video

Execution result is here!

#include <opencv2/opencv.hpp>
#include "wandbcpp.hpp"

int main() {
  cv::VideoCapture cap("examples/data/parrot.mp4");

  if (!cap.isOpened()) {
    std::cerr << "Error: Video file not opened." << std::endl;
    return 1;
  }

  std::vector<cv::Mat> frames;

  while (true) {
    cv::Mat frame;
    cap >> frame;
    if (frame.empty()) break;

    frames.push_back(frame);
  }
  std::cout << "Number of frames: " << frames.size() << std::endl;

  wandbcpp::init({.project = "example_wandb_cpp", .tags = {"video"}});

  wandbcpp::log({{"video", wandbcpp::Video(frames.begin(), frames.end())}});

  wandbcpp::finish();
}

result

Save File

Execution result is here!

#include "wandbcpp.hpp"

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

result

wandb.Table

  • use add_data

    Execution result is here!

    #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();
    }

    result

  • use add_column

    Execution result is here!

    #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();
    }

    result

  • passing data in the constructor

    Execution result is here!

    #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();
    }

    result

wandb.Object3D

  • plot pointcloud

    Execution result is here!

    #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() {
      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;
    }

    result

Build examples

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

CMake options

  • BUILD_WANDBCPP_EXE : Build examples. Default is OFF.
  • USE_OPENCV : To save image, use OpenCV. Default is OFF.

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.

wandb-cpp's People

Contributors

yhisaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

thanduriel

wandb-cpp's Issues

Other log types

Hello,

Epic library.

Is it possible to support other log metrics, such as video and 3d plots?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.