Code Monkey home page Code Monkey logo

idn-torchjs's Introduction

torchjs

Requirements:

sudo apt install g++ cmake unzip

Currently only support linux x86_64.

npm install @idn/torchjs

Export model from pytorch:

import torch
import torchvision

# An instance of your model.
model = torchvision.models.resnet18(pretrained=True)

# An example input you would normally provide to your model's forward() method.
example = torch.rand(1, 3, 224, 224)

# Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing.
traced_script_module = torch.jit.trace(model, example)

traced_script_module.save("resnet18.pt")

Example:

var torchjs = require('@idn/torchjs');
var script_module = new torchjs.ScriptModule('resnet18.pt');
var tensor = torchjs.ones([1, 3, 224, 224], false);

const { performance } = require('perf_hooks');

// Comment this out if you don't have cuda
script_module.cuda();
let start, end;
start = performance.now();
let otensor = script_module.forward(tensor);
end = performance.now();
console.log(`      gpu: ${end - start} ms`);

idn-torchjs's People

Contributors

steerapi avatar

Stargazers

Carmine DiMascio avatar Andrew Carr avatar mrjj avatar Hoàng Tùng Lâm (Linus) avatar

Watchers

James Cloos avatar

idn-torchjs's Issues

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.