This is a code repository for pytorch c++ (or libtorch) tutorial.

Overview

LibtorchTutorials

English version

环境

  • win10
  • visual sutdio 2017 或者Qt4.11.0
  • Libtorch 1.7
  • Opencv4.5

配置

libtorch+Visual Studiolibtorch+QT分别记录libtorch在VS和Qt的开发环境配置。

介绍

注意,这个项目不是直接利用torch::jit加载.pt模型预测,而是用c++构建深度学习模型,在c++中训练预测。

本教程旨在教读者如何用c++搭建模型,训练模型,根据训练结果预测对象。为便于教学和使用,本文的c++模型均使用libtorch(或者pytorch c++ api)完成搭建和训练等。目前,国内各大平台似乎没有pytorch在c++上api的完整教学,也没有基于c++开发的完整的深度学习开源模型。可能原因很多:

  1. c/c++的深度学习已经足够底层和落地,商用价值较高,开发难度偏大,一般不会开源;
  2. 基于python训练,libtorch预测的部署形式足够满足大多数项目的需求,如非产品级应用,不会有人愿意研究如何用c++从头搭建模型,实现模型训练功能;
  3. Tensorflow的市场份额,尤其时工业应用的部署下市场占比足够高,导致基于libtorch的开发和部署占比很小,所以未见开源。

本教程提供基于libtorch的c++开发的深度学习视觉模型教学,本教程的开发平台基于Windows环境和Visual Sutdio集成开发环境,实现三大深度视觉基本任务:分类,分割和检测。适用人群为:

  • 有c++基础,了解面向对象思维,
  • 有pytorch编程经验者。

章节安排

本教程分多个章节:

Issues
  • cuda 11.0  is not supported?

    cuda 11.0 is not supported?

    I download libtorch,and unzip it .

    libtorch/include/c10/cuda/CUDAStream.h:6:10: fatal error: cuda_runtime_api.h: No such file or directory #include <cuda_runtime_api.h> ^~~~~~~~~~~~~~~~~~~~ compilation terminated.

    why,tks

    opened by henbucuoshanghai 1
  • LibTorch使用cuda的问题

    LibTorch使用cuda的问题

    你好,我刚刚接触libtorch但在使用的过程中出现了问题。我使用gpu的时候在运行 "module.to(device_type);" 时出现了不动的问题。 情况如下图。在运行到81行给模型加载到gpu时出现了下面这种情况。 Snipaste_2021-12-27_17-12-08 在使用cpu时一切正常。 我的环境是 cuda10.2、cudnn(8.3.1 / 7.6.5)这两个版本都试过、libtorch1.8.0-release、VS2019、pytorch1.8.0。

    opened by wang8713 2
  • Libtorch推理时间问题

    Libtorch推理时间问题

    您好,非常感谢您提供的教程,我在利用RTX3080和训练好的模型推理过程中遇到这样的奇怪问题: 利用ros播放bag包, 程序从ros topic中获取, 第一次推理时间为0.2s,而后20次推理时间为12s左右,这之后的推理时间稳定在0.03s左右了,请问您有遇到过类似的现象吗?有什么好的解决办法呢?谢谢啦

    opened by oym1994 3
Support Yolov4/Yolov3/Centernet/Classify/Unet. use darknet/libtorch/pytorch to onnx to tensorrt

ONNX-TensorRT Yolov4/Yolov3/CenterNet/Classify/Unet Implementation Yolov4/Yolov3 centernet INTRODUCTION you have the trained model file from the darkn

null 162 Jul 24, 2022
C++ trainable detection library based on libtorch (or pytorch c++). Yolov4 tiny provided now.

C++ Library with Neural Networks for Object Detection Based on LibTorch. ?? Libtorch Tutorials ?? Visit Libtorch Tutorials Project if you want to know

null 48 Aug 11, 2022
LibtorchSegmentation - A c++ trainable semantic segmentation library based on libtorch (pytorch c++). Backbone: VGG, ResNet, ResNext. Architecture: FPN, U-Net, PAN, LinkNet, PSPNet, DeepLab-V3, DeepLab-V3+ by now.

English | 中文 C++ library with Neural Networks for Image Segmentation based on LibTorch. ⭐ Please give a star if this project helps you. ⭐ The main fea

null 281 Aug 6, 2022
ResNet Implementation, Training, and Inference Using LibTorch C++ API

LibTorch C++ ResNet CIFAR Example Introduction ResNet implementation, training, and inference using LibTorch C++ API. Because there is no native imple

