项目作者: AllentDan

项目描述 :
C++ trainable detection library based on libtorch (or pytorch c++). Yolov4 tiny provided now.
高级语言: C++
项目地址: git://github.com/AllentDan/LibtorchDetection.git
创建时间: 2021-05-04T16:13:10Z
项目社区:https://github.com/AllentDan/LibtorchDetection

开源协议:MIT License

下载




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

📚 Libtorch Tutorials 📚

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

" class="reference-link">💡 Examples

  1. Download the VOC image dataset, and split the dataset into train and val parts as follows:

    1. dataset
    2. ├── train
    3. ├── images
    4. | | ├──xxx.jpg
    5. | | └......
    6. ├── labels
    7. | | ├──xxx.xml
    8. | | └......
    9. ├── val
    10. ├── images
    11. | | ├──zzz.jpg
    12. | | └......
    13. ├── labels
    14. | | ├──zzz.xml
    15. | | └......
  2. Download the yolo4_tiny pretrained weight here. And load it into your cpp project as follows:

    1. Detector detector;
    2. detector.Initialize(-1, /*gpu id, -1 for cpu*/
    3. 416, /*resize width*/
    4. 416, /*resize height*/
    5. "your path to class name.txt");
    6. detector.Train("your path to dataset dir",
    7. ".jpg", /*image type*/
    8. 30,/*training epochs*/
    9. 4, /*batch size*/
    10. 0.001, /*learning rate*/
    11. "path to save detector.pt",
    12. "path to load pretrained yolo4_tiny.pt");
  3. 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:

    1. cv::Mat image = cv::imread("your path to 2007_005331.jpg");
    2. Detector detector;
    3. detector.Initialize(0, 416, 416, "your path to voc_classes.txt");
    4. detector.LoadWeight("detector.pt"/*the saved .pt path*/);
    5. detector.Predict(image, true,/*show result or not*/, 0.1, /*confidence thresh*/, 0.3/*nms thresh*/);

    the predicted result shows as follow:

" class="reference-link">🧑‍🚀 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.

" class="reference-link">🛠 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. Then just do the following:

  1. export Torch_DIR='/path/to/libtorch'
  2. cd build
  3. cmake ..
  4. make
  5. ./LibtorchDetection

" class="reference-link">⏳ ToDo

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

" class="reference-link">🤝 Thanks

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

📝 Citing

  1. @misc{Chunyu:2021,
  2. Author = {Chunyu Dong},
  3. Title = {Libtorch Detection},
  4. Year = {2021},
  5. Publisher = {GitHub},
  6. Journal = {GitHub repository},
  7. Howpublished = {\url{https://github.com/AllentDan/LibtorchDetection}}
  8. }

" class="reference-link">🛡️ License

Project is distributed under MIT License.

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.