Skip to content

Commit 4361284

Browse files
committed
refactor code with pre-commit
1 parent a06569a commit 4361284

25 files changed

+154
-131
lines changed

.clang-format

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
Language: Cpp
2+
Language: Cpp
33
# BasedOnStyle: LLVM
44
AccessModifierOffset: -3
55
AlignAfterOpenBracket: true
66
AlignEscapedNewlinesLeft: false
7-
AlignOperands: true
7+
AlignOperands: true
88
AlignTrailingComments: true
99
AllowAllParametersOfDeclarationOnNextLine: true
1010
AllowShortBlocksOnASingleLine: false
@@ -20,7 +20,7 @@ BreakBeforeTernaryOperators: true
2020
BreakConstructorInitializersBeforeComma: true
2121
BinPackParameters: true
2222
BinPackArguments: true
23-
ColumnLimit: 120
23+
ColumnLimit: 120
2424
ConstructorInitializerAllOnOneLineOrOnePerLine: false
2525
ConstructorInitializerIndentWidth: 4
2626
DerivePointerAlignment: false
@@ -43,22 +43,21 @@ PenaltyReturnTypeOnItsOwnLine: 60
4343
PointerAlignment: Left
4444
SpacesBeforeTrailingComments: 2
4545
Cpp11BracedListStyle: true
46-
Standard: Cpp11
47-
IndentWidth: 4
48-
TabWidth: 8
49-
UseTab: Never
46+
Standard: Cpp11
47+
IndentWidth: 4
48+
TabWidth: 8
49+
UseTab: Never
5050
BreakBeforeBraces: Linux # the position of the braces
5151
SpacesInParentheses: false
5252
SpacesInSquareBrackets: false
53-
SpacesInAngles: false
53+
SpacesInAngles: false
5454
SpaceInEmptyParentheses: false
5555
SpacesInCStyleCastParentheses: false
5656
SpaceAfterCStyleCast: false
5757
SpacesInContainerLiterals: true
5858
SpaceBeforeAssignmentOperators: true
5959
ContinuationIndentWidth: 4
60-
CommentPragmas: '.*'
61-
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
60+
CommentPragmas: ".*"
61+
ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
6262
SpaceBeforeParens: ControlStatements
63-
DisableFormat: false
64-
...
63+
DisableFormat: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*~
1212
*#
1313
build*
14+
.cache*
1415

1516
# Packages #
1617
###################

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: v14.0.6
4+
hooks:
5+
- id: clang-format
6+
7+
- repo: https://github.com/cpplint/cpplint
8+
rev: 1.6.0
9+
hooks:
10+
- id: cpplint
11+
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v4.3.0
14+
hooks:
15+
- id: end-of-file-fixer
16+
- id: trailing-whitespace
17+
18+
- repo: https://github.com/pre-commit/mirrors-prettier
19+
rev: v2.7.1
20+
hooks:
21+
- id: prettier
22+
types_or: [json, markdown, yaml]
23+
24+
- repo: https://github.com/lovesegfault/beautysh
25+
rev: v6.2.1
26+
hooks:
27+
- id: beautysh

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
project(ort_utility)
3+
project(ort_utility VERSION 0.0.1)
44
set (CMAKE_CXX_STANDARD 17)
55

66
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

CPPLINT.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set noparent
2+
3+
filter=-legal/copyright
4+
filter=-whitespace/braces
5+
filter=-build/header_guard
6+
filter=+build/pragma_once
7+
filter=-build/include_order
8+
filter=-build/include_subdir
9+
filter=-build/c++11
10+
linelength=120

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ CMAKE_ARGS:=$(CMAKE_ARGS)
44

55
default:
66
@mkdir -p build
7-
@cd build && cmake .. -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) $(CMAKE_ARGS) && make
7+
@cd build && cmake .. -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) \
8+
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
9+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
10+
$(CMAKE_ARGS)
11+
@cd build && make
812

913
debug:
1014
@make default BUILD_TYPE=Debug

README.md

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# small c++ library to quickly use [onnxruntime](https://github.com/microsoft/onnxruntime) to deploy deep learning models #
1+
# small c++ library to quickly use [onnxruntime](https://github.com/microsoft/onnxruntime) to deploy deep learning models
22

