Skip to content

sami-badawi/java-demo

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 1 commit ahead, 5 commits behind pytorch:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

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. Linux and Mac are both supported in nightly builds. Windows is not supported at this time.

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.

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:

Example Setup for macOS with v 1.7.1

cd ~/code/java
wget https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.7.1.zip
unzip libtorch-macos-1.7.1.zip
export LIBTORCH_HOME="~/code/java/libtorch"
export USE_LIBTORCH_NIGHTLY=1
export JAVA_HOME=$(/usr/libexec/java_home)
./gradlew run

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 79.0%
  • Java 21.0%