Lei Mao 20 Jun 20, 2022
The MOT implement by Solov2+DeepSORT with C++ (Libtorch, TensorRT).

Tracking-Solov2-Deepsort This project implement the Multi-Object-Tracking(MOT) base on SOLOv2 and DeepSORT with C++。 The instance segmentation model S

ChenJianqu 31 Jul 1, 2022
The optical flow algorithm RAFT implemented with C++(Libtorch+TensorRT)

RAFT_CPP Attention/注意 There are some bug here,output the wrong result 代码存在bug,估计出来的光流值不准确,解决中 Quick Start 0.Export RAFT onnx model 首先加载训练完成的模型权重: pars

ChenJianqu 15 May 20, 2022
This repository is a tensorrt deployment of the onsets and frames model, which is implemented using pytorch.

Onsets and Frames TensorRT inference This repository is a tensorrt deployment of the onsets and frames model, which is implemented using pytorch (http

Xianke Wang 6 Jan 13, 2022
Official PyTorch Code of GrooMeD-NMS: Grouped Mathematically Differentiable NMS for Monocular 3D Object Detection (CVPR 2021)

GrooMeD-NMS: Grouped Mathematically Differentiable NMS for Monocular 3D Object Detection GrooMeD-NMS: Grouped Mathematically Differentiable NMS for Mo

Abhinav Kumar 75 Jul 31, 2022
GPU PyTorch TOP in TouchDesigner with CUDA-enabled OpenCV

PyTorchTOP This project demonstrates how to use OpenCV with CUDA modules and PyTorch/LibTorch in a TouchDesigner Custom Operator. Building this projec

David 65 Jun 15, 2022
Deep Learning API and Server in C++11 support for Caffe, Caffe2, PyTorch,TensorRT, Dlib, NCNN, Tensorflow, XGBoost and TSNE

Open Source Deep Learning Server & API DeepDetect (https://www.deepdetect.com/) is a machine learning API and server written in C++11. It makes state

JoliBrain 2.4k Aug 2, 2022
Fast, differentiable sorting and ranking in PyTorch

Torchsort Fast, differentiable sorting and ranking in PyTorch. Pure PyTorch implementation of Fast Differentiable Sorting and Ranking (Blondel et al.)

Teddy Koker 612 Jul 30, 2022
functorch is a prototype of JAX-like composable function transforms for PyTorch.

functorch Why functorch? | Install guide | Transformations | Future Plans functorch is a prototype of JAX-like composable FUNCtion transforms for pyTO

Richard Zou 1.1k Aug 6, 2022
functorch is a prototype of JAX-like composable function transforms for PyTorch.

functorch Why functorch? | Install guide | Transformations | Future Plans functorch is a prototype of JAX-like composable FUNCtion transforms for pyTO

Facebook Research 1.1k Aug 11, 2022
UE4 Plugin to execute trained PyTorch modules

SimplePyTorch UE4 Plugin to execute trained PyTorch modules ------- Packaging ------- Download PyTorch C++ distributions: https://pytorch.org/cppdocs/

null 41 Jun 28, 2022
A simple demonstration of how PyTorch autograd works

简单地演示了 PyTorch 中自动求导机制的原理。 官方博客:https://pytorch.org/blog/overview-of-pytorch-autograd-engine/ 编译运行 使用 Bazel bazel run autograd_test 包含了一个使用 MSE 损失函数的一

Howard Lau 14 Feb 24, 2022
An inofficial PyTorch implementation of PREDATOR based on KPConv.

PREDATOR: Registration of 3D Point Clouds with Low Overlap An inofficial PyTorch implementation of PREDATOR based on KPConv. The code has been tested

ZhuLifa 14 Aug 3, 2022
DLPrimitives/OpenCL out of tree backend for pytorch

Pytorch OpenCL backend based on dlprimitives DLPrimitives-OpenCL out of tree backend for pytorch It is only beginning, but you can train some vision n

Artyom Beilis 65 Aug 3, 2022
A external memory allocator example for PyTorch.

Custom PyTorch Memory Management This is a external memory allocator example for PyTorch. The underlying memory allocator is CNMeM. Usage Compile with

Zilin Zhu 12 Aug 2, 2022
A LLVM-based static analyzer to produce PyTorch operator dependency graph.

What is this? This is a clone of the deprecated LLVM-based static analyzer from the PyTorch repo, which can be used to produce the PyTorch operator de

Jiakai Liu 5 Dec 15, 2021