All Projects → yasenh → Libtorch Yolov5

yasenh / Libtorch Yolov5

Licence: mit
A LibTorch inference implementation of the yolov5

Labels

Projects that are alternatives of or similar to Libtorch Yolov5

Fbpic
Spectral, quasi-3D Particle-In-Cell code, for CPU and GPU
Stars: ✭ 111 (-12.6%)
Mutual labels:  gpu
Impala
An imperative and functional programming language
Stars: ✭ 118 (-7.09%)
Mutual labels:  gpu
Hiveos Linux
Hive OS client for GPU rigs
Stars: ✭ 119 (-6.3%)
Mutual labels:  gpu
Ds bowl 2018
Kaggle Data Science Bowl 2018
Stars: ✭ 116 (-8.66%)
Mutual labels:  gpu
Ivy
The templated deep learning framework, enabling framework-agnostic functions, layers and libraries.
Stars: ✭ 118 (-7.09%)
Mutual labels:  gpu
Pyhpc Benchmarks
A suite of benchmarks to test the sequential CPU and GPU performance of most popular high-performance libraries for Python.
Stars: ✭ 119 (-6.3%)
Mutual labels:  gpu
Futhark
💥💻💥 A data-parallel functional programming language
Stars: ✭ 1,641 (+1192.13%)
Mutual labels:  gpu
Deeprecommender
Deep learning for recommender systems
Stars: ✭ 1,593 (+1154.33%)
Mutual labels:  gpu
Deepway
This project is an aid to the blind. Till date there has been no technological advancement in the way the blind navigate. So I have used deep learning particularly convolutional neural networks so that they can navigate through the streets.
Stars: ✭ 118 (-7.09%)
Mutual labels:  gpu
Yudisplacementtransition
A GPU accelerated transition library makes use of displacement maps to create distortion effects.
Stars: ✭ 121 (-4.72%)
Mutual labels:  gpu
Thorin
The Higher-Order Intermediate Representation
Stars: ✭ 116 (-8.66%)
Mutual labels:  gpu
Pex Context
Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
Stars: ✭ 117 (-7.87%)
Mutual labels:  gpu
Context
ConText v4: Neural networks for text categorization
Stars: ✭ 120 (-5.51%)
Mutual labels:  gpu
Tensorflow Object Detection Tutorial
The purpose of this tutorial is to learn how to install and prepare TensorFlow framework to train your own convolutional neural network object detection classifier for multiple objects, starting from scratch
Stars: ✭ 113 (-11.02%)
Mutual labels:  gpu
Onemkl
oneAPI Math Kernel Library (oneMKL) Interfaces
Stars: ✭ 122 (-3.94%)
Mutual labels:  gpu
Blazingsql
BlazingSQL is a lightweight, GPU accelerated, SQL engine for Python. Built on RAPIDS cuDF.
Stars: ✭ 1,652 (+1200.79%)
Mutual labels:  gpu
Gpu Motunui
GPU-Motunui is a path tracer that renders Disney Animation's Moana Island scene.
Stars: ✭ 120 (-5.51%)
Mutual labels:  gpu
Shadergum
Unity3D GPU Sculpt & Morph
Stars: ✭ 125 (-1.57%)
Mutual labels:  gpu
Finitediff.jl
Fast non-allocating calculations of gradients, Jacobians, and Hessians with sparsity support
Stars: ✭ 123 (-3.15%)
Mutual labels:  gpu
Pixelfarm
From Vectors to (sub) Pixels, C# 2D Rendering Library
Stars: ✭ 120 (-5.51%)
Mutual labels:  gpu

Introduction

A LibTorch inference implementation of the yolov5 object detection algorithm. Both GPU and CPU are supported.

Dependencies

  • Ubuntu 16.04
  • CUDA 10.2
  • OpenCV 3.4.12
  • LibTorch 1.6.0

TorchScript Model Export

Please refer to the official document here: https://github.com/ultralytics/yolov5/issues/251

Mandatory Update: developer needs to modify following code from the original export.py in yolov5

# line 29
model.model[-1].export = False

Add GPU support: Note that the current export script in yolov5 uses CPU by default, the "export.py" needs to be modified as following to support GPU:

# line 28
img = torch.zeros((opt.batch_size, 3, *opt.img_size)).to(device='cuda')  
# line 31
model = attempt_load(opt.weights, map_location=torch.device('cuda'))

Export a trained yolov5 model:

cd yolov5
export PYTHONPATH="$PWD"  # add path
python models/export.py --weights yolov5s.pt --img 640 --batch 1  # export

Setup

$ cd /path/to/libtorch-yolo5
$ wget https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.6.0.zip
$ unzip libtorch-cxx11-abi-shared-with-deps-1.6.0.zip
$ mkdir build && cd build
$ cmake .. && make

To run inference on examples in the ./images folder:

# CPU
$ ./libtorch-yolov5 --source ../images/bus.jpg --weights ../weights/yolov5s.torchscript.pt --view-img
# GPU
$ ./libtorch-yolov5 --source ../images/bus.jpg --weights ../weights/yolov5s.torchscript.pt --gpu --view-img
# Profiling
$ CUDA_LAUNCH_BLOCKING=1 ./libtorch-yolov5 --source ../images/bus.jpg --weights ../weights/yolov5s.torchscript.pt --gpu --view-img

Demo

Bus

Zidane

FAQ

  1. terminate called after throwing an instance of 'c10::Error' what(): isTuple() INTERNAL ASSERT FAILED
  • Make sure "model.model[-1].export = False" when running export script.
  1. Why the first "inference takes" so long from the log?

    • The first inference is slower as well due to the initial optimization that the JIT (Just-in-time compilation) is doing on your code. This is similar to "warm up" in other JIT compilers. Typically, production services will warm up a model using representative inputs before marking it as available.

    • It may take longer time for the first cycle. The yolov5 python version run the inference once with an empty image before the actual detection pipeline. User can modify the code to process the same image multiple times or process a video to get the valid processing time.

References

  1. https://github.com/ultralytics/yolov5
  2. Question about the code in non_max_suppression
  3. https://github.com/walktree/libtorch-yolov3
  4. https://pytorch.org/cppdocs/index.html
  5. https://github.com/pytorch/vision
  6. PyTorch.org - CUDA SEMANTICS
  7. PyTorch.org - add synchronization points
  8. PyTorch - why first inference is slower
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].