bug fixes for dla networks and ported optimization from different pull request
This commit is contained in:
+20
-21
@@ -148,8 +148,10 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
// we don't need the network any more
|
||||
//networkRT->destroy();
|
||||
std::cout<<"serialize net\n";
|
||||
builderActive = true;
|
||||
serialize(name);
|
||||
} else {
|
||||
builderActive = false;
|
||||
deserialize(name);
|
||||
}
|
||||
|
||||
@@ -386,6 +388,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Pooling *l) {
|
||||
auto *lRT = networkRT->addPluginV2(&input, 1, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -433,14 +436,15 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Activation *l) {
|
||||
return lRT;
|
||||
}
|
||||
else if(l->act_mode == ACTIVATION_MISH) {
|
||||
IPluginV2 *plugin = new ActivationMishRT();
|
||||
IPluginV2Layer *lRT = networkRT->addPluginV2(&input, 1, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
IActivationLayer *lRT1 = networkRT->addActivation(*input, ActivationType::kSOFTPLUS);
|
||||
lRT1->setAlpha(1);
|
||||
lRT1->setBeta(1);
|
||||
IActivationLayer *lRT2 = networkRT->addActivation(*lRT1->getOutput(0), ActivationType::kTANH);
|
||||
IElementWiseLayer *lRT3 = networkRT->addElementWise(*input, *lRT2->getOutput(0), ElementWiseOperation::kPROD);
|
||||
return lRT3;
|
||||
}
|
||||
else if(l->act_mode == ACTIVATION_LOGISTIC) {
|
||||
IPluginV2 *plugin = new ActivationLogisticRT();
|
||||
IPluginV2Layer *lRT = networkRT->addPluginV2(&input, 1, *plugin);
|
||||
IActivationLayer *lRT = networkRT->addActivation(*input,ActivationType::kSIGMOID);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
@@ -484,7 +488,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Route *l) {
|
||||
return lRT;
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Flatten *l) {
|
||||
IPluginV2Layer* NetworkRT::convert_layer(ITensor *input, Flatten *l) {
|
||||
auto creator = getPluginRegistry()->getPluginCreator("FlattenConcatRT_tkDNN","1");
|
||||
std::vector<PluginField> mPluginAttributes;
|
||||
PluginFieldCollection mFC{};
|
||||
@@ -495,14 +499,13 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Flatten *l) {
|
||||
mPluginAttributes.emplace_back(PluginField("cols",&l->cols,PluginFieldType::kINT32,1));
|
||||
mFC.nbFields = mPluginAttributes.size();
|
||||
mFC.fields = mPluginAttributes.data();
|
||||
|
||||
auto *plugin = creator->createPlugin(l->getLayerName().c_str(),&mFC);
|
||||
auto *lRT = networkRT->addPluginV2(&input, 1, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Reshape *l) {
|
||||
IPluginV2Layer* NetworkRT::convert_layer(ITensor *input, Reshape *l) {
|
||||
// std::cout<<"convert Reshape\n";
|
||||
auto creator = getPluginRegistry()->getPluginCreator("ReshapeRT_tkDNN","1");
|
||||
std::vector<PluginField> mPluginAttributes;
|
||||
@@ -530,7 +533,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Resize *l) {
|
||||
return lRT;
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Reorg *l) {
|
||||
IPluginV2Layer* NetworkRT::convert_layer(ITensor *input, Reorg *l) {
|
||||
//std::cout<<"convert Reorg\n";
|
||||
|
||||
//std::cout<<"New plugin REORG\n";
|
||||
@@ -549,7 +552,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Reorg *l) {
|
||||
return lRT;
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Region *l) {
|
||||
IPluginV2Layer* NetworkRT::convert_layer(ITensor *input, Region *l) {
|
||||
//std::cout<<"convert Region\n";
|
||||
|
||||
//std::cout<<"New plugin REGION\n";
|
||||
@@ -608,10 +611,8 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Shortcut *l) {
|
||||
}
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Yolo *l) {
|
||||
IPluginV2Layer* NetworkRT::convert_layer(ITensor *input, Yolo *l) {
|
||||
|
||||
std::vector<dnnType> mask_h(l->mask_h,l->mask_h+sizeof(dnnType)*l->n_masks);
|
||||
std::vector<dnnType> bias_h(l->bias_h,l->bias_h+sizeof(dnnType)*2*l->n_masks*l->num);
|
||||
auto creator = getPluginRegistry()->getPluginCreator("YoloRT_tkDNN","1");
|
||||
std::vector<PluginField> mPluginAttributes;
|
||||
PluginFieldCollection mFC{};
|
||||
@@ -620,9 +621,6 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Yolo *l) {
|
||||
mPluginAttributes.emplace_back(PluginField("c",&l->input_dim.c,PluginFieldType::kINT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("h",&l->input_dim.h,PluginFieldType::kINT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("w",&l->input_dim.w,PluginFieldType::kINT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("classNames",&l->classesNames[0],PluginFieldType::kUNKNOWN,l->classesNames.size()));
|
||||
mPluginAttributes.emplace_back(PluginField("mask_v",&mask_h[0],PluginFieldType::kFLOAT32,mask_h.size()));
|
||||
mPluginAttributes.emplace_back(PluginField("bias_v",&bias_h[0],PluginFieldType::kFLOAT32,bias_h.size()));
|
||||
mPluginAttributes.emplace_back(PluginField("n_masks",&l->n_masks,PluginFieldType::kINT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("scale_xy",&l->scaleXY,PluginFieldType::kFLOAT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("nms_thresh",&l->nms_thresh,PluginFieldType::kFLOAT32,1));
|
||||
@@ -636,9 +634,8 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Yolo *l) {
|
||||
return lRT;
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Upsample *l) {
|
||||
IPluginV2Layer* NetworkRT::convert_layer(ITensor *input, Upsample *l) {
|
||||
//std::cout<<"convert Upsample\n";
|
||||
|
||||
auto creator = getPluginRegistry()->getPluginCreator("UpSample_tkDNN","1");
|
||||
std::vector<PluginField> mPluginAttributes;
|
||||
PluginFieldCollection mFC{};
|
||||
@@ -789,8 +786,10 @@ bool NetworkRT::deserialize(const char *filename) {
|
||||
|
||||
void NetworkRT::destroy() {
|
||||
contextRT->destroy();
|
||||
engineRT->destroy();
|
||||
builderRT->destroy();
|
||||
if(builderActive) {
|
||||
engineRT->destroy();
|
||||
builderRT->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -9,8 +9,7 @@ PluginFieldCollection YoloRTPluginCreator::mFC{};
|
||||
static const char* YOLORT_PLUGIN_VERSION{"1"};
|
||||
static const char* YOLORT_PLUGIN_NAME{"YoloRT_tkDNN"};
|
||||
|
||||
YoloRT::YoloRT(int classes, int num, int c,int h,int w,std::vector<std::string> classNames,
|
||||
std::vector<float> masks_v,std::vector<float> bias_v,int n_masks, float scale_xy,
|
||||
YoloRT::YoloRT(int classes, int num, int c,int h,int w,int n_masks, float scale_xy,
|
||||
float nms_thresh, int nms_kind,
|
||||
int new_coords) {
|
||||
this->c = c;
|
||||
@@ -23,14 +22,9 @@ YoloRT::YoloRT(int classes, int num, int c,int h,int w,std::vector<std::string>
|
||||
this->nms_thresh = nms_thresh;
|
||||
this->nms_kind = nms_kind;
|
||||
this->new_coords = new_coords;
|
||||
this->classesNames = std::move(classNames);
|
||||
this->mask = std::move(masks_v);
|
||||
this->bias = std::move(bias_v);
|
||||
|
||||
}
|
||||
|
||||
YoloRT::YoloRT(const void *data, size_t length) {
|
||||
std::vector<float> maskTemp,biasTemp;
|
||||
const char* buf = reinterpret_cast<const char*>(data),*bufCheck = buf;
|
||||
classes = readBUF<int>(buf);
|
||||
num = readBUF<int>(buf);
|
||||
@@ -42,21 +36,6 @@ YoloRT::YoloRT(const void *data, size_t length) {
|
||||
c = readBUF<int>(buf);
|
||||
h = readBUF<int>(buf);
|
||||
w = readBUF<int>(buf);
|
||||
mask.resize(n_masks);
|
||||
for(int i=0;i<n_masks;i++){
|
||||
mask[i] = readBUF<dnnType>(buf);
|
||||
}
|
||||
bias.resize(n_masks*2*num);
|
||||
for(int i=0;i<n_masks*2*num;i++){
|
||||
bias[i] = readBUF<dnnType>(buf);
|
||||
}
|
||||
classesNames.resize(classes);
|
||||
for(int i=0;i<classes;i++){
|
||||
char tmp[YOLORT_CLASSNAME_W];
|
||||
for(int j=0;j<YOLORT_CLASSNAME_W;j++)
|
||||
tmp[j] = readBUF<char>(buf);
|
||||
classesNames[1] = std::string(tmp);
|
||||
}
|
||||
assert(buf == bufCheck + length);
|
||||
}
|
||||
|
||||
@@ -147,8 +126,7 @@ int32_t YoloRT::enqueue(int32_t batchSize, const void *const *inputs, void **out
|
||||
|
||||
|
||||
size_t YoloRT::getSerializationSize() const NOEXCEPT {
|
||||
return 8 * sizeof(int) + 2 * sizeof(float) + n_masks * sizeof(dnnType) + num * n_masks * 2 * sizeof(dnnType) +
|
||||
YOLORT_CLASSNAME_W * classes * sizeof(char);
|
||||
return 8 * sizeof(int) + 2 * sizeof(float) ;
|
||||
}
|
||||
|
||||
bool YoloRT::supportsFormat(DataType type, PluginFormat format) const NOEXCEPT {
|
||||
@@ -167,21 +145,7 @@ void YoloRT::serialize(void *buffer) const NOEXCEPT {
|
||||
writeBUF(buf, c); //std::cout << "C : " << c << std::endl;
|
||||
writeBUF(buf, h); //std::cout << "H : " << h << std::endl;
|
||||
writeBUF(buf, w); //std::cout << "C : " << c << std::endl;
|
||||
for (int i = 0; i < n_masks; i++) {
|
||||
writeBUF(buf, mask[i]); //std::cout << "mask[i] : " << mask[i] << std::endl;
|
||||
}
|
||||
for (int i = 0; i < n_masks * 2 * num; i++) {
|
||||
writeBUF(buf, bias[i]); //std::cout << "bias[i] : " << bias[i] << std::endl;
|
||||
}
|
||||
|
||||
// save classes names
|
||||
for (int i = 0; i < classes; i++) {
|
||||
char tmp[YOLORT_CLASSNAME_W];
|
||||
strcpy(tmp, classesNames[i].c_str());
|
||||
for (int j = 0; j < YOLORT_CLASSNAME_W; j++) {
|
||||
writeBUF(buf, tmp[j]);
|
||||
}
|
||||
}
|
||||
assert(buf == a + getSerializationSize());
|
||||
}
|
||||
|
||||
@@ -206,7 +170,7 @@ void YoloRT::setPluginNamespace(const char *pluginNamespace) NOEXCEPT {
|
||||
}
|
||||
|
||||
IPluginV2Ext *YoloRT::clone() const NOEXCEPT {
|
||||
auto *p = new YoloRT(classes, num,c,h,w,classesNames,mask,bias, n_masks, scaleXY, nms_thresh, nms_kind, new_coords);
|
||||
auto *p = new YoloRT(classes, num,c,h,w,n_masks, scaleXY, nms_thresh, nms_kind, new_coords);
|
||||
p->setPluginNamespace(mPluginNamespace.c_str());
|
||||
return p;
|
||||
}
|
||||
@@ -265,15 +229,12 @@ IPluginV2Ext *YoloRTPluginCreator::createPlugin(const char *name, const PluginFi
|
||||
int c = *(static_cast<const int *>(fields[2].data));
|
||||
int h = *(static_cast<const int *>(fields[3].data));
|
||||
int w = *(static_cast<const int *>(fields[4].data));
|
||||
std::vector<std::string> classNames(static_cast<const std::string *>(fields[5].data),static_cast<const std::string *>(fields[5].data) + fields[5].length);
|
||||
std::vector<dnnType> mask_v(static_cast<const dnnType*>(fields[6].data),static_cast<const dnnType*>(fields[6].data) + fields[6].length);
|
||||
std::vector<dnnType> bias_v(static_cast<const dnnType*>(fields[7].data),static_cast<const dnnType*>(fields[7].data) + fields[7].length);
|
||||
int n_masks = *(static_cast<const int *>(fields[8].data));
|
||||
dnnType scaleXY = *(static_cast<const float*>(fields[9].data));
|
||||
dnnType nmsThresh = *(static_cast<const float*>(fields[10].data));
|
||||
int nms_kind = *(static_cast<const int*>(fields[11].data));
|
||||
int new_coords = *(static_cast<const int*>(fields[12].data));
|
||||
auto *pluginObj = new YoloRT(classes,num,c,h,w,classNames,mask_v,bias_v,n_masks,scaleXY,nmsThresh,nms_kind,new_coords);
|
||||
int n_masks = *(static_cast<const int *>(fields[5].data));
|
||||
dnnType scaleXY = *(static_cast<const float*>(fields[6].data));
|
||||
dnnType nmsThresh = *(static_cast<const float*>(fields[7].data));
|
||||
int nms_kind = *(static_cast<const int*>(fields[8].data));
|
||||
int new_coords = *(static_cast<const int*>(fields[9].data));
|
||||
auto *pluginObj = new YoloRT(classes,num,c,h,w,n_masks,scaleXY,nmsThresh,nms_kind,new_coords);
|
||||
return pluginObj;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user