Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] code quality #289

Merged
merged 67 commits into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
9530562
isort
RangiLyu Jun 14, 2021
a2f3818
format
RangiLyu Jun 14, 2021
b0cdb3c
lint
RangiLyu Jun 19, 2021
4f3d5a1
add flake8 config
RangiLyu Jun 19, 2021
56e1ac3
lint
RangiLyu Jun 19, 2021
557ff0c
add isort config
RangiLyu Jun 19, 2021
c266ebb
add pre-commit
RangiLyu Jun 19, 2021
b7d8be8
format
RangiLyu Jun 19, 2021
4546163
fix string
RangiLyu Jun 19, 2021
f659c45
update
RangiLyu Jun 19, 2021
9e496a9
change to black code style
RangiLyu Jun 19, 2021
36351ee
add CI
RangiLyu Jun 19, 2021
0f04abe
isort style
RangiLyu Jun 19, 2021
3eb77bb
extend flake8
RangiLyu Jun 19, 2021
be551a6
add config unit test
RangiLyu Jun 20, 2021
74ef816
add CUDA test
RangiLyu Jun 20, 2021
1c4db4c
update workflow
RangiLyu Jun 20, 2021
f259409
fix torchvision version
RangiLyu Jun 20, 2021
5bac8d8
add conv unit test
RangiLyu Jun 20, 2021
64dcc39
remove cache
RangiLyu Jun 20, 2021
3490ee0
add repvgg conv test
RangiLyu Jun 20, 2021
ebae7e7
add nms unit test
RangiLyu Jun 26, 2021
9467bc7
add scale unit test
RangiLyu Jun 26, 2021
db58ccf
add test data
RangiLyu Jun 26, 2021
9f28958
fix workflow
RangiLyu Jun 26, 2021
4c5dacf
fix workflow
RangiLyu Jun 26, 2021
5d82473
fix workflow
RangiLyu Jun 26, 2021
a51017b
add transformer unit test
RangiLyu Jun 26, 2021
0b858f7
add init_weights unit test
RangiLyu Jun 26, 2021
035a7aa
add norm unit test
RangiLyu Jun 26, 2021
65ce4b6
add iou loss test and fix bug
RangiLyu Jun 26, 2021
a79f4b1
add gfl loss unit test
RangiLyu Jun 26, 2021
85e4007
fix pop
RangiLyu Jun 26, 2021
f2d8be7
iou coverage
RangiLyu Jun 26, 2021
51afd92
add shufflenet efficientnet unit test
RangiLyu Jun 26, 2021
fd5f825
fix lint
RangiLyu Jun 26, 2021
fc6764f
add resnet unit test
RangiLyu Jun 27, 2021
b5a65f0
add repvgg backbone unit test
RangiLyu Jul 4, 2021
95c67ff
add repvgg backbone unit test
RangiLyu Jul 4, 2021
a7858ac
add mbv2 backbone unit test
RangiLyu Jul 4, 2021
60bfd89
add csp backbone unit test
RangiLyu Jul 4, 2021
5a69f88
add csp backbone unit test
RangiLyu Jul 4, 2021
0c3906b
add csp backbone unit test
RangiLyu Jul 4, 2021
effea88
add ghostnet backbone unit test
RangiLyu Jul 4, 2021
25d609e
add pytorch lightning task unit test
RangiLyu Jul 4, 2021
89cb812
update flake8
RangiLyu Jul 4, 2021
c3ec3b2
fix pt1.6
RangiLyu Jul 4, 2021
3c3118e
add trainer unit test
RangiLyu Jul 4, 2021
739f844
use tmp dir
RangiLyu Jul 4, 2021
73ef835
replace dataset name in cfg
RangiLyu Jul 4, 2021
6eb4ce9
add cocodataset unit test
RangiLyu Jul 4, 2021
c9d5958
test collate
RangiLyu Jul 10, 2021
55d2ba5
add xml dataset unit test
RangiLyu Jul 10, 2021
aa82901
change build evaluator
RangiLyu Jul 10, 2021
a8a9bbd
add evaluator unit test
RangiLyu Jul 10, 2021
75f3f64
add transform unit test
RangiLyu Jul 11, 2021
47d4663
add GFL head unit test
RangiLyu Jul 11, 2021
6f24f42
add flops unit test
RangiLyu Jul 11, 2021
b8cb8b3
add coco instance seg unit test
RangiLyu Jul 17, 2021
e7b54cb
add nanodet head unit test
RangiLyu Jul 17, 2021
b8f8631
add fpn unit test
RangiLyu Jul 17, 2021
6c1b473
add pan unit test
RangiLyu Jul 17, 2021
00843f3
add pan unit test
RangiLyu Jul 17, 2021
b48e619
add tan unit test
RangiLyu Jul 17, 2021
5c06d4b
fix unit test
RangiLyu Jul 17, 2021
deaafc2
merge master
RangiLyu Jul 17, 2021
46a4962
Merge pull request #260 from RangiLyu/unit_test
RangiLyu Jul 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
format
  • Loading branch information
