Giter Site home page Giter Site logo

torchscript-demos's Introduction

torchscript-demos

A brief of TorchScript by MNIST and YOLOv5.

Requirements

Any x86 arch CPU and UNIX like system should work.

For training in Python

  • Python==3.7+
  • PyTorch==1.8.1
  • MineTorch==0.6.12

For inference in C++

  • cmake
  • LibTorch
  • OpenCV

Installation

This guide will cover the part of the LibTorch and OpenCV installation and assume other things are already installed. Everything will installed within directory of the repo so uninstallation will be the same as removing the whole directory.

  1. Clone this repo.
git clone https://github.com/louis-she/torchscript-demos.git
cd torchscript-demos
  1. Install OpenCV
# In repo base dir
git clone --branch 3.4 --depth 1 https://github.com/opencv/opencv.git
mkdir opencv/build && cd opencv/build
cmake ..
make -j 4
  1. Download LibTorch
# In repo base dir
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
unzip libtorch-shared-with-deps-latest.zip
  1. Clone YOLOv5(Optional)

Required if you want to try the YOLOv5 example.

git clone https://github.com/ultralytics/yolov5

MNIST

1. Training

# In repo base dir
python3 train.py

Use ctrl + C to stop training process, the training log and graphs can be found at ./alchemistic_directory/baseline.

2. Build binary

# In repo base dir

# Dump TorchScript Module file `./jit_module.pth`
python3 jit_extract.py

# Build C++ binary `./build/mnist`
mkdir build && cd build
cmake .. -DTARGET=mnist
make

3. Make inference with the binary

# In repo base dir
./build/mnist jit_module.pth six.jpg

# Output: The number is: 6

YOLOv5

1. Build binary

# In repo base dir

# Build C++ binary `./build/mnist`
mkdir build && cd build
cmake .. -DTARGET=yolov5
make

2. Export TorchScript module

# In YOLOv5 base dir
python export.py --weights yolov5s.pt --img 640 --batch 1

# Then copy the yolov5s.torchscript to base dir of this repo

3. Make inference with the binary

# In base dir

./build/yolov5 yolov5s.torchscript bus.jpg

torchscript-demos's People

Contributors

louis-she avatar

Stargazers

KernelInterrupt avatar Frances avatar Jiang Tao avatar Zhizhou Sha avatar XueWang avatar 五档起步杰 avatar CaMi1le avatar Plwy avatar Satellite avatar  avatar JrunDing avatar Steel Shen avatar  avatar  avatar  avatar  avatar Hua Gao avatar Steven Cole avatar Lin Li avatar Johan Liu avatar fisher87. avatar Yinqiang Zhang avatar Rex avatar  avatar  avatar  avatar Jason Sun avatar yutian yu avatar  avatar WeiHong Sung avatar 精神病好多了 avatar  avatar  avatar qiutzh avatar Yu Zhou avatar  avatar Konnase Lee avatar Feng Xiong avatar  avatar yoro99 avatar shengxiaolin avatar  avatar  avatar Zz avatar Jingu Xie avatar 2.5 Dimensional Seeker avatar  avatar Liqian Ma avatar lemon avatar XHwfs avatar  avatar Wadleigh avatar liuhuang31 avatar  avatar zxq avatar 冲弱 avatar  avatar  avatar  avatar  avatar  avatar  avatar Tong Zhao avatar  avatar  avatar midon avatar Jensen J. ZHANG avatar Li Kang avatar  avatar vince zeng avatar  avatar  avatar  avatar Zihe Gao avatar  avatar  avatar jiangliuer avatar zhihui wang avatar TankardYegga avatar  avatar Borui Zhang avatar Sijie Zhao avatar yy avatar verseRxyz avatar Hong JianYuan avatar  avatar Qiang avatar  avatar  avatar opsn avatar  avatar Qiu Jueqin avatar Shen Chen(陈燊) avatar Richard Plantagenet avatar Qinyuan Cheng avatar ADFPGA avatar  avatar Samuel avatar TensorDS avatar Sysdn avatar

Watchers

 avatar

torchscript-demos'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.