diff --git a/yolov5/README.md b/yolov5/README.md
index cdae023..8aef754 100644
--- a/yolov5/README.md
+++ b/yolov5/README.md
@@ -49,14 +49,8 @@ Currently, we support yolov5 v1.0, v2.0, v3.0, v3.1, v4.0, v5.0, v6.0, v6.2, v7.
## Config
-- Choose the model n/s/m/l/x/n6/s6/m6/l6/x6 from command line arguments.
-- Input shape defined in yololayer.h
-- Number of classes defined in yololayer.h, **DO NOT FORGET TO ADAPT THIS, If using your own model**
-- INT8/FP16/FP32 can be selected by the macro in yolov5.cpp, **INT8 need more steps, pls follow `How to Run` first and then go the `INT8 Quantization` below**
-- GPU id can be selected by the macro in yolov5.cpp
-- NMS thresh in yolov5.cpp
-- BBox confidence thresh in yolov5.cpp
-- Batch size in yolov5.cpp
+- Choose the YOLOv5 sub-model n/s/m/l/x/n6/s6/m6/l6/x6 from command line arguments.
+- Other configs please check src/config.h
## Build and Run
@@ -83,14 +77,14 @@ cd build
cp {ultralytics}/yolov5/yolov5s.wts {tensorrtx}/yolov5/build
cmake ..
make
-sudo ./yolov5_det -s [.wts] [.engine] [n/s/m/l/x/n6/s6/m6/l6/x6 or c/c6 gd gw] // serialize model to plan file
-sudo ./yolov5_det -d [.engine] [image folder] // deserialize and run inference, the images in [image folder] will be processed.
+./yolov5_det -s [.wts] [.engine] [n/s/m/l/x/n6/s6/m6/l6/x6 or c/c6 gd gw] // serialize model to plan file
+./yolov5_det -d [.engine] [image folder] // deserialize and run inference, the images in [image folder] will be processed.
// For example yolov5s
-sudo ./yolov5_det -s yolov5s.wts yolov5s.engine s
-sudo ./yolov5_det -d yolov5s.engine ../samples
+./yolov5_det -s yolov5s.wts yolov5s.engine s
+./yolov5_det -d yolov5s.engine ../images
// For example Custom model with depth_multiple=0.17, width_multiple=0.25 in yolov5.yaml
-sudo ./yolov5_det -s yolov5_custom.wts yolov5.engine c 0.17 0.25
-sudo ./yolov5_det -d yolov5.engine ../samples
+./yolov5_det -s yolov5_custom.wts yolov5.engine c 0.17 0.25
+./yolov5_det -d yolov5.engine ../images
```
3. check the images generated, as follows. _zidane.jpg and _bus.jpg
@@ -120,7 +114,7 @@ wget https://github.com/joannzhang00/ImageNet-dataset-classes-labels/blob/main/i
./yolov5_cls -s yolov5s-cls.wts yolov5s-cls.engine s
# Run inference
-./yolov5_cls -d yolov5s-cls.engine ../samples
+./yolov5_cls -d yolov5s-cls.engine ../images
```
### Instance Segmentation
@@ -133,7 +127,7 @@ wget https://github.com/joannzhang00/ImageNet-dataset-classes-labels/blob/main/i
wget -O coco.txt https://raw.githubusercontent.com/amikelive/coco-labels/master/coco-labels-2014_2017.txt
# Run inference with labels file
-./yolov5_seg -d yolov5s-seg.engine ../samples coco.txt
+./yolov5_seg -d yolov5s-seg.engine ../images coco.txt
```
@@ -146,7 +140,7 @@ wget -O coco.txt https://raw.githubusercontent.com/amikelive/coco-labels/master/
2. unzip it in yolov5/build
-3. set the macro `USE_INT8` in yolov5.cpp and make
+3. set the macro `USE_INT8` in src/config.h and make
4. serialize the model and test
diff --git a/yolov5/images b/yolov5/images
new file mode 120000
index 0000000..02cc755
--- /dev/null
+++ b/yolov5/images
@@ -0,0 +1 @@
+../yolov3-spp/samples
\ No newline at end of file
diff --git a/yolov5/plugin/yololayer.cu b/yolov5/plugin/yololayer.cu
index 02dcd4c..d80a9a4 100644
--- a/yolov5/plugin/yololayer.cu
+++ b/yolov5/plugin/yololayer.cu
@@ -1,322 +1,280 @@
-#include
-#include
-#include
#include "yololayer.h"
#include "cuda_utils.h"
-namespace Tn
-{
- template
- void write(char*& buffer, const T& val)
- {
- *reinterpret_cast(buffer) = val;
- buffer += sizeof(T);
- }
+#include
+#include
+#include
- template
- void read(const char*& buffer, T& val)
- {
- val = *reinterpret_cast(buffer);
- buffer += sizeof(T);
- }
+namespace Tn {
+template
+void write(char*& buffer, const T& val) {
+ *reinterpret_cast(buffer) = val;
+ buffer += sizeof(T);
}
-using namespace Yolo;
-
-namespace nvinfer1
-{
- YoloLayerPlugin::YoloLayerPlugin(int classCount, int netWidth, int netHeight, int maxOut, bool is_segmentation, const std::vector& vYoloKernel)
- {
- mClassCount = classCount;
- mYoloV5NetWidth = netWidth;
- mYoloV5NetHeight = netHeight;
- mMaxOutObject = maxOut;
- is_segmentation_ = is_segmentation;
- mYoloKernel = vYoloKernel;
- mKernelCount = vYoloKernel.size();
-
- CUDA_CHECK(cudaMallocHost(&mAnchor, mKernelCount * sizeof(void*)));
- size_t AnchorLen = sizeof(float)* CHECK_COUNT * 2;
- for (int ii = 0; ii < mKernelCount; ii++)
- {
- CUDA_CHECK(cudaMalloc(&mAnchor[ii], AnchorLen));
- const auto& yolo = mYoloKernel[ii];
- CUDA_CHECK(cudaMemcpy(mAnchor[ii], yolo.anchors, AnchorLen, cudaMemcpyHostToDevice));
- }
- }
- YoloLayerPlugin::~YoloLayerPlugin()
- {
- for (int ii = 0; ii < mKernelCount; ii++)
- {
- CUDA_CHECK(cudaFree(mAnchor[ii]));
- }
- CUDA_CHECK(cudaFreeHost(mAnchor));
- }
-
- // create the plugin at runtime from a byte stream
- YoloLayerPlugin::YoloLayerPlugin(const void* data, size_t length)
- {
- using namespace Tn;
- const char *d = reinterpret_cast(data), *a = d;
- read(d, mClassCount);
- read(d, mThreadCount);
- read(d, mKernelCount);
- read(d, mYoloV5NetWidth);
- read(d, mYoloV5NetHeight);
- read(d, mMaxOutObject);
- read(d, is_segmentation_);
- mYoloKernel.resize(mKernelCount);
- auto kernelSize = mKernelCount * sizeof(YoloKernel);
- memcpy(mYoloKernel.data(), d, kernelSize);
- d += kernelSize;
- CUDA_CHECK(cudaMallocHost(&mAnchor, mKernelCount * sizeof(void*)));
- size_t AnchorLen = sizeof(float)* CHECK_COUNT * 2;
- for (int ii = 0; ii < mKernelCount; ii++)
- {
- CUDA_CHECK(cudaMalloc(&mAnchor[ii], AnchorLen));
- const auto& yolo = mYoloKernel[ii];
- CUDA_CHECK(cudaMemcpy(mAnchor[ii], yolo.anchors, AnchorLen, cudaMemcpyHostToDevice));
- }
- assert(d == a + length);
- }
-
- void YoloLayerPlugin::serialize(void* buffer) const TRT_NOEXCEPT
- {
- using namespace Tn;
- char* d = static_cast(buffer), *a = d;
- write(d, mClassCount);
- write(d, mThreadCount);
- write(d, mKernelCount);
- write(d, mYoloV5NetWidth);
- write(d, mYoloV5NetHeight);
- write(d, mMaxOutObject);
- write(d, is_segmentation_);
- auto kernelSize = mKernelCount * sizeof(YoloKernel);
- memcpy(d, mYoloKernel.data(), kernelSize);
- d += kernelSize;
-
- assert(d == a + getSerializationSize());
- }
-
- size_t YoloLayerPlugin::getSerializationSize() const TRT_NOEXCEPT
- {
- return sizeof(mClassCount) + sizeof(mThreadCount) + sizeof(mKernelCount) + sizeof(Yolo::YoloKernel) * mYoloKernel.size() + sizeof(mYoloV5NetWidth) + sizeof(mYoloV5NetHeight) + sizeof(mMaxOutObject) + sizeof(is_segmentation_);
- }
-
- int YoloLayerPlugin::initialize() TRT_NOEXCEPT
- {
- return 0;
- }
-
- Dims YoloLayerPlugin::getOutputDimensions(int index, const Dims* inputs, int nbInputDims) TRT_NOEXCEPT
- {
- //output the result to channel
- int totalsize = mMaxOutObject * sizeof(Detection) / sizeof(float);
-
- return Dims3(totalsize + 1, 1, 1);
- }
-
- // Set plugin namespace
- void YoloLayerPlugin::setPluginNamespace(const char* pluginNamespace) TRT_NOEXCEPT
- {
- mPluginNamespace = pluginNamespace;
- }
-
- const char* YoloLayerPlugin::getPluginNamespace() const TRT_NOEXCEPT
- {
- return mPluginNamespace;
- }
-
- // Return the DataType of the plugin output at the requested index
- DataType YoloLayerPlugin::getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const TRT_NOEXCEPT
- {
- return DataType::kFLOAT;
- }
-
- // Return true if output tensor is broadcast across a batch.
- bool YoloLayerPlugin::isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const TRT_NOEXCEPT
- {
- return false;
- }
-
- // Return true if plugin can use input that is broadcast across batch without replication.
- bool YoloLayerPlugin::canBroadcastInputAcrossBatch(int inputIndex) const TRT_NOEXCEPT
- {
- return false;
- }
-
- void YoloLayerPlugin::configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) TRT_NOEXCEPT
- {
- }
-
- // Attach the plugin object to an execution context and grant the plugin the access to some context resource.
- void YoloLayerPlugin::attachToContext(cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) TRT_NOEXCEPT
- {
- }
-
- // Detach the plugin object from its execution context.
- void YoloLayerPlugin::detachFromContext() TRT_NOEXCEPT {}
-
- const char* YoloLayerPlugin::getPluginType() const TRT_NOEXCEPT
- {
- return "YoloLayer_TRT";
- }
-
- const char* YoloLayerPlugin::getPluginVersion() const TRT_NOEXCEPT
- {
- return "1";
- }
-
- void YoloLayerPlugin::destroy() TRT_NOEXCEPT
- {
- delete this;
- }
-
- // Clone the plugin
- IPluginV2IOExt* YoloLayerPlugin::clone() const TRT_NOEXCEPT
- {
- YoloLayerPlugin* p = new YoloLayerPlugin(mClassCount, mYoloV5NetWidth, mYoloV5NetHeight, mMaxOutObject, is_segmentation_, mYoloKernel);
- p->setPluginNamespace(mPluginNamespace);
- return p;
- }
-
- __device__ float Logist(float data) { return 1.0f / (1.0f + expf(-data)); };
-
- __global__ void CalDetection(const float *input, float *output, int noElements,
- const int netwidth, const int netheight, int maxoutobject, int yoloWidth, int yoloHeight, const float anchors[CHECK_COUNT * 2], int classes, int outputElem, bool is_segmentation)
- {
-
- int idx = threadIdx.x + blockDim.x * blockIdx.x;
- if (idx >= noElements) return;
-
- int total_grid = yoloWidth * yoloHeight;
- int bnIdx = idx / total_grid;
- idx = idx - total_grid * bnIdx;
- int info_len_i = 5 + classes;
- if (is_segmentation) info_len_i += 32;
- const float* curInput = input + bnIdx * (info_len_i * total_grid * CHECK_COUNT);
-
- for (int k = 0; k < CHECK_COUNT; ++k) {
- float box_prob = Logist(curInput[idx + k * info_len_i * total_grid + 4 * total_grid]);
- if (box_prob < IGNORE_THRESH) continue;
- int class_id = 0;
- float max_cls_prob = 0.0;
- for (int i = 5; i < 5 + classes; ++i) {
- float p = Logist(curInput[idx + k * info_len_i * total_grid + i * total_grid]);
- if (p > max_cls_prob) {
- max_cls_prob = p;
- class_id = i - 5;
- }
- }
- float *res_count = output + bnIdx * outputElem;
- int count = (int)atomicAdd(res_count, 1);
- if (count >= maxoutobject) return;
- char *data = (char*)res_count + sizeof(float) + count * sizeof(Detection);
- Detection *det = (Detection*)(data);
-
- int row = idx / yoloWidth;
- int col = idx % yoloWidth;
-
- //Location
- // pytorch:
- // y = x[i].sigmoid()
- // y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + self.grid[i].to(x[i].device)) * self.stride[i] # xy
- // y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i] # wh
- // X: (sigmoid(tx) + cx)/FeaturemapW * netwidth
- det->bbox[0] = (col - 0.5f + 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 0 * total_grid])) * netwidth / yoloWidth;
- det->bbox[1] = (row - 0.5f + 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 1 * total_grid])) * netheight / yoloHeight;
-
- // W: (Pw * e^tw) / FeaturemapW * netwidth
- // v5: https://github.com/ultralytics/yolov5/issues/471
- det->bbox[2] = 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 2 * total_grid]);
- det->bbox[2] = det->bbox[2] * det->bbox[2] * anchors[2 * k];
- det->bbox[3] = 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 3 * total_grid]);
- det->bbox[3] = det->bbox[3] * det->bbox[3] * anchors[2 * k + 1];
- det->conf = box_prob * max_cls_prob;
- det->class_id = class_id;
-
- for (int i = 0; is_segmentation && i < 32; i++) {
- det->mask[i] = curInput[idx + k * info_len_i * total_grid + (i + 5 + classes) * total_grid];
- }
- }
- }
-
- void YoloLayerPlugin::forwardGpu(const float* const* inputs, float *output, cudaStream_t stream, int batchSize)
- {
- int outputElem = 1 + mMaxOutObject * sizeof(Detection) / sizeof(float);
- for (int idx = 0; idx < batchSize; ++idx) {
- CUDA_CHECK(cudaMemsetAsync(output + idx * outputElem, 0, sizeof(float), stream));
- }
- int numElem = 0;
- for (unsigned int i = 0; i < mYoloKernel.size(); ++i) {
- const auto& yolo = mYoloKernel[i];
- numElem = yolo.width * yolo.height * batchSize;
- if (numElem < mThreadCount) mThreadCount = numElem;
-
- //printf("Net: %d %d \n", mYoloV5NetWidth, mYoloV5NetHeight);
- CalDetection << < (numElem + mThreadCount - 1) / mThreadCount, mThreadCount, 0, stream >> >
- (inputs[i], output, numElem, mYoloV5NetWidth, mYoloV5NetHeight, mMaxOutObject, yolo.width, yolo.height, (float*)mAnchor[i], mClassCount, outputElem, is_segmentation_);
- }
- }
-
-
- int YoloLayerPlugin::enqueue(int batchSize, const void* const* inputs, void* TRT_CONST_ENQUEUE* outputs, void* workspace, cudaStream_t stream) TRT_NOEXCEPT
- {
- forwardGpu((const float* const*)inputs, (float*)outputs[0], stream, batchSize);
- return 0;
- }
-
- PluginFieldCollection YoloPluginCreator::mFC{};
- std::vector YoloPluginCreator::mPluginAttributes;
-
- YoloPluginCreator::YoloPluginCreator()
- {
- mPluginAttributes.clear();
-
- mFC.nbFields = mPluginAttributes.size();
- mFC.fields = mPluginAttributes.data();
- }
-
- const char* YoloPluginCreator::getPluginName() const TRT_NOEXCEPT
- {
- return "YoloLayer_TRT";
- }
-
- const char* YoloPluginCreator::getPluginVersion() const TRT_NOEXCEPT
- {
- return "1";
- }
-
- const PluginFieldCollection* YoloPluginCreator::getFieldNames() TRT_NOEXCEPT
- {
- return &mFC;
- }
-
- IPluginV2IOExt* YoloPluginCreator::createPlugin(const char* name, const PluginFieldCollection* fc) TRT_NOEXCEPT
- {
- assert(fc->nbFields == 2);
- assert(strcmp(fc->fields[0].name, "netinfo") == 0);
- assert(strcmp(fc->fields[1].name, "kernels") == 0);
- int *p_netinfo = (int*)(fc->fields[0].data);
- int class_count = p_netinfo[0];
- int input_w = p_netinfo[1];
- int input_h = p_netinfo[2];
- int max_output_object_count = p_netinfo[3];
- bool is_segmentation = (bool)p_netinfo[4];
- std::vector kernels(fc->fields[1].length);
- memcpy(&kernels[0], fc->fields[1].data, kernels.size() * sizeof(Yolo::YoloKernel));
- YoloLayerPlugin* obj = new YoloLayerPlugin(class_count, input_w, input_h, max_output_object_count, is_segmentation, kernels);
- obj->setPluginNamespace(mNamespace.c_str());
- return obj;
- }
-
- IPluginV2IOExt* YoloPluginCreator::deserializePlugin(const char* name, const void* serialData, size_t serialLength) TRT_NOEXCEPT
- {
- // This object will be deleted when the network is destroyed, which will
- // call YoloLayerPlugin::destroy()
- YoloLayerPlugin* obj = new YoloLayerPlugin(serialData, serialLength);
- obj->setPluginNamespace(mNamespace.c_str());
- return obj;
- }
+template
+void read(const char*& buffer, T& val) {
+ val = *reinterpret_cast(buffer);
+ buffer += sizeof(T);
+}
+}
+
+namespace nvinfer1 {
+YoloLayerPlugin::YoloLayerPlugin(int classCount, int netWidth, int netHeight, int maxOut, bool is_segmentation, const std::vector& vYoloKernel) {
+ mClassCount = classCount;
+ mYoloV5NetWidth = netWidth;
+ mYoloV5NetHeight = netHeight;
+ mMaxOutObject = maxOut;
+ is_segmentation_ = is_segmentation;
+ mYoloKernel = vYoloKernel;
+ mKernelCount = vYoloKernel.size();
+
+ CUDA_CHECK(cudaMallocHost(&mAnchor, mKernelCount * sizeof(void*)));
+ size_t AnchorLen = sizeof(float)* kNumAnchor * 2;
+ for (int ii = 0; ii < mKernelCount; ii++) {
+ CUDA_CHECK(cudaMalloc(&mAnchor[ii], AnchorLen));
+ const auto& yolo = mYoloKernel[ii];
+ CUDA_CHECK(cudaMemcpy(mAnchor[ii], yolo.anchors, AnchorLen, cudaMemcpyHostToDevice));
+ }
+}
+
+YoloLayerPlugin::~YoloLayerPlugin() {
+ for (int ii = 0; ii < mKernelCount; ii++) {
+ CUDA_CHECK(cudaFree(mAnchor[ii]));
+ }
+ CUDA_CHECK(cudaFreeHost(mAnchor));
+}
+
+// create the plugin at runtime from a byte stream
+YoloLayerPlugin::YoloLayerPlugin(const void* data, size_t length) {
+ using namespace Tn;
+ const char *d = reinterpret_cast(data), *a = d;
+ read(d, mClassCount);
+ read(d, mThreadCount);
+ read(d, mKernelCount);
+ read(d, mYoloV5NetWidth);
+ read(d, mYoloV5NetHeight);
+ read(d, mMaxOutObject);
+ read(d, is_segmentation_);
+ mYoloKernel.resize(mKernelCount);
+ auto kernelSize = mKernelCount * sizeof(YoloKernel);
+ memcpy(mYoloKernel.data(), d, kernelSize);
+ d += kernelSize;
+ CUDA_CHECK(cudaMallocHost(&mAnchor, mKernelCount * sizeof(void*)));
+ size_t AnchorLen = sizeof(float)* kNumAnchor * 2;
+ for (int ii = 0; ii < mKernelCount; ii++) {
+ CUDA_CHECK(cudaMalloc(&mAnchor[ii], AnchorLen));
+ const auto& yolo = mYoloKernel[ii];
+ CUDA_CHECK(cudaMemcpy(mAnchor[ii], yolo.anchors, AnchorLen, cudaMemcpyHostToDevice));
+ }
+ assert(d == a + length);
+}
+
+void YoloLayerPlugin::serialize(void* buffer) const TRT_NOEXCEPT {
+ using namespace Tn;
+ char* d = static_cast(buffer), *a = d;
+ write(d, mClassCount);
+ write(d, mThreadCount);
+ write(d, mKernelCount);
+ write(d, mYoloV5NetWidth);
+ write(d, mYoloV5NetHeight);
+ write(d, mMaxOutObject);
+ write(d, is_segmentation_);
+ auto kernelSize = mKernelCount * sizeof(YoloKernel);
+ memcpy(d, mYoloKernel.data(), kernelSize);
+ d += kernelSize;
+
+ assert(d == a + getSerializationSize());
+}
+
+size_t YoloLayerPlugin::getSerializationSize() const TRT_NOEXCEPT {
+ size_t s = sizeof(mClassCount) + sizeof(mThreadCount) + sizeof(mKernelCount);
+ s += sizeof(YoloKernel) * mYoloKernel.size();
+ s += sizeof(mYoloV5NetWidth) + sizeof(mYoloV5NetHeight);
+ s += sizeof(mMaxOutObject) + sizeof(is_segmentation_);
+ return s;
+}
+
+int YoloLayerPlugin::initialize() TRT_NOEXCEPT {
+ return 0;
+}
+
+Dims YoloLayerPlugin::getOutputDimensions(int index, const Dims* inputs, int nbInputDims) TRT_NOEXCEPT {
+ //output the result to channel
+ int totalsize = mMaxOutObject * sizeof(Detection) / sizeof(float);
+ return Dims3(totalsize + 1, 1, 1);
+}
+
+// Set plugin namespace
+void YoloLayerPlugin::setPluginNamespace(const char* pluginNamespace) TRT_NOEXCEPT {
+ mPluginNamespace = pluginNamespace;
+}
+
+const char* YoloLayerPlugin::getPluginNamespace() const TRT_NOEXCEPT {
+ return mPluginNamespace;
+}
+
+// Return the DataType of the plugin output at the requested index
+DataType YoloLayerPlugin::getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const TRT_NOEXCEPT {
+ return DataType::kFLOAT;
+}
+
+// Return true if output tensor is broadcast across a batch.
+bool YoloLayerPlugin::isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const TRT_NOEXCEPT {
+ return false;
+}
+
+// Return true if plugin can use input that is broadcast across batch without replication.
+bool YoloLayerPlugin::canBroadcastInputAcrossBatch(int inputIndex) const TRT_NOEXCEPT {
+ return false;
+}
+
+void YoloLayerPlugin::configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) TRT_NOEXCEPT {}
+
+// Attach the plugin object to an execution context and grant the plugin the access to some context resource.
+void YoloLayerPlugin::attachToContext(cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) TRT_NOEXCEPT {}
+
+// Detach the plugin object from its execution context.
+void YoloLayerPlugin::detachFromContext() TRT_NOEXCEPT {}
+
+const char* YoloLayerPlugin::getPluginType() const TRT_NOEXCEPT {
+ return "YoloLayer_TRT";
+}
+
+const char* YoloLayerPlugin::getPluginVersion() const TRT_NOEXCEPT {
+ return "1";
+}
+
+void YoloLayerPlugin::destroy() TRT_NOEXCEPT {
+ delete this;
+}
+
+// Clone the plugin
+IPluginV2IOExt* YoloLayerPlugin::clone() const TRT_NOEXCEPT {
+ YoloLayerPlugin* p = new YoloLayerPlugin(mClassCount, mYoloV5NetWidth, mYoloV5NetHeight, mMaxOutObject, is_segmentation_, mYoloKernel);
+ p->setPluginNamespace(mPluginNamespace);
+ return p;
+}
+
+__device__ float Logist(float data) { return 1.0f / (1.0f + expf(-data)); };
+
+__global__ void CalDetection(const float *input, float *output, int noElements,
+ const int netwidth, const int netheight, int maxoutobject, int yoloWidth,
+ int yoloHeight, const float anchors[kNumAnchor * 2], int classes, int outputElem, bool is_segmentation) {
+
+ int idx = threadIdx.x + blockDim.x * blockIdx.x;
+ if (idx >= noElements) return;
+
+ int total_grid = yoloWidth * yoloHeight;
+ int bnIdx = idx / total_grid;
+ idx = idx - total_grid * bnIdx;
+ int info_len_i = 5 + classes;
+ if (is_segmentation) info_len_i += 32;
+ const float* curInput = input + bnIdx * (info_len_i * total_grid * kNumAnchor);
+
+ for (int k = 0; k < kNumAnchor; ++k) {
+ float box_prob = Logist(curInput[idx + k * info_len_i * total_grid + 4 * total_grid]);
+ if (box_prob < kIgnoreThresh) continue;
+ int class_id = 0;
+ float max_cls_prob = 0.0;
+ for (int i = 5; i < 5 + classes; ++i) {
+ float p = Logist(curInput[idx + k * info_len_i * total_grid + i * total_grid]);
+ if (p > max_cls_prob) {
+ max_cls_prob = p;
+ class_id = i - 5;
+ }
+ }
+ float *res_count = output + bnIdx * outputElem;
+ int count = (int)atomicAdd(res_count, 1);
+ if (count >= maxoutobject) return;
+ char *data = (char*)res_count + sizeof(float) + count * sizeof(Detection);
+ Detection *det = (Detection*)(data);
+
+ int row = idx / yoloWidth;
+ int col = idx % yoloWidth;
+
+ det->bbox[0] = (col - 0.5f + 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 0 * total_grid])) * netwidth / yoloWidth;
+ det->bbox[1] = (row - 0.5f + 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 1 * total_grid])) * netheight / yoloHeight;
+
+ det->bbox[2] = 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 2 * total_grid]);
+ det->bbox[2] = det->bbox[2] * det->bbox[2] * anchors[2 * k];
+ det->bbox[3] = 2.0f * Logist(curInput[idx + k * info_len_i * total_grid + 3 * total_grid]);
+ det->bbox[3] = det->bbox[3] * det->bbox[3] * anchors[2 * k + 1];
+ det->conf = box_prob * max_cls_prob;
+ det->class_id = class_id;
+
+ for (int i = 0; is_segmentation && i < 32; i++) {
+ det->mask[i] = curInput[idx + k * info_len_i * total_grid + (i + 5 + classes) * total_grid];
+ }
+ }
+}
+
+void YoloLayerPlugin::forwardGpu(const float* const* inputs, float *output, cudaStream_t stream, int batchSize) {
+ int outputElem = 1 + mMaxOutObject * sizeof(Detection) / sizeof(float);
+ for (int idx = 0; idx < batchSize; ++idx) {
+ CUDA_CHECK(cudaMemsetAsync(output + idx * outputElem, 0, sizeof(float), stream));
+ }
+ int numElem = 0;
+ for (unsigned int i = 0; i < mYoloKernel.size(); ++i) {
+ const auto& yolo = mYoloKernel[i];
+ numElem = yolo.width * yolo.height * batchSize;
+ if (numElem < mThreadCount) mThreadCount = numElem;
+
+ CalDetection << < (numElem + mThreadCount - 1) / mThreadCount, mThreadCount, 0, stream >> >
+ (inputs[i], output, numElem, mYoloV5NetWidth, mYoloV5NetHeight, mMaxOutObject, yolo.width, yolo.height, (float*)mAnchor[i], mClassCount, outputElem, is_segmentation_);
+ }
+}
+
+
+int YoloLayerPlugin::enqueue(int batchSize, const void* const* inputs, void* TRT_CONST_ENQUEUE* outputs, void* workspace, cudaStream_t stream) TRT_NOEXCEPT {
+ forwardGpu((const float* const*)inputs, (float*)outputs[0], stream, batchSize);
+ return 0;
+}
+
+PluginFieldCollection YoloPluginCreator::mFC{};
+std::vector YoloPluginCreator::mPluginAttributes;
+
+YoloPluginCreator::YoloPluginCreator() {
+ mPluginAttributes.clear();
+ mFC.nbFields = mPluginAttributes.size();
+ mFC.fields = mPluginAttributes.data();
+}
+
+const char* YoloPluginCreator::getPluginName() const TRT_NOEXCEPT {
+ return "YoloLayer_TRT";
+}
+
+const char* YoloPluginCreator::getPluginVersion() const TRT_NOEXCEPT {
+ return "1";
+}
+
+const PluginFieldCollection* YoloPluginCreator::getFieldNames() TRT_NOEXCEPT {
+ return &mFC;
+}
+
+IPluginV2IOExt* YoloPluginCreator::createPlugin(const char* name, const PluginFieldCollection* fc) TRT_NOEXCEPT {
+ assert(fc->nbFields == 2);
+ assert(strcmp(fc->fields[0].name, "netinfo") == 0);
+ assert(strcmp(fc->fields[1].name, "kernels") == 0);
+ int *p_netinfo = (int*)(fc->fields[0].data);
+ int class_count = p_netinfo[0];
+ int input_w = p_netinfo[1];
+ int input_h = p_netinfo[2];
+ int max_output_object_count = p_netinfo[3];
+ bool is_segmentation = (bool)p_netinfo[4];
+ std::vector kernels(fc->fields[1].length);
+ memcpy(&kernels[0], fc->fields[1].data, kernels.size() * sizeof(YoloKernel));
+ YoloLayerPlugin* obj = new YoloLayerPlugin(class_count, input_w, input_h, max_output_object_count, is_segmentation, kernels);
+ obj->setPluginNamespace(mNamespace.c_str());
+ return obj;
+}
+
+IPluginV2IOExt* YoloPluginCreator::deserializePlugin(const char* name, const void* serialData, size_t serialLength) TRT_NOEXCEPT {
+ // This object will be deleted when the network is destroyed, which will
+ // call YoloLayerPlugin::destroy()
+ YoloLayerPlugin* obj = new YoloLayerPlugin(serialData, serialLength);
+ obj->setPluginNamespace(mNamespace.c_str());
+ return obj;
+}
}
diff --git a/yolov5/plugin/yololayer.h b/yolov5/plugin/yololayer.h
index cbf6427..a73190b 100644
--- a/yolov5/plugin/yololayer.h
+++ b/yolov5/plugin/yololayer.h
@@ -1,140 +1,106 @@
-#ifndef _YOLO_LAYER_H
-#define _YOLO_LAYER_H
+#pragma once
+
+#include "types.h"
+#include "macros.h"
#include
#include
-#include
-#include "macros.h"
-namespace Yolo
-{
- static constexpr int CHECK_COUNT = 3;
- static constexpr float IGNORE_THRESH = 0.1f;
- struct YoloKernel
- {
- int width;
- int height;
- float anchors[CHECK_COUNT * 2];
- };
- static constexpr int MAX_OUTPUT_BBOX_COUNT = 1000;
- static constexpr int CLASS_NUM = 80;
- static constexpr int INPUT_H = 640; // yolov5's input height and width must be divisible by 32.
- static constexpr int INPUT_W = 640;
+namespace nvinfer1 {
+class API YoloLayerPlugin : public IPluginV2IOExt {
+public:
+ YoloLayerPlugin(int classCount, int netWidth, int netHeight, int maxOut, bool is_segmentation, const std::vector& vYoloKernel);
+ YoloLayerPlugin(const void* data, size_t length);
+ ~YoloLayerPlugin();
- static constexpr int LOCATIONS = 4;
- struct alignas(float) Detection {
- //center_x center_y w h
- float bbox[LOCATIONS];
- float conf; // bbox_conf * cls_conf
- float class_id;
- float mask[32];
- };
-}
+ int getNbOutputs() const TRT_NOEXCEPT override { return 1; }
-namespace nvinfer1
-{
- class API YoloLayerPlugin : public IPluginV2IOExt
- {
- public:
- YoloLayerPlugin(int classCount, int netWidth, int netHeight, int maxOut, bool is_segmentation, const std::vector& vYoloKernel);
- YoloLayerPlugin(const void* data, size_t length);
- ~YoloLayerPlugin();
+ Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) TRT_NOEXCEPT override;
- int getNbOutputs() const TRT_NOEXCEPT override
- {
- return 1;
- }
+ int initialize() TRT_NOEXCEPT override;
- Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) TRT_NOEXCEPT override;
+ virtual void terminate() TRT_NOEXCEPT override {};
- int initialize() TRT_NOEXCEPT override;
+ virtual size_t getWorkspaceSize(int maxBatchSize) const TRT_NOEXCEPT override { return 0; }
- virtual void terminate() TRT_NOEXCEPT override {};
+ virtual int enqueue(int batchSize, const void* const* inputs, void*TRT_CONST_ENQUEUE* outputs, void* workspace, cudaStream_t stream) TRT_NOEXCEPT override;
- virtual size_t getWorkspaceSize(int maxBatchSize) const TRT_NOEXCEPT override { return 0; }
+ virtual size_t getSerializationSize() const TRT_NOEXCEPT override;
- virtual int enqueue(int batchSize, const void* const* inputs, void*TRT_CONST_ENQUEUE* outputs, void* workspace, cudaStream_t stream) TRT_NOEXCEPT override;
+ virtual void serialize(void* buffer) const TRT_NOEXCEPT override;
- virtual size_t getSerializationSize() const TRT_NOEXCEPT override;
+ bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const TRT_NOEXCEPT override {
+ return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
+ }
- virtual void serialize(void* buffer) const TRT_NOEXCEPT override;
+ const char* getPluginType() const TRT_NOEXCEPT override;
- bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const TRT_NOEXCEPT override {
- return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
- }
+ const char* getPluginVersion() const TRT_NOEXCEPT override;
- const char* getPluginType() const TRT_NOEXCEPT override;
+ void destroy() TRT_NOEXCEPT override;
- const char* getPluginVersion() const TRT_NOEXCEPT override;
+ IPluginV2IOExt* clone() const TRT_NOEXCEPT override;
- void destroy() TRT_NOEXCEPT override;
+ void setPluginNamespace(const char* pluginNamespace) TRT_NOEXCEPT override;
- IPluginV2IOExt* clone() const TRT_NOEXCEPT override;
+ const char* getPluginNamespace() const TRT_NOEXCEPT override;
- void setPluginNamespace(const char* pluginNamespace) TRT_NOEXCEPT override;
+ DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const TRT_NOEXCEPT override;
- const char* getPluginNamespace() const TRT_NOEXCEPT override;
+ bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const TRT_NOEXCEPT override;
- DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const TRT_NOEXCEPT override;
+ bool canBroadcastInputAcrossBatch(int inputIndex) const TRT_NOEXCEPT override;
- bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const TRT_NOEXCEPT override;
+ void attachToContext(
+ cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) TRT_NOEXCEPT override;
- bool canBroadcastInputAcrossBatch(int inputIndex) const TRT_NOEXCEPT override;
+ void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) TRT_NOEXCEPT override;
- void attachToContext(
- cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) TRT_NOEXCEPT override;
+ void detachFromContext() TRT_NOEXCEPT override;
- void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) TRT_NOEXCEPT override;
-
- void detachFromContext() TRT_NOEXCEPT override;
-
- private:
- void forwardGpu(const float* const* inputs, float *output, cudaStream_t stream, int batchSize = 1);
- int mThreadCount = 256;
- const char* mPluginNamespace;
- int mKernelCount;
- int mClassCount;
- int mYoloV5NetWidth;
- int mYoloV5NetHeight;
- int mMaxOutObject;
- bool is_segmentation_;
- std::vector mYoloKernel;
- void** mAnchor;
- };
-
- class API YoloPluginCreator : public IPluginCreator
- {
- public:
- YoloPluginCreator();
-
- ~YoloPluginCreator() override = default;
-
- const char* getPluginName() const TRT_NOEXCEPT override;
-
- const char* getPluginVersion() const TRT_NOEXCEPT override;
-
- const PluginFieldCollection* getFieldNames() TRT_NOEXCEPT override;
-
- IPluginV2IOExt* createPlugin(const char* name, const PluginFieldCollection* fc) TRT_NOEXCEPT override;
-
- IPluginV2IOExt* deserializePlugin(const char* name, const void* serialData, size_t serialLength) TRT_NOEXCEPT override;
-
- void setPluginNamespace(const char* libNamespace) TRT_NOEXCEPT override
- {
- mNamespace = libNamespace;
- }
-
- const char* getPluginNamespace() const TRT_NOEXCEPT override
- {
- return mNamespace.c_str();
- }
-
- private:
- std::string mNamespace;
- static PluginFieldCollection mFC;
- static std::vector mPluginAttributes;
- };
- REGISTER_TENSORRT_PLUGIN(YoloPluginCreator);
+ private:
+ void forwardGpu(const float* const* inputs, float *output, cudaStream_t stream, int batchSize = 1);
+ int mThreadCount = 256;
+ const char* mPluginNamespace;
+ int mKernelCount;
+ int mClassCount;
+ int mYoloV5NetWidth;
+ int mYoloV5NetHeight;
+ int mMaxOutObject;
+ bool is_segmentation_;
+ std::vector mYoloKernel;
+ void** mAnchor;
+};
+
+class API YoloPluginCreator : public IPluginCreator {
+ public:
+ YoloPluginCreator();
+
+ ~YoloPluginCreator() override = default;
+
+ const char* getPluginName() const TRT_NOEXCEPT override;
+
+ const char* getPluginVersion() const TRT_NOEXCEPT override;
+
+ const PluginFieldCollection* getFieldNames() TRT_NOEXCEPT override;
+
+ IPluginV2IOExt* createPlugin(const char* name, const PluginFieldCollection* fc) TRT_NOEXCEPT override;
+
+ IPluginV2IOExt* deserializePlugin(const char* name, const void* serialData, size_t serialLength) TRT_NOEXCEPT override;
+
+ void setPluginNamespace(const char* libNamespace) TRT_NOEXCEPT override {
+ mNamespace = libNamespace;
+ }
+
+ const char* getPluginNamespace() const TRT_NOEXCEPT override {
+ return mNamespace.c_str();
+ }
+
+ private:
+ std::string mNamespace;
+ static PluginFieldCollection mFC;
+ static std::vector mPluginAttributes;
+};
+REGISTER_TENSORRT_PLUGIN(YoloPluginCreator);
};
-#endif // _YOLO_LAYER_H
diff --git a/yolov5/samples b/yolov5/samples
deleted file mode 120000
index 3a29e7c..0000000
--- a/yolov5/samples
+++ /dev/null
@@ -1 +0,0 @@
-../yolov3-spp/samples/
\ No newline at end of file
diff --git a/yolov5/src/calibrator.cpp b/yolov5/src/calibrator.cpp
index 472582f..ed7ce19 100644
--- a/yolov5/src/calibrator.cpp
+++ b/yolov5/src/calibrator.cpp
@@ -1,11 +1,35 @@
-#include
-#include
-#include
-#include
#include "calibrator.h"
#include "cuda_utils.h"
#include "utils.h"
+#include
+#include
+#include
+#include
+#include
+
+static cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h) {
+ int w, h, x, y;
+ float r_w = input_w / (img.cols * 1.0);
+ float r_h = input_h / (img.rows * 1.0);
+ if (r_h > r_w) {
+ w = input_w;
+ h = r_w * img.rows;
+ x = 0;
+ y = (input_h - h) / 2;
+ } else {
+ w = r_h * img.cols;
+ h = input_h;
+ x = (input_w - w) / 2;
+ y = 0;
+ }
+ cv::Mat re(h, w, CV_8UC3);
+ cv::resize(img, re, re.size(), 0, 0, cv::INTER_LINEAR);
+ cv::Mat out(input_h, input_w, CV_8UC3, cv::Scalar(128, 128, 128));
+ re.copyTo(out(cv::Rect(x, y, re.cols, re.rows)));
+ return out;
+}
+
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)
: batchsize_(batchsize),
input_w_(input_w),
@@ -15,59 +39,59 @@ Int8EntropyCalibrator2::Int8EntropyCalibrator2(int batchsize, int input_w, int i
calib_table_name_(calib_table_name),
input_blob_name_(input_blob_name),
read_cache_(read_cache) {
- input_count_ = 3 * input_w * input_h * batchsize;
- CUDA_CHECK(cudaMalloc(&device_input_, input_count_ * sizeof(float)));
- read_files_in_dir(img_dir, img_files_);
+ input_count_ = 3 * input_w * input_h * batchsize;
+ CUDA_CHECK(cudaMalloc(&device_input_, input_count_ * sizeof(float)));
+ read_files_in_dir(img_dir, img_files_);
}
Int8EntropyCalibrator2::~Int8EntropyCalibrator2() {
- CUDA_CHECK(cudaFree(device_input_));
+ CUDA_CHECK(cudaFree(device_input_));
}
int Int8EntropyCalibrator2::getBatchSize() const TRT_NOEXCEPT {
- return batchsize_;
+ return batchsize_;
}
bool Int8EntropyCalibrator2::getBatch(void* bindings[], const char* names[], int nbBindings) TRT_NOEXCEPT {
- if (img_idx_ + batchsize_ > (int)img_files_.size()) {
- return false;
- }
+ if (img_idx_ + batchsize_ > (int)img_files_.size()) {
+ return false;
+ }
- std::vector input_imgs_;
- for (int i = img_idx_; i < img_idx_ + batchsize_; i++) {
- std::cout << img_files_[i] << " " << i << std::endl;
- cv::Mat temp = cv::imread(img_dir_ + img_files_[i]);
- if (temp.empty()) {
- std::cerr << "Fatal error: image cannot open!" << std::endl;
- return false;
- }
- cv::Mat pr_img = preprocess_img(temp, input_w_, input_h_);
- input_imgs_.push_back(pr_img);
+ std::vector input_imgs_;
+ for (int i = img_idx_; i < img_idx_ + batchsize_; i++) {
+ std::cout << img_files_[i] << " " << i << std::endl;
+ cv::Mat temp = cv::imread(img_dir_ + img_files_[i]);
+ if (temp.empty()) {
+ std::cerr << "Fatal error: image cannot open!" << std::endl;
+ return false;
}
- img_idx_ += batchsize_;
- cv::Mat blob = cv::dnn::blobFromImages(input_imgs_, 1.0 / 255.0, cv::Size(input_w_, input_h_), cv::Scalar(0, 0, 0), true, false);
+ cv::Mat pr_img = preprocess_img(temp, input_w_, input_h_);
+ input_imgs_.push_back(pr_img);
+ }
+ img_idx_ += batchsize_;
+ cv::Mat blob = cv::dnn::blobFromImages(input_imgs_, 1.0 / 255.0, cv::Size(input_w_, input_h_), cv::Scalar(0, 0, 0), true, false);
- CUDA_CHECK(cudaMemcpy(device_input_, blob.ptr(0), input_count_ * sizeof(float), cudaMemcpyHostToDevice));
- assert(!strcmp(names[0], input_blob_name_));
- bindings[0] = device_input_;
- return true;
+ CUDA_CHECK(cudaMemcpy(device_input_, blob.ptr(0), input_count_ * sizeof(float), cudaMemcpyHostToDevice));
+ assert(!strcmp(names[0], input_blob_name_));
+ bindings[0] = device_input_;
+ return true;
}
const void* Int8EntropyCalibrator2::readCalibrationCache(size_t& length) TRT_NOEXCEPT {
- std::cout << "reading calib cache: " << calib_table_name_ << std::endl;
- calib_cache_.clear();
- std::ifstream input(calib_table_name_, std::ios::binary);
- input >> std::noskipws;
- if (read_cache_ && input.good()) {
- std::copy(std::istream_iterator(input), std::istream_iterator(), std::back_inserter(calib_cache_));
- }
- length = calib_cache_.size();
- return length ? calib_cache_.data() : nullptr;
+ std::cout << "reading calib cache: " << calib_table_name_ << std::endl;
+ calib_cache_.clear();
+ std::ifstream input(calib_table_name_, std::ios::binary);
+ input >> std::noskipws;
+ if (read_cache_ && input.good()) {
+ std::copy(std::istream_iterator(input), std::istream_iterator(), std::back_inserter(calib_cache_));
+ }
+ length = calib_cache_.size();
+ return length ? calib_cache_.data() : nullptr;
}
void Int8EntropyCalibrator2::writeCalibrationCache(const void* cache, size_t length) TRT_NOEXCEPT {
- std::cout << "writing calib cache: " << calib_table_name_ << " size: " << length << std::endl;
- std::ofstream output(calib_table_name_, std::ios::binary);
- output.write(reinterpret_cast(cache), length);
+ std::cout << "writing calib cache: " << calib_table_name_ << " size: " << length << std::endl;
+ std::ofstream output(calib_table_name_, std::ios::binary);
+ output.write(reinterpret_cast(cache), length);
}
diff --git a/yolov5/src/calibrator.h b/yolov5/src/calibrator.h
index afba664..ed77b5f 100644
--- a/yolov5/src/calibrator.h
+++ b/yolov5/src/calibrator.h
@@ -1,10 +1,8 @@
-#ifndef ENTROPY_CALIBRATOR_H
-#define ENTROPY_CALIBRATOR_H
+#pragma once
-#include
+#include "macros.h"
#include
#include
-#include "macros.h"
//! \class Int8EntropyCalibrator2
//!
@@ -12,28 +10,27 @@
//! CalibrationAlgoType is kENTROPY_CALIBRATION_2.
//!
class Int8EntropyCalibrator2 : public nvinfer1::IInt8EntropyCalibrator2 {
-public:
- 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 = true);
+ public:
+ 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 = true);
- virtual ~Int8EntropyCalibrator2();
- int getBatchSize() const TRT_NOEXCEPT override;
- bool getBatch(void* bindings[], const char* names[], int nbBindings) TRT_NOEXCEPT override;
- const void* readCalibrationCache(size_t& length) TRT_NOEXCEPT override;
- void writeCalibrationCache(const void* cache, size_t length) TRT_NOEXCEPT override;
+ virtual ~Int8EntropyCalibrator2();
+ int getBatchSize() const TRT_NOEXCEPT override;
+ bool getBatch(void* bindings[], const char* names[], int nbBindings) TRT_NOEXCEPT override;
+ const void* readCalibrationCache(size_t& length) TRT_NOEXCEPT override;
+ void writeCalibrationCache(const void* cache, size_t length) TRT_NOEXCEPT override;
-private:
- int batchsize_;
- int input_w_;
- int input_h_;
- int img_idx_;
- std::string img_dir_;
- std::vector img_files_;
- size_t input_count_;
- std::string calib_table_name_;
- const char* input_blob_name_;
- bool read_cache_;
- void* device_input_;
- std::vector calib_cache_;
+ private:
+ int batchsize_;
+ int input_w_;
+ int input_h_;
+ int img_idx_;
+ std::string img_dir_;
+ std::vector img_files_;
+ size_t input_count_;
+ std::string calib_table_name_;
+ const char* input_blob_name_;
+ bool read_cache_;
+ void* device_input_;
+ std::vector calib_cache_;
};
-#endif // ENTROPY_CALIBRATOR_H
diff --git a/yolov5/src/common.hpp b/yolov5/src/common.hpp
deleted file mode 100644
index e7458de..0000000
--- a/yolov5/src/common.hpp
+++ /dev/null
@@ -1,344 +0,0 @@
-#ifndef YOLOV5_COMMON_H_
-#define YOLOV5_COMMON_H_
-
-#include
-#include