Skip to content

Commit 63f0b88

Browse files
committed
💚
1 parent c62216e commit 63f0b88

File tree

94 files changed

+26270
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+26270
-377
lines changed

3rdparty/src/pthread.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ typedef void (*windows_thread)(void *);
1313
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void
1414
*(*start_routine)(void *), void *arg)
1515
{
16-
uintptr_t handle = _beginthread((windows_thread)start_routine,0,arg);
16+
DWORD dwThreadId = 1;
17+
18+
HANDLE handle = CreateThread(NULL, 0, start_routine, arg, 0, &dwThreadId);
19+
20+
//uintptr_t handle = _beginthread((windows_thread)start_routine,0,arg);
1721
thread->handle = (HANDLE)handle;
18-
if(thread->handle == (HANDLE)-1){
22+
if(thread->handle == (HANDLE)NULL){
1923
return 1;
2024
}else{
2125
return 0;
@@ -36,6 +40,7 @@ void pthread_exit(void *value_ptr)
3640
int pthread_join(pthread_t thread, void **value_ptr)
3741
{
3842
DWORD retvalue = WaitForSingleObject(thread.handle,INFINITE);
43+
CloseHandle(thread.handle);
3944
if(retvalue == WAIT_OBJECT_0){
4045
return 0;
4146
}else{

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ set(SOURCE_FILES
7474
src/im2col.h
7575
src/image.c
7676
src/image.h
77+
src/iseg_layer.c
78+
src/iseg_layer.h
7779
src/l2norm_layer.c
7880
src/l2norm_layer.h
7981
src/layer.c

README.md

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
YOLOv3_SpringEdition <img src="https://i.imgur.com/oYejfWp.png" title="Windows8" width="48">
22
--------------------------------------------------------------------------------------------
33

4+
5+
작성중....
6+
VS2017
7+
LINUX
8+
기타 등등...
9+
410
<img src="https://i.imgur.com/ElCyyzT.png" title="Windows8" width="48"><img src="https://i.imgur.com/O5bye0l.png" width="48"><img src="https://i.imgur.com/kmfOMZz.png" width="48"><img src="https://i.imgur.com/6OT8yM9.png" width="48">
511

612
#### YOLOv3 C++ Windows and Linux interface library. (Train,Detect both)
@@ -22,21 +28,54 @@ std::vector<BoxSE> boxes = detector.Detect(img, 0.5F);
2228

2329
### 1. Setup for train.
2430

25-
You need only 2 files for train that are **YOLOv3SE_Train.exe** and **cudnn64_5.dll** on Windows. If you are on Linux, then you need only **YOLOv3SE_Train**. This files are in `YOLOv3_SpringEdition/bin`.
31+
#### 1.1. Train detector
32+
You need only 2 files for train that are **YOLOv3SE_Train.exe** and **cudnn64_7.dll** on Windows. If you are on Linux, then you need only **YOLOv3SE_Train**. This files are in `YOLOv3_SpringEdition/bin`.
2633

2734
The requirement interface not changed. Same as **[pjreddie/darknet](https://github.com/pjreddie/darknet)**.
2835

2936
There is a example training directory `Yolov3_SpringEdition_Train/`. You can start training using above files.
3037

3138
Actually, all the interfaces are same with YOLOv2. So you can easily train your own data.
3239

33-
The **YOLOv3SE_Train.exe**'s arguments are [base directory],[data file path] and [cfg file path].
40+
The **YOLOv3SE_Train.exe**'s arguments are `[option]`,`[base directory]`,`[data file path]` and `[cfg file path]`.
3441

3542
And YOLOv3SE_Train.exe is automatically choosing multi-gpu training. and select latest backup weights file.
3643

44+
#### 1.2. Train classifier
45+
Example : [Yolov3_SpringEdition_Train/ClassifierExample/](Yolov3_SpringEdition_Train/ClassifierExample/)
46+
47+
##### Sample directory structure with STL10 dataset.
48+
```
49+
┌ stl10
50+
│ ├ airplane
51+
│ ├ bird
52+
│ ├ car
53+
│ ...
54+
│ └ truck
55+
├ backup
56+
├ resnext50.cfg
57+
├ stl10.data
58+
├ stl10.names
59+
├ train.txt
60+
├ cudnn64_7.dll
61+
├ YOLOv3SE_ Train.exe
62+
```
63+
##### Sample run argument with STL10 dataset.
64+
```
65+
"YOLOv3SE_Train.exe" classifier . stl10.data resnext50.cfg
66+
```
67+
3768
### 2. Setup for detect
3869

39-
Just include **YOLOv3SE.h** and use it. See `YOLOv3_SpringEdition_Test/`. You need only **YOLOv3SE.h**, **libYOLOv3SE.dll** and **cudnn64_5.dll** for detect.
70+
**Do not change "batch" and "subdivisions" in cfg file. It automatically read those values as 1 when the network is on testing mode.**
71+
72+
Just include **YOLOv3SE.h** and use it. See `YOLOv3_SpringEdition_Test/`. You need only **YOLOv3SE.h**, **libYOLOv3SE.dll** and **cudnn64_7.dll** for detect.
73+
74+
###### 1. Go to [Yolov3_SpringEdition_Test](Yolov3_SpringEdition_Test)
75+
###### 2. Run "download_cudnn64_7.dll.bat" if you're in Windows.
76+
###### 3. Download "voc2007valid", "yolov3_darknet53.weights" for detection.
77+
###### Download "stl10valid", "resnext50_256_10000.weights" for classification.
78+
###### 4. Run VS solution or build.sh.
4079

4180
##### Reference
4281

@@ -46,22 +85,40 @@ The class `YOLOv3` that in `YOLOv3SE.h` has 3 methods.
4685
void Create(std::string weights,std::string cfg,std::string names);
4786
```
4887
49-
This method load trained model(**weights**), network configuration(**cfg**) and class naming file(**names**\)* **Parameter** * **weights** : trained model path(e.g. "obj.weights") * **cfg** : network configuration file(e.g. "obj.cfg") * **names** : class naming file(e.g. "obj.names")
88+
This method load trained model(**weights**), network configuration(**cfg**) and class naming file(**names**\)*
89+
90+
* **Parameter**
91+
* **weights** : trained model path(e.g. "obj.weights")
92+
* **cfg** : network configuration file(e.g. "obj.cfg")
93+
* **names** : class naming file(e.g. "obj.names")
5094
5195
```cpp
5296
std::vector<BoxSE> Detect(cv::Mat img, float threshold);
5397
std::vector<BoxSE> Detect(std::string file, float threshold);
5498
std::vector<BoxSE> Detect(IplImage* img, float threshold);
99+
int Classify(IplImage* img);
100+
int Classify(cv::Mat img);
101+
int Classify(std::string file);
55102
```
56103

57-
This method is detecting objects of `file`,`cv::Mat` or `IplImage`.* **Parameter** * **file** : image file path * **img** : 3-channel image. * **threshold** : It removes predictive boxes if there score is less than threshold.
104+
This method is detecting objects or classify of `file`,`cv::Mat` or `IplImage`.
105+
* **Parameter**
106+
* **file** : image file path
107+
* **img** : 3-channel image.
108+
* **threshold** : It removes predictive boxes if there score is less than threshold.
109+
58110

59111
```cpp
60112
void Release();
61113
```
62-
63114
Release loaded network.
64115

116+
### 3. Setup for train(classification).
117+
118+
119+
120+
121+
65122
Technical issue
66123
---------------
67124

@@ -73,11 +130,12 @@ change log
73130
**build_windows.bat** and **build_linux.sh** will download automatically correct version of cudnn. and build as cmake.
74131

75132
```
76-
Windows + 1080ti + CUDA8.0 + cudnn7.1 = 36FPS
77-
Windows + 1080ti + CUDA9.0 + cudnn7.1 = 36FPS
78-
Windows + 1080 + CUDA9.0 + cudnn7.1 = 27FPS
79-
Ubuntu + 1080 + CUDA8.0 + cudnn7.1 = 30FPS
80-
Ubuntu + 1080 + CUDA9.0 + cudnn7.1 = 30FPS
133+
Windows + 1080ti + CUDA8.0 + cudnn7.1 + yolov3 = 36FPS
134+
Windows + 1080ti + CUDA9.0 + cudnn7.1 + yolov3 = 36FPS
135+
Windows + 1080 + CUDA9.0 + cudnn7.1 + yolov3 = 27FPS
136+
Windows + 1080 + CUDA9.0 + cudnn7.1 + yolov3(spp) = 15FPS
137+
Ubuntu + 1080 + CUDA8.0 + cudnn7.1 + yolov3 = 30FPS
138+
Ubuntu + 1080 + CUDA9.0 + cudnn7.1 + yolov3 = 30FPS
81139
```
82140

83141
Software requirement
@@ -86,7 +144,7 @@ Software requirement
86144
- CMake
87145
- CUDA 8.0 or 9.0(9.1 is not working)
88146
- OpenCV(for testing)
89-
- Visual Studio
147+
- Visual Studio 2015
90148

91149
Hardware requirement
92150
--------------------
0 Bytes
Binary file not shown.

Yolov3_SpringEdition_Test/YOLOv3SE.h

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* YOLOv3_SE.h
44
* YOLOv3_SpringEdition
55
*
6-
* Created by kimbom on 2018. 03. 31...
7-
* Copyright 2018 Sogang Univ. All rights reserved.
6+
* Created by kimbomm on 2018. 03. 31...
7+
* Copyright 2018 kimbomm. All rights reserved.
88
*
99
*/
1010
#if !defined(YOLO_7E0_05_17_YOLOV3_H_INCLUDED)
@@ -69,11 +69,15 @@ class YOLOv3 {
6969
using YoloDetectFromFileType = int(*)(char* img_path, int* _net, float threshold, float* result, int result_sz);
7070
using YoloDetectFromImageType = int(*)(float* data, int w, int h, int c, int* _net, float threshold, float* result, int result_sz);
7171
using YoloReleaseType = void(*)(int* net);
72+
using YoloClassifyFromFileType = int(*)(char* img_path, int* _net, float* result);
73+
using YoloClassifyFromImageType = int(*)(float* data, int w, int h, int c, int* _net, float* result);
7274
private:
7375
YoloLoadType YoloLoad = nullptr;
7476
YoloTrainType YoloTrain = nullptr;
7577
YoloDetectFromFileType YoloDetectFromFile = nullptr;
7678
YoloDetectFromImageType YoloDetectFromImage = nullptr;
79+
YoloClassifyFromFileType YoloClassifyFromFile = nullptr;
80+
YoloClassifyFromImageType YoloClassifyFromImage = nullptr;
7781
YoloReleaseType YoloRelease=nullptr;
7882
protected:
7983
int* m_network = nullptr;
@@ -151,25 +155,6 @@ class YOLOv3 {
151155
return boxes;
152156
}
153157
std::vector<BoxSE> Detect(IplImage* img, float threshold) {
154-
auto ipl_to_image=[](IplImage* src)->image {
155-
image out;
156-
out.data = 0;
157-
out.h = src->height;
158-
out.w = src->width;
159-
out.c = src->nChannels;
160-
out.data = (float*)calloc(out.h*out.w*out.c, sizeof(float));
161-
unsigned char *data = (unsigned char *)src->imageData;
162-
int step = src->widthStep;
163-
int i, j, k;
164-
for (i = 0; i < out.h; ++i) {
165-
for (k = 0; k < out.c; ++k) {
166-
for (j = 0; j < out.w; ++j) {
167-
out.data[k*out.w*out.h + i*out.w + j] = data[i*step + j*out.c + k] / 255.;
168-
}
169-
}
170-
}
171-
return out;
172-
};
173158
float result[6000] = { 0 };
174159
image im = ipl_to_image(img);
175160
int n = YoloDetectFromImage(im.data,im.w,im.h,im.c,this->m_network, threshold, result, 6000);
@@ -191,6 +176,22 @@ class YOLOv3 {
191176
std::sort(boxes.begin(), boxes.end(), [](BoxSE a, BoxSE b)->bool { return a.m_score > b.m_score; });
192177
return boxes;
193178
}
179+
180+
int Classify(IplImage* img) {
181+
image im = ipl_to_image(img);
182+
int r=this->YoloClassifyFromImage(im.data, im.w, im.h, im.c, this->m_network, nullptr);
183+
free(im.data);
184+
return r;
185+
}
186+
int Classify(cv::Mat img) {
187+
IplImage* iplimg = new IplImage(img);
188+
int r = Classify(iplimg);
189+
delete iplimg;
190+
return r;
191+
}
192+
int Classify(std::string file) {
193+
return YoloClassifyFromFile(const_cast<char*>(file.c_str()), this->m_network, nullptr);
194+
}
194195
std::vector<BoxSE> GroundTruth(std::string image_file) {
195196
std::vector<BoxSE> ret;
196197
std::string txt_file = image_file.substr(0, image_file.find_last_of(".")) + ".txt";
@@ -227,6 +228,8 @@ class YOLOv3 {
227228
YoloTrain = (YoloTrainType)GetProcAddress(m_hmod, "YoloTrain");
228229
YoloDetectFromFile = (YoloDetectFromFileType)GetProcAddress(m_hmod, "YoloDetectFromFile");
229230
YoloDetectFromImage = (YoloDetectFromImageType)GetProcAddress(m_hmod, "YoloDetectFromImage");
231+
YoloClassifyFromFile = (YoloClassifyFromFileType)GetProcAddress(m_hmod, "YoloClassifyFromFile");
232+
YoloClassifyFromImage = (YoloClassifyFromImageType)GetProcAddress(m_hmod, "YoloClassifyFromImage");
230233
YoloRelease = (YoloReleaseType)GetProcAddress(m_hmod, "YoloRelease");
231234
#else
232235
m_hmod = dlopen("libYOLOv3SE.so",RTLD_LAZY);
@@ -245,6 +248,26 @@ class YOLOv3 {
245248
~YOLOv3() {
246249
this->Release();
247250
}
251+
private:
252+
image ipl_to_image(IplImage* src){
253+
image out;
254+
out.data = 0;
255+
out.h = src->height;
256+
out.w = src->width;
257+
out.c = src->nChannels;
258+
out.data = (float*)calloc(out.h*out.w*out.c, sizeof(float));
259+
unsigned char *data = (unsigned char *)src->imageData;
260+
int step = src->widthStep;
261+
int i, j, k;
262+
for (i = 0; i < out.h; ++i) {
263+
for (k = 0; k < out.c; ++k) {
264+
for (j = 0; j < out.w; ++j) {
265+
out.data[k*out.w*out.h + i*out.w + j] = data[i*step + j*out.c + k] / 255.F;
266+
}
267+
}
268+
}
269+
return out;
270+
}
248271
};
249272

250273
#endif

Yolov3_SpringEdition_Test/download_cudnn64_7.dll.bat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@echo off
22
title download_cudnn64_7.dll
3+
set cudir=%CD%
4+
cd %TEMP%
35
nvcc -V | findstr /C:"release 8.0" > cuda_ver.txt
46
set /p "ver80="<"cuda_ver.txt"
57
if not "%ver80%" equ "" (
@@ -10,9 +12,11 @@ set /p "ver90="<"cuda_ver.txt"
1012
if not "%ver90%" equ "" (
1113
powershell "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://github.com/springkim/YOLOv3_SpringEdition/releases/download/cudnn7.1cuda9.0/cudnn64_7.dll','cudnn64_7.dll')"
1214
)
15+
DEL cuda_ver.txt
16+
move cudnn64_7.dll "%cudir%"
1317
::nvcc -V | findstr /C:"release 9.1" > cuda_ver.txt
1418
::set /p "ver91="<"cuda_ver.txt"
1519
::if not "%ver91%" equ "" (
1620
:: powershell "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://www.dropbox.com/s/l0zsm9g78ciexzh/cudnn64_7.dll?dl=1','cudnn64_7.dll')"
1721
::)
18-
DEL cuda_ver.txt
22+
pause

Yolov3_SpringEdition_Test/download_darknet53.weights.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
title download_resnext50_256_10000.weights
3+
powershell "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://github.com/springkim/YOLOv3_SpringEdition/releases/download/image/resnext50_256_10000.weights','resnext50_256_10000.weights')"
4+
pause
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
curl -L https://github.com/springkim/YOLOv3_SpringEdition/releases/download/image/resnext50_256_10000.weights -o resnext50_256_10000.weights

0 commit comments

Comments
 (0)