New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

libtorchjs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libtorchjs

Node.js N-API wrapper for Libtorch

  • 1.0.0-alpha.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 :heavy_check_mark:, Mac support
  • Use travis/appveyor for automatic builds

Keywords

FAQs

Package last updated on 24 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc