Giter Club home page Giter Club logo

pytorch_cpp's Introduction

PyTorch C++ Samples

Language LibTorch

These are Deep Learning sample programs of PyTorch written in C++.

Description

PyTorch is famous as a kind of Deep Learning Frameworks.
Among them, Python source code is overflowing on the Web, so we can easily write the source code of Deep Learning in Python.
However, there is very little source code written in C++ of compiler language.
Therefore, I hope this repository will help many programmers by providing PyTorch sample programs written in C++.
In addition, I might adapt programs to the latest version.

Updates

06/27,2023: Release of v2.0.1
06/27,2023: Create the heatmap for Anomaly Detection
05/07,2023: Release of v2.0.0
03/01,2023: Release of v1.13.1
09/12,2022: Release of v1.12.1
08/04,2022: Release of v1.12.0
03/18,2022: Release of v1.11.0
02/10,2022: Release of v1.10.2
02/09,2022: Implementation of YOLOv3
01/09,2022: Release of v1.10.1

See more...

01/09,2022: Fixed execution error in test on CPU package
11/12,2021: Release of v1.10.0
09/27,2021: Release of v1.9.1
09/27,2021: Support for using different devices between training and test
09/06,2021: Improved accuracy of time measurement using GPU
06/19,2021: Release of v1.9.0
03/29,2021: Release of v1.8.1
03/18,2021: Implementation of Discriminator from DCGAN
03/17,2021: Implementation of AE1d
03/16,2021: Release of v1.8.0
03/15,2021: Implementation of YOLOv2
02/11,2021: Implementation of YOLOv1
01/21,2021: Release of v1.7.1
10/30,2020: Release of v1.7.0
10/04,2020: Implementation of Skip-GANomaly2d
10/03,2020: Implementation of GANomaly2d
09/29,2020: Implementation of EGBAD2d
09/28,2020: Implementation of AnoGAN2d
09/27,2020: Implementation of SegNet
09/26,2020: Implementation of DAE2d
09/13,2020: Implementation of ResNet
09/07,2020: Implementation of VGGNet
09/05,2020: Implementation of AlexNet
09/02,2020: Implementation of WAE2d GAN and WAE2d MMD
08/30,2020: Release of v1.6.0
06/26,2020: Implementation of DAGMM2d
06/26,2020: Release of v1.5.1
06/26,2020: Implementation of VAE2d and DCGAN
06/01,2020: Implementation of pix2pix
05/29,2020: Implementation of U-Net Classification
05/26,2020: Implementation of U-Net Regression
04/24,2020: Release of v1.5.0
03/23,2020: Implementation of AE2d

Implementation

Details

Multiclass Classification

Model Paper Conference/Journal Code Release Version
AlexNet A. Krizhevsky et al. NeurIPS 2012 AlexNet v1.7.0
VGGNet K. Simonyan et al. ICLR 2015 VGGNet v1.7.0
ResNet K. He et al. CVPR 2016 ResNet v1.7.0
Discriminator A. Radford et al. ICLR 2016 Discriminator v1.8.1

Dimensionality Reduction

Model Paper Conference/Journal Code Release Version
Autoencoder G. E. Hinton et al. Science 2006 AE1d v1.8.1
AE2d v1.5.0
Denoising Autoencoder P. Vincent et al. ICML 2008 DAE2d v1.7.0

Generative Modeling

Model Paper Conference/Journal Code Release Version
Variational Autoencoder D. P. Kingma et al. ICLR 2014 VAE2d v1.5.1
DCGAN A. Radford et al. ICLR 2016 DCGAN v1.5.1
Wasserstein Autoencoder I. Tolstikhin et al. ICLR 2018 WAE2d GAN v1.7.0
WAE2d MMD

Image-to-Image Translation

Model Paper Conference/Journal Code Release Version
U-Net O. Ronneberger et al. MICCAI 2015 U-Net Regression v1.5.1
pix2pix P. Isola et al. CVPR 2017 pix2pix v1.5.1

Semantic Segmentation

Model Paper Conference/Journal Code Release Version
SegNet V. Badrinarayanan et al. CVPR 2015 SegNet v1.7.0
U-Net O. Ronneberger et al. MICCAI 2015 U-Net Classification v1.5.1

Object Detection

Model Paper Conference/Journal Code Release Version
YOLOv1 J. Redmon et al. CVPR 2016 YOLOv1 v1.8.0
YOLOv2 J. Redmon et al. CVPR 2017 YOLOv2 v1.8.0
YOLOv3 J. Redmon et al. arXiv 2018 YOLOv3 v1.10.2

Anomaly Detection

Model Paper Conference/Journal Code Release Version
AnoGAN T. Schlegl et al. IPMI 2017 AnoGAN2d v1.7.0
DAGMM B. Zong et al. ICLR 2018 DAGMM2d v1.6.0
EGBAD H. Zenati et al. ICLR Workshop 2018 EGBAD2d v1.7.0
GANomaly S. Akçay et al. ACCV 2018 GANomaly2d v1.7.0
Skip-GANomaly S. Akçay et al. IJCNN 2019 Skip-GANomaly2d v1.7.0

Requirement

Details

1. PyTorch C++

Please select the environment to use as follows on PyTorch official.
PyTorch official : https://pytorch.org/


PyTorch Build : Stable (2.0.1)
Your OS : Linux
Package : LibTorch
Language : C++ / Java
Run this Command : Download here (cxx11 ABI)
CUDA 11.7 : https://download.pytorch.org/libtorch/cu117/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcu117.zip
CUDA 11.8 : https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcu118.zip
CPU : https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcpu.zip


