Skip to content

Commit 1a82822

Browse files
committed
fix and optimize
1 parent 6161f28 commit 1a82822

File tree

9 files changed

+51
-45
lines changed

9 files changed

+51
-45
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All the models are implemented in pytorch/mxnet/tensorflown first, and export a
1010

1111
## News
1212

13+
- `29 Jan 2021`. U-Net added by [YuzhouPeng](https://github.com/YuzhouPeng).
1314
- `24 Jan 2021`. IBN-Net added by [TCHeish](https://github.com/TCHeish), PSENet optimized, YOLOv5 v4.0 INT8, etc.
1415
- `8 Jan 2021`. YOLOv5 s/m/l/x updated to v4.0.
1516
- `27 Dec 2020`. HRNet-Semantic-Segmentation added by [BaofengZan](https://github.com/BaofengZan).
@@ -24,7 +25,6 @@ All the models are implemented in pytorch/mxnet/tensorflown first, and export a
2425
- `28 Aug 2020`. [BaofengZan](https://github.com/BaofengZan) added a tutorial for compiling and running tensorrtx on windows.
2526
- `16 Aug 2020`. [upczww](https://github.com/upczww) added a python wrapper for yolov5.
2627
- `28 May 2020`. arcface LResNet50E-IR model from [deepinsight/insightface](https://github.com/deepinsight/insightface) implemented. We got 333fps on GTX1080.
27-
- `22 May 2020`. A new branch [trt4](https://github.com/wang-xinyu/tensorrtx/tree/trt4) created, which is using TensorRT 4 API. Now the master branch is using TensorRT 7 API. But only `yolov4` has been migrated to TensorRT 7 API for now. The rest will be migrated soon. And a tutorial for `migarating from TensorRT 4 to 7` provided.
2828

2929
## Tutorials
3030

@@ -79,6 +79,7 @@ Following models are implemented.
7979
|[hrnet](./hrnet)| hrnet-image-classification and hrnet-semantic-segmentation, pytorch implementation from [HRNet-Image-Classification](https://github.com/HRNet/HRNet-Image-Classification) and [HRNet-Semantic-Segmentation](https://github.com/HRNet/HRNet-Semantic-Segmentation) |
8080
|[psenet](./psenet)| PSENet Text Detection, tensorflow implementation from [liuheng92/tensorflow_PSENet](https://github.com/liuheng92/tensorflow_PSENet) |
8181
|[ibnnet](./ibnnet)| IBN-Net, pytorch implementation from [XingangPan/IBN-Net](https://github.com/XingangPan/IBN-Net), ECCV2018 |
82+
|[unet](./unet)| U-Net, pytorch implementation from [milesial/Pytorch-UNet](https://github.com/milesial/Pytorch-UNet) |
8283

8384
## Model Zoo
8485

hrnet/hrnet-image-classification/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include_directories(/usr/local/cuda/include)
1313
link_directories(/usr/local/cuda/lib64)
1414

1515
find_package(OpenCV)
16-
include_directories(OpenCV_INCLUDE_DIRS)
16+
include_directories(${OpenCV_INCLUDE_DIRS})
1717

1818
add_executable(hrnet ${PROJECT_SOURCE_DIR}/hrnet.cpp)
1919
target_link_libraries(hrnet nvinfer)

hrnet/hrnet-semantic-segmentation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ link_directories(/usr/lib/x86_64-linux-gnu/)
2222
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
2323

2424
find_package(OpenCV)
25-
include_directories(OpenCV_INCLUDE_DIRS)
25+
include_directories(${OpenCV_INCLUDE_DIRS})
2626

2727
add_executable(hrnetseg ${PROJECT_SOURCE_DIR}/hrnetseg.cpp)
2828
target_link_libraries(hrnetseg nvinfer)

unet/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ add_definitions(-O2 -pthread)
3030

3131
# opencv library
3232
find_package(OpenCV)
33-
include_directories(OpenCV_INCLUDE_DIRS)
34-
target_link_libraries(unet ${OpenCV_LIBS})
33+
include_directories(${OpenCV_INCLUDE_DIRS})
34+
target_link_libraries(unet ${OpenCV_LIBS})

yolov5/calibrator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <fstream>
44
#include <opencv2/dnn/dnn.hpp>
55
#include "calibrator.h"
6-
#include "cuda_runtime_api.h"
6+
#include "cuda_utils.h"
77
#include "utils.h"
88

99
Int8EntropyCalibrator2::Int8EntropyCalibrator2(int batchsize, int input_w, int input_h, const char* img_dir, const char* calib_table_name, const char* input_blob_name, bool read_cache)

yolov5/cuda_utils.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef TRTX_CUDA_UTILS_H_
2+
#define TRTX_CUDA_UTILS_H_
3+
4+
#include <cuda_runtime_api.h>
5+
6+
#ifndef CUDA_CHECK
7+
#define CUDA_CHECK(callstr)\
8+
{\
9+
cudaError_t error_code = callstr;\
10+
if (error_code != cudaSuccess) {\
11+
std::cerr << "CUDA error " << error_code << " at " << __FILE__ << ":" << __LINE__;\
12+
assert(0);\
13+
}\
14+
}
15+
#endif // CUDA_CHECK
16+
17+
#endif // TRTX_CUDA_UTILS_H_
18+

yolov5/utils.h

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,9 @@
1-
#ifndef __TRT_UTILS_H_
2-
#define __TRT_UTILS_H_
1+
#ifndef TRTX_YOLOV5_UTILS_H_
2+
#define TRTX_YOLOV5_UTILS_H_
33

4-
#include <iostream>
5-
#include <vector>
6-
#include <algorithm>
7-
#include <cudnn.h>
84
#include <dirent.h>
95
#include <opencv2/opencv.hpp>
106

11-
#ifndef CUDA_CHECK
12-
13-
#define CUDA_CHECK(callstr) \
14-
{ \
15-
cudaError_t error_code = callstr; \
16-
if (error_code != cudaSuccess) { \
17-
std::cerr << "CUDA error " << error_code << " at " << __FILE__ << ":" << __LINE__; \
18-
assert(0); \
19-
} \
20-
}
21-
22-
#endif
23-
24-
namespace Tn
25-
{
26-
template<typename T>
27-
void write(char*& buffer, const T& val)
28-
{
29-
*reinterpret_cast<T*>(buffer) = val;
30-
buffer += sizeof(T);
31-
}
32-
33-
template<typename T>
34-
void read(const char*& buffer, T& val)
35-
{
36-
val = *reinterpret_cast<const T*>(buffer);
37-
buffer += sizeof(T);
38-
}
39-
}
40-
417
static inline cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h) {
428
int w, h, x, y;
439
float r_w = input_w / (img.cols*1.0);
@@ -82,4 +48,5 @@ static inline int read_files_in_dir(const char *p_dir_name, std::vector<std::str
8248
return 0;
8349
}
8450

85-
#endif
51+
#endif // TRTX_YOLOV5_UTILS_H_
52+

yolov5/yololayer.cu

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
#include <assert.h>
2+
#include <vector>
3+
#include <iostream>
24
#include "yololayer.h"
3-
#include "utils.h"
5+
#include "cuda_utils.h"
6+
7+
namespace Tn
8+
{
9+
template<typename T>
10+
void write(char*& buffer, const T& val)
11+
{
12+
*reinterpret_cast<T*>(buffer) = val;
13+
buffer += sizeof(T);
14+
}
15+
16+
template<typename T>
17+
void read(const char*& buffer, T& val)
18+
{
19+
val = *reinterpret_cast<const T*>(buffer);
20+
buffer += sizeof(T);
21+
}
22+
}
423

524
using namespace Yolo;
625

@@ -311,3 +330,4 @@ namespace nvinfer1
311330
return obj;
312331
}
313332
}
333+

yolov5/yolov5.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <iostream>
22
#include <chrono>
3-
#include "cuda_runtime_api.h"
3+
#include "cuda_utils.h"
44
#include "logging.h"
55
#include "common.hpp"
66
#include "utils.h"

0 commit comments

Comments
 (0)