• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    C++
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 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
239
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
114
star
4

gradio-log

A Gradio component designed to continuously show any logs.
Python
25
star
5

dsb

kaggle 2018 data science bowl competition
Python
24
star
6

exhaustive-weighted-random-sampler

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

reef-solution

reef-solution for upload
Python
23
star
8

ai4code

ai4code competition source code
Python
18
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

featurize-comfyui

Python
1
star
19

hcho-bill

Jupyter Notebook
1
star
20

tornado-resource-handler

tornado resource handler
Python
1
star
21

collector-go

log collector in go
Go
1
star
22

maskrcnn.pytorch

mask rcnn implemented by pytorch
Python
1
star
23

aio-scheduler

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

voc2012-dataset.torch

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

featurize-tensorboard

ๅœจ Featurize ไธญไฝฟ็”จ TensorBoard
Python
1
star
26

simple-uploader

Resumable file upload service
Go
1
star