2. OpenCV

version : 3.0.0 or more
This is used for pre-processing and post-processing.
Please refer to other sites for more detailed installation method.

3. OpenMP

This is used to load data in parallel.
(It may be installed on standard Linux OS.)

4. Boost

This is used for command line arguments, etc.

$ sudo apt install libboost-dev libboost-all-dev

5. Gnuplot

This is used to display loss graph.

$ sudo apt install gnuplot

6. libpng/png++/zlib

This is used to load and save index-color image in semantic segmentation.

$ sudo apt install libpng-dev libpng++-dev zlib1g-dev

Preparation

Details

1. Git Clone

$ git clone https://github.com/koba-jon/pytorch_cpp.git
$ cd pytorch_cpp

2. Path Setting

$ vi utils/CMakeLists.txt

Please change the 4th line of "CMakeLists.txt" according to the path of the directory "libtorch".
The following is an example where the directory "libtorch" is located directly under the directory "HOME".

3: # LibTorch
4: set(LIBTORCH_DIR $ENV{HOME}/libtorch)
5: list(APPEND CMAKE_PREFIX_PATH ${LIBTORCH_DIR})

3. Compiler Install

If you don't have g++ version 8 or above, install it.

$ sudo apt install g++-8

4. Execution

Please move to the directory of each model and refer to "README.md".

Utility

Details

1. Making Original Dataset

Please create a link for the original dataset.
The following is an example of "AE2d" using "celebA" Dataset.

$ cd Dimensionality_Reduction/AE2d/datasets
$ ln -s <dataset_path> ./celebA_org

You should substitute the path of dataset for "<dataset_path>".
Please make sure you have training or test data directly under "<dataset_path>".

$ vi ../../../scripts/hold_out.sh

Please edit the file for original dataset.

#!/bin/bash

SCRIPT_DIR=$(cd $(dirname $0); pwd)

python3 ${SCRIPT_DIR}/hold_out.py \
    --input_dir "celebA_org" \
    --output_dir "celebA" \
    --train_rate 9 \
    --valid_rate 1

By running this file, you can split it into training and validation data.

$ sudo apt install python3 python3-pip
$ pip3 install natsort
$ sh ../../../scripts/hold_out.sh
$ cd ../../..

2. Data Input System

There are transform, dataset and dataloader for data input in this repository.
It corresponds to the following source code in the directory, and we can add new function to the source code below.

  • transforms.cpp
  • transforms.hpp
  • datasets.cpp
  • datasets.hpp
  • dataloader.cpp
  • dataloader.hpp

3. Check Progress

There are a feature to check progress for training in this repository.
We can watch the number of epoch, loss, time and speed in training.
util1
It corresponds to the following source code in the directory.

  • progress.cpp
  • progress.hpp

4. Monitoring System

There are monitoring system for training in this repository.
We can watch output image and loss graph.
The feature to watch output image is in the "samples" in the directory "checkpoints" created during training.
The feature to watch loss graph is in the "graph" in the directory "checkpoints" created during training.
util2
It corresponds to the following source code in the directory.

  • visualizer.cpp
  • visualizer.hpp

License

Details

You can feel free to use all source code in this repository.
(Click here for details.)

But if you exploit external libraries (e.g. redistribution), you should be careful.
At a minimum, the license notation at the following URL is required.
In addition, third party copyrights belong to their respective owners.

Conclusion

I hope this repository will help many programmers by providing PyTorch sample programs written in C++.
If you have any problems with the source code of this repository, please feel free to "issue".
Let's have a good development and research life!

pytorch_cpp's People

Contributors

koba-jon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytorch_cpp's Issues

Training in C++?

Hey, you have showed such an amazing work to train NNs in C++.
I would like to know what are the reasons for which you started training models in C++ instead of python? Because once the model definition has been written in pytorch in python and data pipeline has been setup, all the computation needs to be done will be done on GPU. So there wont be much drastic performance gains when migrating from python to c++. Please tell me some of your thoughts on this.

plan?

Do you have a plan to implement Libtorch version YOLOV4 or YOLOV5 or YOLOX can be trained?

Statically building pix2pix

Hi!
I want to be able to run pix2pix in SGX, but SGX only supports statically linked programs. So I was wondering if you think it would be possible to build pix2pix statically? I would need the *.a files instead of the *.so files for each of the dependencies, but where do I make the changes in the cmake files for this? Thank you so much for your help!

Temporal Convolution Network (TCN)

I checked your examples but I still cannot figure out how to build TCN using Pytorch C++.
Can you give me guidance?
or It would be great if the TCN example is added.
Thank you

build failing

Hi,
I'm trying to build this project according to the given instructions, but the make fails because it says it needs -std=c++11 support. Where do I add this flag? I do not have g++-8 (I'm not able to install it, so I have to work with g++-5).
Thank you so much!

About AE1d

Hello,
No can find the RBM code, you not use it ad in original paper?

AE2d test() throws exception on non-GPU environment

Hello. I tried to run test.sh of Dimensionality_Reduction/AE2d on my PC which doesn't have GPU, but failed with the below error message.

terminate called after throwing an instance of 'c10::Error'
  what():  No CUDA GPUs are available

It's because test() in AE2d/test.cpp calls torch::cuda::synchronize() regardless of device type. I think it should be called only on GPU environment. For example:

        if (!device.is_cpu()) torch::cuda::synchronize();

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.