Skip to content

Commit 7c67c0d

Browse files
committed
add yolov3-tiny
1 parent f09aa3b commit 7c67c0d

8 files changed

+1604
-0
lines changed

yolov3-tiny/CMakeLists.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
cmake_minimum_required(VERSION 2.6)
2+
3+
project(yolov3-tiny)
4+
5+
add_definitions(-std=c++11)
6+
7+
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
8+
set(CMAKE_CXX_STANDARD 11)
9+
set(CMAKE_BUILD_TYPE Debug)
10+
11+
find_package(CUDA REQUIRED)
12+
13+
set(CUDA_NVCC_PLAGS ${CUDA_NVCC_PLAGS};-std=c++11;-g;-G;-gencode;arch=compute_30;code=sm_30)
14+
15+
include_directories(${PROJECT_SOURCE_DIR}/include)
16+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
17+
message("embed_platform on")
18+
include_directories(/usr/local/cuda/targets/aarch64-linux/include)
19+
link_directories(/usr/local/cuda/targets/aarch64-linux/lib)
20+
else()
21+
message("embed_platform off")
22+
include_directories(/usr/local/cuda/include)
23+
link_directories(/usr/local/cuda/lib64)
24+
endif()
25+
26+
27+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
28+
29+
#cuda_add_library(leaky ${PROJECT_SOURCE_DIR}/leaky.cu)
30+
cuda_add_library(yololayer SHARED ${PROJECT_SOURCE_DIR}/yololayer.cu)
31+
32+
find_package(OpenCV)
33+
include_directories(OpenCV_INCLUDE_DIRS)
34+
35+
add_executable(yolov3-tiny ${PROJECT_SOURCE_DIR}/yolov3-tiny.cpp)
36+
target_link_libraries(yolov3-tiny nvinfer)
37+
target_link_libraries(yolov3-tiny cudart)
38+
target_link_libraries(yolov3-tiny yololayer)
39+
target_link_libraries(yolov3-tiny ${OpenCV_LIBS})
40+
41+
add_definitions(-O2 -pthread)
42+

yolov3-tiny/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# yolov3-tiny
2+
3+
The Pytorch implementation is [ultralytics/yolov3](https://github.com/ultralytics/yolov3).
4+
5+
## Excute:
6+
7+
```
8+
1. generate yolov3-tiny.wts from pytorch implementation with yolov3-tiny.cfg and yolov3-tiny.weights
9+
10+
git clone https://github.com/ultralytics/yolov3.git
11+
// download its weights 'yolov3-tiny.pt' or 'yolov3-tiny.weights'
12+
// put tensorrtx/yolov3-tiny/gen_wts.py into ultralytics/yolov3 and run
13+
python gen_wts.py yolov3-tiny.weights
14+
// a file 'yolov3-tiny.wts' will be generated.
15+
16+
2. put yolov3-tiny.wts into tensorrtx/yolov3-tiny, build and run
17+
18+
// go to tensorrtx/yolov3-tiny
19+
mkdir build
20+
cd build
21+
cmake ..
22+
make
23+
sudo ./yolov3-tiny -s // serialize model to plan file i.e. 'yolov3-tiny.engine'
24+
sudo ./yolov3-tiny -d ../../yolov3-spp/samples // deserialize plan file and run inference, the images in samples will be processed.
25+
26+
3. check the images generated, as follows. _zidane.jpg and _bus.jpg
27+
```
28+
29+
<p align="center">
30+
<img src="https://user-images.githubusercontent.com/15235574/78247927-4d9fac00-751e-11ea-8b1b-704a0aeb3fcf.jpg">
31+
</p>
32+
33+
<p align="center">
34+
<img src="https://user-images.githubusercontent.com/15235574/78247970-60b27c00-751e-11ea-88df-41473fed4823.jpg">
35+
</p>
36+
37+
## Config
38+
39+
- Input shape defined in yololayer.h
40+
- Number of classes defined in yololayer.h
41+
- FP16/FP32 can be selected by the macro in yolov3-tiny.cpp
42+
- GPU id can be selected by the macro in yolov3-tiny.cpp
43+
- NMS thresh in yolov3-tiny.cpp
44+
- BBox confidence thresh in yolov3-tiny.cpp
45+
46+
## More Information
47+
48+
See the readme in [home page.](https://github.com/wang-xinyu/tensorrtx)
49+

yolov3-tiny/gen_wts.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import struct
2+
import sys
3+
from models import *
4+
from utils.utils import *
5+
6+
model = Darknet('cfg/yolov3-tiny.cfg', (608, 608))
7+
weights = sys.argv[1]
8+
dev = '0'
9+
if weights.endswith('.pt'): # pytorch format
10+
model.load_state_dict(torch.load(weights, map_location=device)['model'])
11+
else: # darknet format
12+
load_darknet_weights(model, weights)
13+
model = model.eval()
14+
15+
f = open('yolov3-tiny.wts', 'w')
16+
f.write('{}\n'.format(len(model.state_dict().keys())))
17+
for k, v in model.state_dict().items():
18+
vr = v.reshape(-1).cpu().numpy()
19+
f.write('{} {} '.format(k, len(vr)))
20+
for vv in vr:
21+
f.write(' ')
22+
f.write(struct.pack('>f',float(vv)).hex())
23+
f.write('\n')
24+

0 commit comments

Comments
 (0)