All Projects → vvmnnnkv → libtorchjs

vvmnnnkv / libtorchjs

Licence: other
Node.js N-API wrapper for libtorch

Programming Languages

CMake
9771 projects
C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to libtorchjs

LibtorchTutorials
This is a code repository for pytorch c++ (or libtorch) tutorial.
Stars: ✭ 463 (+2793.75%)
Mutual labels:  libtorch
dtt
A C++ header-only for data transfer between linear algebra libraries (Eigen, Armadillo, OpenCV, ArrayFire, LibTorch).
Stars: ✭ 74 (+362.5%)
Mutual labels:  libtorch
win-ca
Get Windows System Root certificates
Stars: ✭ 78 (+387.5%)
Mutual labels:  n-api
Node Webrtc
node-webrtc is a Node.js Native Addon that provides bindings to WebRTC M87
Stars: ✭ 2,258 (+14012.5%)
Mutual labels:  n-api
glfwJS
The N-API bindings for GLFW
Stars: ✭ 49 (+206.25%)
Mutual labels:  n-api
DCGAN-CelebA-PyTorch-CPP
DCGAN Implementation using PyTorch in both C++ and Python
Stars: ✭ 14 (-12.5%)
Mutual labels:  libtorch
Torch-TensorRT
PyTorch/TorchScript compiler for NVIDIA GPUs using TensorRT
Stars: ✭ 1,216 (+7500%)
Mutual labels:  libtorch
PyTorchTOP
GPU PyTorch TOP in TouchDesigner with CUDA-enabled OpenCV
Stars: ✭ 58 (+262.5%)
Mutual labels:  libtorch
pytorch-cpp
Just messing around with PyTorch 1.0's JIT compiler and their new C++ API Libtorch.
Stars: ✭ 17 (+6.25%)
Mutual labels:  libtorch
onnx tensorrt project
Support Yolov5(4.0)/Yolov5(5.0)/YoloR/YoloX/Yolov4/Yolov3/CenterNet/CenterFace/RetinaFace/Classify/Unet. use darknet/libtorch/pytorch/mxnet to onnx to tensorrt
Stars: ✭ 145 (+806.25%)
Mutual labels:  libtorch
YoloV5-LibTorch
一个 C++ 版本的 YoloV5 封装库
Stars: ✭ 77 (+381.25%)
Mutual labels:  libtorch
libdeepvac
Use PyTorch model in C++ project
Stars: ✭ 98 (+512.5%)
Mutual labels:  libtorch
SemanticSegmentation-Libtorch
Libtorch Examples
Stars: ✭ 38 (+137.5%)
Mutual labels:  libtorch

LibtorchJS

Simple Node.js N-API module that wraps few pieces of pytorch C++ library (libtorch) to allow loading and running pytorch-trained models in Node.js.

Node.js non-blocking model is great for scheduling heavy computational tasks such as NN inference. This wrapper provides async methods that do not block event loop, so it's possible to use it in a web-service.

This module was made just for fun, to check if it's easily possible to create image style transfer app with Node.js.

Installation

With npm: npm i --save libtorchjs

Module binary is pre-built and published using node-pre-gyp so it's not required to download libtorch/pytorch or install build tools.

Currently, Linux & Windows builds are available.

Usage Example

const torch = require('libtorchjs');

const input = torch.randn([1, 3, 224, 224]);
torch.load('model.pt', function(err, model) {
    model.forward(input, function(err, result) {
        const output = result.toUint8Array();
        console.log(output);
    });
});

API

The overall goal is to mirror pytorch API where possible. Currently just a few methods are exposed.

Tensor

ones(Array shape)

Create tensor of specified shape filled with 1's (autograd is disabled) and return Tensor object.

randn(Array shape)

Create tensor of specified shape (autograd is disabled) filled with random values in (0..1) range.

ScriptModule

load(String filename, callback)

Load traced model async from file and return resulting ScripModule.

forward(Tensor tensor, callback)

Forward tensor async and return resulting Tensor.

Acknowledgments

Following resources were extremely useful for creating this module:

Possible Future

  • Expose more of libtorch
  • Promisify libtorchjs API
  • GPU support
  • Windows ✔️, Mac support
  • Use travis/appveyor for automatic builds
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].