forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_factory.cpp
More file actions
171 lines (138 loc) · 4.33 KB
/
plugin_factory.cpp
File metadata and controls
171 lines (138 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "plugin_factory.h"
#include "trt_utils.h"
/******* Yolo Layer V3 *******/
/*****************************/
namespace nvinfer1
{
YoloLayer::YoloLayer()
{}
YoloLayer::YoloLayer(const void* data, size_t length)
{
const char *d = static_cast<const char*>(data), *a = d;
re(d, m_NumBoxes);
re(d, m_NumClasses);
re(d, _n_grid_h);
re(d, _n_grid_w);
re(d, m_OutputSize);
assert(d = a + length);
}
void YoloLayer::serialize(void* buffer)const noexcept
{
char *d = static_cast<char*>(buffer), *a = d;
wr(d, m_NumBoxes);
wr(d, m_NumClasses);
wr(d, _n_grid_h);
wr(d, _n_grid_w);
wr(d, m_OutputSize);
assert(d == a + getSerializationSize());
}
bool YoloLayer::supportsFormat(DataType type, PluginFormat format) const noexcept
{
return (type == DataType::kFLOAT && format == PluginFormat::kLINEAR);
}
void YoloLayer::configureWithFormat(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, DataType type, PluginFormat format, int maxBatchSize) noexcept
{
}
IPluginV2* YoloLayer::clone() const noexcept
{
YoloLayer *p = new YoloLayer(m_NumBoxes,m_NumClasses,_n_grid_h,_n_grid_w);
p->setPluginNamespace(_s_plugin_namespace.c_str());
return p;
}
YoloLayer::YoloLayer(const uint32_t& numBoxes, const uint32_t& numClasses, const uint32_t& grid_h_, const uint32_t &grid_w_) :
m_NumBoxes(numBoxes),
m_NumClasses(numClasses),
_n_grid_h(grid_h_),
_n_grid_w(grid_w_)
{
assert(m_NumBoxes > 0);
assert(m_NumClasses > 0);
assert(_n_grid_h > 0);
assert(_n_grid_w > 0);
m_OutputSize = _n_grid_h * _n_grid_w * (m_NumBoxes * (4 + 1 + m_NumClasses));
}
int YoloLayer::getNbOutputs() const noexcept { return 1; }
nvinfer1::Dims YoloLayer::getOutputDimensions(int index, const nvinfer1::Dims* inputs,
int nbInputDims) noexcept
{
assert(index == 0);
assert(nbInputDims == 1);
return inputs[0];
}
//void YoloLayerV3::configure(const nvinfer1::Dims* inputDims, int nbInputs,
// const nvinfer1::Dims* outputDims, int nbOutputs, int maxBatchSize) noexcept
//{
// assert(nbInputs == 1);
// assert(inputDims != nullptr);
//}
int YoloLayer::initialize() noexcept { return 0; }
void YoloLayer::terminate() noexcept {}
size_t YoloLayer::getWorkspaceSize(int maxBatchSize) const noexcept
{
return 0;
}
int YoloLayer::enqueue(int batchSize,
const void* const* inputs,
void* const* outputs,
void* workspace,
cudaStream_t stream) noexcept
{
NV_CUDA_CHECK(cudaYoloLayerV3(inputs[0], outputs[0], batchSize, _n_grid_h, _n_grid_w, m_NumClasses,
m_NumBoxes, m_OutputSize, stream));
return 0;
}
int YoloLayer::enqueue(int batchSize,
const void* const* inputs,
void** outputs,
void* workspace,
cudaStream_t stream) noexcept
{
return enqueue(batchSize, inputs, (void* const*)outputs, workspace, stream);
}
size_t YoloLayer::getSerializationSize()const noexcept
{
return sizeof(m_NumBoxes) + sizeof(m_NumClasses) + sizeof(_n_grid_w) + sizeof(_n_grid_h) + sizeof(m_OutputSize);
}
PluginFieldCollection YoloLayerPluginCreator::mFC{};
std::vector<PluginField> YoloLayerPluginCreator::mPluginAttributes;
YoloLayerPluginCreator::YoloLayerPluginCreator()
{
mPluginAttributes.clear();
mFC.nbFields = mPluginAttributes.size();
mFC.fields = mPluginAttributes.data();
}
const char* YoloLayerPluginCreator::getPluginName() const noexcept
{
return "YOLO_TRT";
}
const char* YoloLayerPluginCreator::getPluginVersion() const noexcept
{
return "1.0";
}
const PluginFieldCollection* YoloLayerPluginCreator::getFieldNames()noexcept
{
return &mFC;
}
IPluginV2* YoloLayerPluginCreator::createPlugin(const char* name, const PluginFieldCollection* fc)noexcept
{
YoloLayer* obj = new YoloLayer();
obj->setPluginNamespace(mNamespace.c_str());
return obj;
}
IPluginV2* YoloLayerPluginCreator::deserializePlugin(const char* name, const void* serialData, size_t serialLength)noexcept
{
// This object will be deleted when the network is destroyed, which will
// call MishPlugin::destroy()
YoloLayer* obj = new YoloLayer(serialData, serialLength);
obj->setPluginNamespace(mNamespace.c_str());
return obj;
}
void YoloLayerPluginCreator::setPluginNamespace(const char* libNamespace)noexcept
{
mNamespace = libNamespace;
}
const char* YoloLayerPluginCreator::getPluginNamespace() const noexcept
{
return mNamespace.c_str();
}
}