RangiLyu committed Jun 19, 2021
commit b7d8be80da078bd8a30cdbdf2d61eebcd57ed1ed
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ repos:
- id: name-tests-test
- id: requirements-txt-fixer

- repo: https://github.com/psf/black
rev: 21.6b0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/psf/black
rev: 21.6b0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright 2020-2021 RangiLyu. All rights reserved.

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Model |Resolution|COCO mAP |Latency(ARM 4 Threads) | FLOPS | Par
:-------------:|:--------:|:-------:|:--------------------:|:----------:|:---------:|:-------:
NanoDet-m | 320*320 | 20.6 | **10.23ms** | **0.72G** | **0.95M** | **1.8MB(FP16)** | **980KB(INT8)**
NanoDet-m | 416*416 | 23.5 | 16.44ms | 1.2G | **0.95M** | **1.8MB(FP16)** | **980KB(INT8)**
NanoDet-m-1.5x | 320*320 | 23.5 | 13.53ms | 1.44G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-m-1.5x | 416*416 | **26.8** | 21.53ms | 2.42G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-m-1.5x | 320*320 | 23.5 | 13.53ms | 1.44G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-m-1.5x | 416*416 | **26.8** | 21.53ms | 2.42G | 2.08M | 3.9MB(FP16) | 2MB(INT8)
NanoDet-g | 416*416 | 22.9 | Not Designed For ARM | 4.2G | 3.81M | 7.7MB(FP16) | 3.6MB(INT8)
YoloV3-Tiny | 416*416 | 16.6 | 37.6ms | 5.62G | 8.86M | 33.7MB
YoloV4-Tiny | 416*416 | 21.7 | 32.81ms | 6.96G | 6.06M | 23.0MB
Expand Down Expand Up @@ -222,15 +222,15 @@ NanoDet-RepVGG | RepVGG-A0 | 416*416 | 27.8 | 11.3G | 6.75M |
3. **Start training**

