{"id":16270244,"url":"https://github.com/allentdan/libtorchdetection","last_synced_at":"2026-02-27T20:14:10.103Z","repository":{"id":43727596,"uuid":"364314886","full_name":"AllentDan/LibtorchDetection","owner":"AllentDan","description":"C++ trainable detection library based on libtorch (or pytorch c++). Yolov4 tiny provided now.","archived":false,"fork":false,"pushed_at":"2022-10-27T08:30:47.000Z","size":9017,"stargazers_count":110,"open_issues_count":7,"forks_count":40,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-09-02T09:38:15.798Z","etag":null,"topics":["cpp","detection","detection-model","libtorch","pretrained","pretrained-weights","pytorch","pytorch-cpp","yolo","yolov4","yolov4-tiny"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AllentDan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-04T16:13:10.000Z","updated_at":"2025-08-07T14:36:16.000Z","dependencies_parsed_at":"2022-09-17T00:11:31.273Z","dependency_job_id":null,"html_url":"https://github.com/AllentDan/LibtorchDetection","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/AllentDan/LibtorchDetection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AllentDan%2FLibtorchDetection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AllentDan%2FLibtorchDetection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AllentDan%2FLibtorchDetection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AllentDan%2FLibtorchDetection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AllentDan","download_url":"https://codeload.github.com/AllentDan/LibtorchDetection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AllentDan%2FLibtorchDetection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29911554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"ssl_error","status_checked_at":"2026-02-27T19:37:41.463Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","detection","detection-model","libtorch","pretrained","pretrained-weights","pytorch","pytorch-cpp","yolo","yolov4","yolov4-tiny"],"created_at":"2024-10-10T18:09:57.675Z","updated_at":"2026-02-27T20:14:10.076Z","avatar_url":"https://github.com/AllentDan.png","language":"C++","readme":"\u003cdiv align=\"center\"\u003e\n\n![logo](https://raw.githubusercontent.com/AllentDan/ImageBase/main/detection/libtorch_detection.png)\n**C++ Library with Neural Networks for Object  \nDetection Based on [LibTorch](https://pytorch.org/).**  \n\u003c/div\u003e\n\n### [📚 Libtorch Tutorials 📚](https://github.com/AllentDan/LibtorchTutorials)\n\nVisit [Libtorch Tutorials Project](https://github.com/AllentDan/LibtorchTutorials) if you want to know more about Libtorch Detection library.\n\n### 📋 Table of content\n 1. [Examples](#examples)\n 2. [Train your own data](#trainingOwn)\n 3. [Installation](#installation)\n 4. [To do list](#todo)\n 5. [Thanks](#thanks)\n 6. [Citing](#citing)\n 7. [License](#license)\n 8. [Related repository](#related_repos)\n\n### 💡 Examples \u003ca name=\"examples\"\u003e\u003c/a\u003e\n 1. Download the [VOC](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar) image dataset, and split the dataset into train and val parts as follows:\n```\ndataset\n├── train\n│   ├── images\n|   |     ├──xxx.jpg\n|   |     └......\n│   ├── labels\n|   |     ├──xxx.xml\n|   |     └......\n├── val\n│   ├── images\n|   |     ├──zzz.jpg\n|   |     └......\n│   ├── labels\n|   |     ├──zzz.xml\n|   |     └......\n```\n\n 2. Download the yolo4_tiny pretrained weight [here](https://github.com/AllentDan/LibtorchDetection/releases/download/0.1/yolo4_tiny.pt). And load it into your cpp project as follows:\n```cpp\nDetector detector;\ndetector.Initialize(-1, /*gpu id, -1 for cpu*/\n                    416, /*resize width*/\n                    416, /*resize height*/\n                    \"your path to class name.txt\");\ndetector.Train(\"your path to dataset dir\", \n                    \".jpg\", /*image type*/\n                    30,/*training epochs*/\n                    4, /*batch size*/\n                    0.001, /*learning rate*/\n                    \"path to save detector.pt\",\n                    \"path to load pretrained yolo4_tiny.pt\");\n```\n\n 3. Predicting test. A detector.pt file is provided in the project [here](https://github.com/AllentDan/LibtorchDetection/releases/download/0.1/detector.pt) (trained on VOC for one epoch, just for testing...). Click and download, then you can directly test the detection result through:\n```cpp\ncv::Mat image = cv::imread(\"your path to 2007_005331.jpg\");\nDetector detector;\ndetector.Initialize(0, 416, 416, \"your path to voc_classes.txt\");\ndetector.LoadWeight(\"detector.pt\"/*the saved .pt path*/);\ndetector.Predict(image, true,/*show result or not*/, 0.1, /*confidence thresh*/, 0.3/*nms thresh*/);\n```\nthe predicted result shows as follow:\n\n![](https://raw.githubusercontent.com/AllentDan/ImageBase/main/detection/2007_005331_pred.jpg)\n\n### 🧑‍🚀 Train your own data \u003ca name=\"trainingOwn\"\u003e\u003c/a\u003e\n- Create your own dataset. Using [labelImg](https://github.com/tzutalin/labelImg) through \"pip install\" and label your images. Split the output xml files and images into folders just like the example above.\n\n- Training or testing. Just like the example of VOC detection, replace with your own dataset path.\n\n\n### 🛠 Installation \u003ca name=\"installation\"\u003e\u003c/a\u003e\n**Dependency:**\n\n- [Opencv 3+](https://opencv.org/releases/)\n- [Libtorch 1.7+](https://pytorch.org/)\n\n**Windows:**\n\nConfigure the environment for libtorch development. [Visual studio](https://allentdan.github.io/2020/03/05/windows-libtorch-configuration/) and [Qt Creator](https://allentdan.github.io/2020/03/05/QT-Creator-Opencv-Libtorch-CUDA-English/) are verified for libtorch1.7+.\n\n**Linux \u0026\u0026 MacOS:**\n\nInstall libtorch and opencv. \n\nFor libtorch, follow the official pytorch c++ tutorials [here](https://pytorch.org/tutorials/advanced/cpp_export.html).\n\nFor opencv, follow the official opencv install steps [here](https://github.com/opencv/opencv).\n\nIf you have already configured them both, congratulations!!! Download the pretrained weight [here](https://github.com/AllentDan/LibtorchDetection/releases/download/0.1/yolo4_tiny.pt) and a demo .pt file [here](https://github.com/AllentDan/LibtorchDetection/releases/download/0.1/detector.pt) into weights. Then just do the following:\n```bash\nexport Torch_DIR='/path/to/libtorch'\ncd build\ncmake ..\nmake\n./LibtorchDetection\n```\n\n### ⏳ ToDo \u003ca name=\"todo\"\u003e\u003c/a\u003e\n- [ ] More detection architectures, mainly one-stage algorithms.\n- [ ] Data augmentations.\n- [ ] Training tricks.\n\n### 🤝 Thanks \u003ca name=\"thanks\"\u003e\u003c/a\u003e\nThis project is under developing. By now, these projects helps a lot.\n- [official pytorch](https://github.com/pytorch/pytorch)\n- [yolo4 tiny](https://github.com/bubbliiiing/yolov4-tiny-pytorch)\n- [labelImg](https://github.com/tzutalin/labelImg)\n- [tiny xml](https://github.com/leethomason/tinyxml2)\n\n### 📝 Citing\n```\n@misc{Chunyu:2021,\n  Author = {Chunyu Dong},\n  Title = {Libtorch Detection},\n  Year = {2021},\n  Publisher = {GitHub},\n  Journal = {GitHub repository},\n  Howpublished = {\\url{https://github.com/AllentDan/LibtorchDetection}}\n}\n```\n\n### 🛡️ License \u003ca name=\"license\"\u003e\u003c/a\u003e\nProject is distributed under [MIT License](https://github.com/qubvel/segmentation_models.pytorch/blob/master/LICENSE). \n\n## Related repository \u003ca name=\"related_repos\"\u003e\u003c/a\u003e\nBased on libtorch, I released following repositories:\n- [LibtorchTutorials](https://github.com/AllentDan/LibtorchTutorials)\n- [LibtorchSegmentation](https://github.com/AllentDan/LibtorchSegmentation)\n- [LibtorchDetection](https://github.com/AllentDan/LibtorchDetection)\n\nLast but not least, **don't forget** your star...\n\nFeel free to commit issues or pull requests, contributors wanted.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallentdan%2Flibtorchdetection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallentdan%2Flibtorchdetection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallentdan%2Flibtorchdetection/lists"}