GithubHelp home page GithubHelp logo

java-demo's Introduction

PyTorch Java Demo

This repository is a demonstration of how to use PyTorch from Java.

Setup

Download and unpack libtorch nightly (or 1.4 or greater). From the pytorch.org homepage under "Quick Start Locally", make sure "LibTorch" is the selected package. Linux is supported as of version 1.4. Mac is supported as of version 1.5. Windows is supported as of version 1.9. All are both supported in nightly builds.

Run export LIBTORCH_HOME=/path/to/libtorch. The build.gradle file will use this to set java.library.path when running the application. If you are using PyTorch in your own environment, LIBTORCH_HOME is not necessary. Instead, you will need to set java.library.path to /path/to/libtorch/lib.

It might be necessary to set the JAVA_HOME environment variable. On Mac, use export JAVA_HOME=$(/usr/libexec/java_home). On Windows, with GitHub bash, try export JAVA_HOME=/c/Progra~1/Java/jdk-*

On Mac, you might get security errors. You must manually approve execution for each library under libtorch. As a shortcut, xattr -r -d /path/to/libtorch/lib might work.

On Windows, you will probably need to run export PATH="$LIBTORCH_HOME/lib:$PATH".

If using a nightly build, run export USE_LIBTORCH_NIGHTLY=1.

Run ./gradlew run to build and run the demo application. It will load demo-model.pt and run it on some simple data. This notebook was used to generate the model.

More information about the Java API and TorchScript:

java-demo's People

Contributors

dreiss avatar facebook-github-bot avatar

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.