NanoDet is now using [pytorch lightning](https://github.com/PyTorchLightning/pytorch-lightning) for training.

For both single-GPU or multiple-GPUs, run:

```shell script
python tools/train.py CONFIG_FILE_PATH
```

For **Windows users**, if you have problems with the new lightning trainer, try to use tools/deprecated/train.py

<details>
<summary>follow this...</summary>

Expand All @@ -245,7 +245,7 @@ NanoDet-RepVGG | RepVGG-A0 | 416*416 | 27.8 | 11.3G | 6.75M |
```shell script
python -m torch.distributed.launch --nproc_per_node=GPU_NUM --master_port 29501 tools/deprecated/train.py CONFIG_FILE_PATH
```

</details>


Expand Down
2 changes: 1 addition & 1 deletion demo/demo-inference-with-pytorch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
2 changes: 1 addition & 1 deletion demo_android_ncnn/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
5 changes: 2 additions & 3 deletions demo_android_ncnn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repo is an Android object detection demo of NanoDet using

# Tutorial

## Step1.
## Step1.
Download ncnn-android-vulkan.zip from ncnn repo or build ncnn-android from source.

- [ncnn-android-vulkan.zip download link](https://github.com/Tencent/ncnn/releases)
Expand All @@ -32,5 +32,4 @@ Open demo_android_ncnn folder with Android Studio and then build it.
# Reference

* [ncnn](https://github.com/tencent/ncnn)
* [YOLOv5_NCNN](https://github.com/WZTENG/YOLOv5_NCNN)

* [YOLOv5_NCNN](https://github.com/WZTENG/YOLOv5_NCNN)
2 changes: 1 addition & 1 deletion demo_android_ncnn/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
android:theme="@style/AppNoTitleTheme" />
</application>

</manifest>
</manifest>
1 change: 0 additions & 1 deletion demo_android_ncnn/app/src/main/cpp/YoloV4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@ YoloV4::decode_infer(ncnn::Mat &data, const yolocv::YoloSize &frame_size, int ne
}
return result;
}

3 changes: 0 additions & 3 deletions demo_android_ncnn/app/src/main/cpp/jni_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,3 @@ Java_com_rangi_nanodet_YOLOv4_detect(JNIEnv *env, jclass, jobject image, jdouble
}
return ret;
}



Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@
app:layout_constraintTop_toBottomOf="@+id/imageView"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
</adaptive-icon>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
</adaptive-icon>
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public class ExampleUnitTest {
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
}
4 changes: 2 additions & 2 deletions demo_android_ncnn/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ buildscript {
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
1 change: 0 additions & 1 deletion demo_android_ncnn/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

6 changes: 3 additions & 3 deletions demo_libtorch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ include_directories(
add_executable(nanodet_demo main.cpp nanodet_libtorch.cpp)

target_link_libraries(
nanodet_demo
nanodet_demo
${TORCH_LIBRARIES}
${OpenCV_LIBS}
${OpenCV_LIBS}
)

if (MSVC)
Expand All @@ -28,4 +28,4 @@ if (MSVC)
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:nanodet_demo>)
endif (MSVC)
endif (MSVC)
4 changes: 2 additions & 2 deletions demo_libtorch/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NanoDet TorchScript / LibTorch Demo

This folder provides NanoDet inference code using for LibTorch.
This folder provides NanoDet inference code using for LibTorch.

## Install dependencies

Expand Down Expand Up @@ -29,4 +29,4 @@ mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..
make
```
```
8 changes: 4 additions & 4 deletions demo_libtorch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void draw_bboxes(const cv::Mat& bgr, const std::vector<BoxInfo>& bboxes, object_
//fprintf(stderr, "%d = %.5f at %.2f %.2f %.2f %.2f\n", bbox.label, bbox.score,
// bbox.x1, bbox.y1, bbox.x2, bbox.y2);

cv::rectangle(image, cv::Rect(cv::Point((bbox.x1 - effect_roi.x) * width_ratio, (bbox.y1 - effect_roi.y) * height_ratio),
cv::rectangle(image, cv::Rect(cv::Point((bbox.x1 - effect_roi.x) * width_ratio, (bbox.y1 - effect_roi.y) * height_ratio),
cv::Point((bbox.x2 - effect_roi.x) * width_ratio, (bbox.y2 - effect_roi.y) * height_ratio)), color);

char text[256];
Expand Down Expand Up @@ -292,15 +292,15 @@ int benchmark(NanoDet& detector)
double time_max = -DBL_MAX;
double time_avg = 0;
cv::Mat image(320, 320, CV_8UC3, cv::Scalar(1, 1, 1));

for (int i = 0; i < warm_up + loop_num; i++)
{
auto start = std::chrono::steady_clock::now();
std::vector<BoxInfo> results;
results = detector.detect(image, 0.4, 0.5);
auto end = std::chrono::steady_clock::now();
double time = std::chrono::duration<double, std::milli>(end - start).count();
if (i >= warm_up)
if (i >= warm_up)
{
time_min = (std::min)(time_min, time);
time_max = (std::max)(time_max, time);
Expand All @@ -312,7 +312,7 @@ int benchmark(NanoDet& detector)
return 0;
}

int main(int argc, char** argv)
int main(int argc, char** argv)
{
if (argc != 3)
{
Expand Down
22 changes: 11 additions & 11 deletions demo_libtorch/nanodet_libtorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "nanodet_libtorch.h"


inline float fast_exp(float x)
inline float fast_exp(float x)
{
union {
uint32_t i;
Expand All @@ -13,7 +13,7 @@ inline float fast_exp(float x)
return v.f;
}

inline float sigmoid(float x)
inline float sigmoid(float x)
{
return 1.0f / (1.0f + fast_exp(-x));
}
Expand All @@ -24,13 +24,13 @@ int activation_function_softmax(const _Tp* src, _Tp* dst, int length)
const _Tp alpha = *std::max_element(src, src + length);
_Tp denominator{ 0 };

for (int i = 0; i < length; ++i)
for (int i = 0; i < length; ++i)
{
dst[i] = fast_exp(src[i] - alpha);
denominator += dst[i];
}

for (int i = 0; i < length; ++i)
for (int i = 0; i < length; ++i)
{
dst[i] /= denominator;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ std::vector<BoxInfo> NanoDet::detect(cv::Mat image, float score_threshold, float
for (int i = 0; i < (int)results.size(); i++)
{
this->nms(results[i], nms_threshold);

for (auto box : results[i])
{
dets.push_back(box);
Expand Down Expand Up @@ -161,14 +161,14 @@ void NanoDet::nms(std::vector<BoxInfo>& input_boxes, float NMS_THRESH)
{
std::sort(input_boxes.begin(), input_boxes.end(), [](BoxInfo a, BoxInfo b) { return a.score > b.score; });
std::vector<float> vArea(input_boxes.size());
for (int i = 0; i < int(input_boxes.size()); ++i)
for (int i = 0; i < int(input_boxes.size()); ++i)
{
vArea[i] = (input_boxes.at(i).x2 - input_boxes.at(i).x1 + 1)
* (input_boxes.at(i).y2 - input_boxes.at(i).y1 + 1);
}
for (int i = 0; i < int(input_boxes.size()); ++i)
for (int i = 0; i < int(input_boxes.size()); ++i)
{
for (int j = i + 1; j < int(input_boxes.size());)
for (int j = i + 1; j < int(input_boxes.size());)
{
float xx1 = (std::max)(input_boxes[i].x1, input_boxes[j].x1);
float yy1 = (std::max)(input_boxes[i].y1, input_boxes[j].y1);
Expand All @@ -178,15 +178,15 @@ void NanoDet::nms(std::vector<BoxInfo>& input_boxes, float NMS_THRESH)
float h = (std::max)(float(0), yy2 - yy1 + 1);
float inter = w * h;
float ovr = inter / (vArea[i] + vArea[j] - inter);
if (ovr >= NMS_THRESH)
if (ovr >= NMS_THRESH)
{
input_boxes.erase(input_boxes.begin() + j);
vArea.erase(vArea.begin() + j);
}
else
else
{
j++;
}
}
}
}
}
4 changes: 2 additions & 2 deletions demo_libtorch/nanodet_libtorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <opencv2/core/core.hpp>


typedef struct BoxInfo
typedef struct BoxInfo
{
float x1;
float y1;
Expand Down Expand Up @@ -30,4 +30,4 @@ class NanoDet
int num_class_ = 80;
int reg_max_ = 7;

};
};
7 changes: 3 additions & 4 deletions demo_mnn/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void draw_bboxes(const cv::Mat& bgr, const std::vector<BoxInfo>& bboxes, object_
//fprintf(stderr, "%d = %.5f at %.2f %.2f %.2f %.2f\n", bbox.label, bbox.score,
// bbox.x1, bbox.y1, bbox.x2, bbox.y2);

cv::rectangle(image, cv::Rect(cv::Point((bbox.x1 - effect_roi.x) * width_ratio, (bbox.y1 - effect_roi.y) * height_ratio),
cv::rectangle(image, cv::Rect(cv::Point((bbox.x1 - effect_roi.x) * width_ratio, (bbox.y1 - effect_roi.y) * height_ratio),
cv::Point((bbox.x2 - effect_roi.x) * width_ratio, (bbox.y2 - effect_roi.y) * height_ratio)), color);

char text[256];
Expand Down Expand Up @@ -250,7 +250,7 @@ int image_demo(NanoDet &detector, const char* imagepath)
resize_uniform(image, resized_img, cv::Size(320, 320), effect_roi);
std::vector<BoxInfo> results;
detector.detect(resized_img, results);

#ifdef __SAVE_RESULT__
std::string save_path = img_name.operator std::string();
draw_bboxes(image, results, effect_roi, save_path.replace(3, 4, "results"));
Expand Down Expand Up @@ -319,7 +319,7 @@ int benchmark(NanoDet& detector)

std::chrono::duration<double> elapsed = end - start;
double time = elapsed.count();
if (i >= warm_up)
if (i >= warm_up)
{
time_min = (std::min)(time_min, time);
time_max = (std::max)(time_max, time);
Expand Down Expand Up @@ -369,4 +369,3 @@ int main(int argc, char** argv)
}
}
}

6 changes: 3 additions & 3 deletions demo_ncnn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include_directories(
add_executable(nanodet_demo main.cpp nanodet.cpp)

target_link_libraries(
nanodet_demo
nanodet_demo
ncnn
${OpenCV_LIBS}
)
${OpenCV_LIBS}
)
2 changes: 1 addition & 1 deletion demo_ncnn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Download Vulkan SDK from https://vulkan.lunarg.com/sdk/home
Clone NCNN repository

``` shell script
git clone --recursive https://github.com/Tencent/ncnn.git
git clone --recursive https://github.com/Tencent/ncnn.git
```

Build NCNN following this tutorial: [Build for Linux / NVIDIA Jetson / Raspberry Pi](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-linux)
Expand Down
Loading