33
Thanks to [cardboardcode](https://github.com/cardboardcode), we have [the documentation](https://onnx-runtime-cpp.readthedocs.io/en/latest/index.html) for this small library.
44
Hope that they both are helpful for your work.
@@ -9,14 +9,17 @@ Hope that they both are helpful for your work.
99
- [x] Examples for famous models, like yolov3, mask-rcnn, [ultra-light-weight face detector](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB), [yolox](https://github.com/Megvii-BaseDetection/YOLOX), [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.3). Might consider supporting more if requested
1010
- [ ] Batch-inference
1111

12-
## Installation ##
12+
## Installation
13+
1314
- build onnxruntime from source with the following script
15+
1416
```bash
1517
sudo bash ./scripts/install_onnx_runtime.sh
1618
```
1719

18-
## How to build ##
19-
***
20+
## How to build
21+
22+
---
2023

2124
```bash
2225
make default
@@ -25,17 +28,21 @@ make default
2528
make apps
2629
```
2730

28-
## How to test apps ##
29-
***
31+
## How to test apps
3032

31-
### Image Classification With Squeezenet ###
32-
***
33+
---
34+
35+
### Image Classification With Squeezenet
36+
37+
---
3338

3439
```bash
3540
# after make apps
3641
./build/examples/TestImageClassification ./data/squeezenet1.1.onnx ./data/images/dog.jpg
3742
```
43+
3844
the following result can be obtained
45+
3946
```
4047
264 : Cardigan, Cardigan Welsh corgi : 0.391365
4148
263 : Pembroke, Pembroke Welsh corgi : 0.376214
@@ -44,30 +51,39 @@ the following result can be obtained
4451
230 : Shetland sheepdog, Shetland sheep dog, Shetland : 0.020529
4552
```
4653

47-
### Object Detection With Tiny-Yolov2 trained on VOC dataset (with 20 classes) ###
48-
***
54+
### Object Detection With Tiny-Yolov2 trained on VOC dataset (with 20 classes)
55+
56+
---
57+
4958
- Download model from onnx model zoo: [HERE](https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/yolov2)
5059

5160
- The shape of the output would be
61+
5262
```text
5363
OUTPUT_FEATUREMAP_SIZE X OUTPUT_FEATUREMAP_SIZE * NUM_ANCHORS * (NUM_CLASSES + 4 + 1)
5464
where OUTPUT_FEATUREMAP_SIZE = 13; NUM_ANCHORS = 5; NUM_CLASSES = 20 for the tiny-yolov2 model from onnx model zoo
5565
```
66+
5667
- Test tiny-yolov2 inference apps
68+
5769
```bash
5870
# after make apps
5971
./build/examples/tiny_yolo_v2 [path/to/tiny_yolov2/onnx/model] ./data/images/dog.jpg
6072
```
73+
6174
- Test result
6275

6376
![tinyyolov2 test result](./data/images/result.jpg)
6477

65-
### Object Instance Segmentation With MaskRCNN trained on MS CoCo Dataset (80 + 1(background) clasess) ###
66-
***
78+
### Object Instance Segmentation With MaskRCNN trained on MS CoCo Dataset (80 + 1(background) clasess)
79+
80+
---
81+
6782
- Download model from onnx model zoo: [HERE](https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/mask-rcnn)
6883

6984
- As also stated in the url above, there are four outputs: boxes(nboxes x 4), labels(nboxes), scores(nboxes), masks(nboxesx1x28x28)
7085
- Test mask-rcnn inference apps
86+
7187
```bash
7288
# after make apps
7389
./build/examples/mask_rcnn [path/to/mask_rcnn/onnx/model] ./data/images/dogs.jpg
@@ -79,12 +95,14 @@ the following result can be obtained
7995

8096
![indoor maskrcnn result](./data/images/indoor_maskrcnn_result.jpg)
8197

82-
### Yolo V3 trained on Ms CoCo Dataset ###
83-
***
98+
### Yolo V3 trained on Ms CoCo Dataset
99+
100+
---
84101

85102
- Download model from onnx model zoo: [HERE](https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/yolov3)
86103

87104
- Test yolo-v3 inference apps
105+
88106
```bash
89107
# after make apps
90108
./build/examples/yolov3 [path/to/yolov3/onnx/model] ./data/images/no_way_home.jpg
@@ -96,61 +114,67 @@ the following result can be obtained
96114
<img width="1000" height="667" src="./data/images/no_way_home_result.jpg">
97115
</p>
98116

117+
### [Ultra-Light-Fast-Generic-Face-Detector-1MB](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB)
99118

100-
### [Ultra-Light-Fast-Generic-Face-Detector-1MB](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB) ###
101-
***
119+
---
102120

103121
- App to use onnx model trained with famous light-weight [Ultra-Light-Fast-Generic-Face-Detector-1MB](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB)
104122
- Sample weight has been saved [./data/version-RFB-640.onnx](./data/version-RFB-640.onnx)
105123
- Test inference apps
124+
106125
```bash
107126
# after make apps
108127
./build/examples/ultra_light_face_detector ./data/version-RFB-640.onnx ./data/images/endgame.jpg
109128
```
110129

111130
- Test results:
112-
![ultra light weight face result](./data/images/endgame_result.jpg)
131+
![ultra light weight face result](./data/images/endgame_result.jpg)
113132

114133
### [YoloX: high-performance anchor-free YOLO by Megvii](https://github.com/Megvii-BaseDetection/YOLOX)
115-
***
134+
135+
---
116136

117137
- Download onnx model trained on COCO dataset from [HERE](https://github.com/Megvii-BaseDetection/YOLOX/tree/main/demo/ONNXRuntime)
138+
118139
```bash
119140
# this app tests yolox_l model but you can try with other yolox models also.
120141
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_l.onnx -O ./data/yolox_l.onnx
121142
```
122143

123144
- Test inference apps
145+
124146
```bash
125147
# after make apps
126148
./build/examples/yolox ./data/yolox_l.onnx ./data/images/matrix.jpg
127149
```
150+
128151
- Test results:
129-
![yolox result](./data/images/matrix_result.jpg)
152+
![yolox result](./data/images/matrix_result.jpg)
130153

131154
### [Semantic Segmentation Paddle Seg](https://github.com/PaddlePaddle/PaddleSeg)
132-
***
155+
156+
---
133157

134158
- Download PaddleSeg's bisenetv2 trained on cityscapes dataset that has been converted to onnx [HERE](https://drive.google.com/file/d/1e-anuWG_ppDXmoy0sQ0sgrdutCTGlk95/view?usp=sharing) and copy to [./data directory](./data)
135159

136160
<details>
137161
<summary>You can also convert your own PaddleSeg with following procedures</summary>
138162

139-
* [export PaddleSeg model](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.3/docs/model_export.md)
140-
* convert exported model to onnx format with [Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX)
163+
- [export PaddleSeg model](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.3/docs/model_export.md)
164+
- convert exported model to onnx format with [Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX)
141165

142166
</details>
143167

144168
- Test inference apps
145169

146170
```bash
147-
./build/examples/semantic_segmentation_paddleseg_bisenetv2 ./data/bisenetv2_cityscapes.onnx ./sample_city_scapes.png
148-
./build/examples/semantic_segmentation_paddleseg_bisenetv2 ./data/bisenetv2_cityscapes.onnx ./odaiba.jpg
171+
./build/examples/semantic_segmentation_paddleseg_bisenetv2 ./data/bisenetv2_cityscapes.onnx ./data/images/sample_city_scapes.png
172+
./build/examples/semantic_segmentation_paddleseg_bisenetv2 ./data/bisenetv2_cityscapes.onnx ./data/images/odaiba.jpg
149173
```
150174

151175
- Test results:
152176

153-
+ cityscapes dataset's color legend
177+
- cityscapes dataset's color legend
154178

155179
![city scapes color legend](./data/images/cityscapes_legend.jpg)
156180

examples/MaskRCNN.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
*
44
* @author btran
55
*
6-
* @date 2020-05-18
7-
*
8-
* Copyright (c) organization
9-
*
106
*/
117

128
#include <cstring>

examples/MaskRCNN.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
*
44
* @author btran
55
*
6-
* @date 2020-05-18
7-
*
8-
* Copyright (c) organization
9-
*
106
*/
117

128
#pragma once

examples/MaskRCNNApp.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
*
44
* @author btran
55
*
6-
* @date 2020-05-18
7-
*
8-
* Copyright (c) organization
9-
*
106
*/
7+
118
#include <chrono>
129
#include <iostream>
1310
#include <memory>
@@ -24,7 +21,7 @@ static const std::vector<cv::Scalar> COLORS = toCvScalarColors(Ort::MSCOCO_COLOR
2421

2522
namespace
2623
{
27-
cv::Mat processOneFrame(Ort::MaskRCNN& osh, const cv::Mat& inputImg, int newW, int newH, int paddedW, int paddedH,
24+
cv::Mat processOneFrame(const Ort::MaskRCNN& osh, const cv::Mat& inputImg, int newW, int newH, int paddedW, int paddedH,
2825
float ratio, float* dst, const float confThresh = 0.5,
2926
const cv::Scalar& meanVal = cv::Scalar(102.9801, 115.9465, 122.7717),
3027
bool visualizeMask = true);
@@ -68,7 +65,7 @@ int main(int argc, char* argv[])
6865

6966
namespace
7067
{
71-
cv::Mat processOneFrame(Ort::MaskRCNN& osh, const cv::Mat& inputImg, int newW, int newH, int paddedW, int paddedH,
68+
cv::Mat processOneFrame(const Ort::MaskRCNN& osh, const cv::Mat& inputImg, int newW, int newH, int paddedW, int paddedH,
7269
float ratio, float* dst, float confThresh, const cv::Scalar& meanVal, bool visualizeMask)
7370
{
7471
cv::Mat tmpImg;

examples/SemanticSegmentationPaddleSegBisenetv2.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#pragma once
99

1010
#include <opencv2/opencv.hpp>
11+
#include <string>
12+
#include <vector>
1113

1214
#include <ort_utility/ort_utility.hpp>
1315

0 commit comments

Comments
 (0)