Git Product home page Git Product logo

libtorchdetection's Introduction

logo C++ Library with Neural Networks for Object
Detection Based on LibTorch.

Visit Libtorch Tutorials Project if you want to know more about Libtorch Detection library.

๐Ÿ“‹ Table of content

  1. Examples
  2. Train your own data
  3. Installation
  4. To do list
  5. Thanks
  6. Citing
  7. License
  8. Related repository

๐Ÿ’ก Examples

  1. Download the VOC image dataset, and split the dataset into train and val parts as follows:
dataset
โ”œโ”€โ”€ train
โ”‚   โ”œโ”€โ”€ images
|   |     โ”œโ”€โ”€xxx.jpg
|   |     โ””......
โ”‚   โ”œโ”€โ”€ labels
|   |     โ”œโ”€โ”€xxx.xml
|   |     โ””......
โ”œโ”€โ”€ val
โ”‚   โ”œโ”€โ”€ images
|   |     โ”œโ”€โ”€zzz.jpg
|   |     โ””......
โ”‚   โ”œโ”€โ”€ labels
|   |     โ”œโ”€โ”€zzz.xml
|   |     โ””......
  1. Download the yolo4_tiny pretrained weight here. And load it into your cpp project as follows:
Detector detector;
detector.Initialize(-1, /*gpu id, -1 for cpu*/
                    416, /*resize width*/
                    416, /*resize height*/
                    "your path to class name.txt");
detector.Train("your path to dataset dir", 
                    ".jpg", /*image type*/
                    30,/*training epochs*/
                    4, /*batch size*/
                    0.001, /*learning rate*/
                    "path to save detector.pt",
                    "path to load pretrained yolo4_tiny.pt");
  1. Predicting test. A detector.pt file is provided in the project here (trained on VOC for one epoch, just for testing...). Click and download, then you can directly test the detection result through:
cv::Mat image = cv::imread("your path to 2007_005331.jpg");
Detector detector;
detector.Initialize(0, 416, 416, "your path to voc_classes.txt");
detector.LoadWeight("detector.pt"/*the saved .pt path*/);
detector.Predict(image, true,/*show result or not*/, 0.1, /*confidence thresh*/, 0.3/*nms thresh*/);

the predicted result shows as follow:

๐Ÿง‘โ€๐Ÿš€ Train your own data

  • Create your own dataset. Using labelImg through "pip install" and label your images. Split the output xml files and images into folders just like the example above.

  • Training or testing. Just like the example of VOC detection, replace with your own dataset path.

๐Ÿ›  Installation

Dependency:

Windows:

Configure the environment for libtorch development. Visual studio and Qt Creator are verified for libtorch1.7+.

Linux && MacOS:

Install libtorch and opencv.

For libtorch, follow the official pytorch c++ tutorials here.

For opencv, follow the official opencv install steps here.

If you have already configured them both, congratulations!!! Download the pretrained weight here and a demo .pt file here into weights. Change the CMAKE_PREFIX_PATH to your own in CMakeLists.txt. Then just do the following:

cd build
cmake ..
make
./LibtorchDetection

โณ ToDo

  • More detection architectures, mainly one-stage algorithms.
  • Data augmentations.
  • Training tricks.

๐Ÿค Thanks

This project is under developing. By now, these projects helps a lot.

๐Ÿ“ Citing

@misc{Chunyu:2021,
  Author = {Chunyu Dong},
  Title = {Libtorch Detection},
  Year = {2021},
  Publisher = {GitHub},
  Journal = {GitHub repository},
  Howpublished = {\url{https://github.com/AllentDan/LibtorchDetection}}
}

๐Ÿ›ก๏ธ License

Project is distributed under MIT License.

Related repository

Based on libtorch, I released following repositories:

Last but not least, don't forget your star...

Feel free to commit issues or pull requests, contributors wanted.

libtorchdetection's People

Contributors

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