• Stars
    star
    107
  • Rank 321,651 (Top 7 %)
  • Language
    C++
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A brief of TorchScript by MNIST

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

More Repositories

1

minetorch

Build deep learning applications in a new and easy way.
Python
236
star
2

center-loss.pytorch

center loss for face recognition
Python
177
star
3

sfd.pytorch

S3FD: single shot face detector in pytorch
Jupyter Notebook
115
star
4

dsb

kaggle 2018 data science bowl competition
Python
24
star
5

exhaustive-weighted-random-sampler

The missing distributed weighted random sampler for PyTorch
Python
24
star
6

reef-solution

reef-solution for upload
Python
23
star
7

ai4code

ai4code competition source code
Python
18
star
8

gradio-log

A Gradio component designed to continuously show any logs.
Python
14
star
9

pytorch-tao

tao for machine learning
Python
12
star
10

focal-loss.pytorch

Focal loss implemention by PyTorch
Python
11
star
11

BiSeNet.pytorch

BiSeNet in pytorch
Python
10
star
12

nvjpeg2k-python

NVJPEG2K python binding
C++
9
star
13

rsna-2022-public

RSNA Screening Mammography Breast Cancer Detection 26 th source code
Python
6
star
14

torch-serve-mnist

torch-serve-mnist example
Python
4
star
15

featurize-doc

document of featurize
Ruby
3
star
16

gislr-live

Live Demo of Google - Isolated Sign Language Recognition
JavaScript
3
star
17

pytorch-tricks

Jupyter Notebook
3
star
18

tornado-resource-handler

tornado resource handler
Python
1
star
19

voc2012-dataset.torch

Pytorch Dataset and other utils for VOC2012 dataset
Jupyter Notebook
1
star
20

collector-go

log collector in go
Go
1
star
21

maskrcnn.pytorch

mask rcnn implemented by pytorch
Python
1
star
22

aio-scheduler

This is async io scheduler based on redis
Python
1
star
23

featurize-tensorboard

在 Featurize 中使用 TensorBoard
Python
1
star
24

simple-uploader

Resumable file upload service
Go
1
star