Code Monkey home page Code Monkey logo

pytorch_cpp's Introduction

PyTorch C++ Samples

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.

Requirement

1. PyTorch C++

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


PyTorch Build : Stable (1.6.0)
Your OS : Linux
Package : LibTorch
CUDA : 10.2
Run this Command : Download here (cxx11 ABI)
GPU : https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.6.0.zip
CPU : https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.6.0%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

version : 4.5 (It works on other versions.)
This is used to load data in parallel.
It may be installed on standard Linux OS.

4. Boost

version : 1.65.1 (It works on other versions.)
This is used for command line arguments, etc.

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

5. Gnuplot

version : 5.2 (It works on other versions.)
This is used to display loss graph.

$ sudo apt install gnuplot

6. libpng

version : 0.2 (It works on other versions.)
This is used to load and save index-color image in semantic segmentation.

$ sudo apt install libpng++-dev

Preparation

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. Execution

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

Utility

1. Making Original Dataset

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

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

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

$ vi hold_out.sh

Please edit the file for original dataset.

#!/bin/bash

python3 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 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 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

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

Watchers

 avatar

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.