Merge with master, all tests passed
Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
This commit is contained in:
+105
-41
@@ -140,6 +140,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
engineRT = builderRT->buildEngineWithConfig(*networkRT, *configRT);
|
||||
#else
|
||||
engineRT = builderRT->buildCudaEngine(*networkRT);
|
||||
//engineRT = std::shared_ptr<nvinfer1::ICudaEngine>(builderRT->buildCudaEngine(*networkRT));
|
||||
#endif
|
||||
if(engineRT == nullptr)
|
||||
FatalError("cloud not build cuda engine")
|
||||
@@ -163,7 +164,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
// note that indices are guaranteed to be less than IEngine::getNbBindings()
|
||||
buf_input_idx = engineRT->getBindingIndex("data");
|
||||
buf_output_idx = engineRT->getBindingIndex("out");
|
||||
std::cout<<"input idex = "<<buf_input_idx<<" -> output index = "<<buf_output_idx<<"\n";
|
||||
std::cout<<"input index = "<<buf_input_idx<<" -> output index = "<<buf_output_idx<<"\n";
|
||||
|
||||
|
||||
Dims iDim = engineRT->getBindingDimensions(buf_input_idx);
|
||||
@@ -226,7 +227,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Layer *l) {
|
||||
return convert_layer(input, (Conv2d*) l);
|
||||
if(type == LAYER_POOLING)
|
||||
return convert_layer(input, (Pooling*) l);
|
||||
if(type == LAYER_ACTIVATION || type == LAYER_ACTIVATION_CRELU || type == LAYER_ACTIVATION_LEAKY || type == LAYER_ACTIVATION_MISH)
|
||||
if(type == LAYER_ACTIVATION || type == LAYER_ACTIVATION_CRELU || type == LAYER_ACTIVATION_LEAKY || type == LAYER_ACTIVATION_MISH || type == LAYER_ACTIVATION_LOGISTIC)
|
||||
return convert_layer(input, (Activation*) l);
|
||||
if(type == LAYER_SOFTMAX)
|
||||
return convert_layer(input, (Softmax*) l);
|
||||
@@ -423,6 +424,12 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Activation *l) {
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
else if(l->act_mode == ACTIVATION_LOGISTIC) {
|
||||
IPlugin *plugin = new ActivationLogisticRT();
|
||||
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
else {
|
||||
FatalError("this Activation mode is not yet implemented");
|
||||
return NULL;
|
||||
@@ -451,12 +458,15 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Route *l) {
|
||||
// }
|
||||
// std::cout<<"\n";
|
||||
}
|
||||
|
||||
IConcatenationLayer *lRT = networkRT->addConcatenation(tens, l->layers_n);
|
||||
//IPlugin *plugin = new RouteRT();
|
||||
//IPluginLayer *lRT = networkRT->addPlugin(tens, l->layers_n, *plugin);
|
||||
checkNULL(lRT);
|
||||
|
||||
if(l->groups > 1){
|
||||
IPlugin *plugin = new RouteRT(l->groups, l->group_id);
|
||||
IPluginLayer *lRT = networkRT->addPlugin(tens, l->layers_n, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
IConcatenationLayer *lRT = networkRT->addConcatenation(tens, l->layers_n);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
|
||||
@@ -538,7 +548,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Yolo *l) {
|
||||
//std::cout<<"convert Yolo\n";
|
||||
|
||||
//std::cout<<"New plugin YOLO\n";
|
||||
IPlugin *plugin = new YoloRT(l->classes, l->num, l, l->n_masks, l->scaleXY);
|
||||
IPlugin *plugin = new YoloRT(l->classes, l->num, l, l->n_masks, l->scaleXY, l->nms_thresh, l->nsm_kind, l->new_coords);
|
||||
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
@@ -570,7 +580,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) {
|
||||
IPluginLayer *lRT = networkRT->addPlugin(inputs, 2, *plugin);
|
||||
checkNULL(lRT);
|
||||
lRT->setName( ("Deformable" + std::to_string(l->id)).c_str() );
|
||||
delete(inputs);
|
||||
delete[](inputs);
|
||||
// batchnorm
|
||||
void *bias_b, *power_b, *mean_b, *variance_b, *scales_b;
|
||||
if(dtRT == DataType::kHALF) {
|
||||
@@ -647,7 +657,7 @@ bool NetworkRT::deserialize(const char *filename) {
|
||||
|
||||
|
||||
IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialData, size_t serialLength) {
|
||||
const char * buf = reinterpret_cast<const char*>(serialData);
|
||||
const char * buf = reinterpret_cast<const char*>(serialData),*bufCheck = buf;
|
||||
|
||||
std::string name(layerName);
|
||||
//std::cout<<name<<std::endl;
|
||||
@@ -655,35 +665,53 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
if(name.find("ActivationLeaky") == 0) {
|
||||
ActivationLeakyRT *a = new ActivationLeakyRT(readBUF<float>(buf));
|
||||
a->size = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return a;
|
||||
}
|
||||
if(name.find("ActivationMish") == 0) {
|
||||
ActivationMishRT *a = new ActivationMishRT();
|
||||
a->size = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return a;
|
||||
}
|
||||
if(name.find("ActivationLogistic") == 0) {
|
||||
ActivationLogisticRT *a = new ActivationLogisticRT();
|
||||
a->size = readBUF<int>(buf);
|
||||
return a;
|
||||
}
|
||||
if(name.find("ActivationLogistic") == 0) {
|
||||
ActivationLogisticRT *a = new ActivationLogisticRT();
|
||||
a->size = readBUF<int>(buf);
|
||||
return a;
|
||||
}
|
||||
if(name.find("ActivationCReLU") == 0) {
|
||||
ActivationReLUCeiling *a = new ActivationReLUCeiling(readBUF<float>(buf));
|
||||
float activationReluTemp = readBUF<float>(buf);
|
||||
ActivationReLUCeiling* a = new ActivationReLUCeiling(activationReluTemp);
|
||||
a->size = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return a;
|
||||
}
|
||||
|
||||
if(name.find("Region") == 0) {
|
||||
RegionRT *r = new RegionRT(readBUF<int>(buf), //classes
|
||||
readBUF<int>(buf), //coords
|
||||
readBUF<int>(buf)); //num
|
||||
int classesTemp = readBUF<int>(buf);
|
||||
int coordsTemp = readBUF<int>(buf);
|
||||
int numTemp = readBUF<int>(buf);
|
||||
RegionRT* r = new RegionRT(classesTemp, coordsTemp, numTemp);
|
||||
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
|
||||
if(name.find("Reorg") == 0) {
|
||||
ReorgRT *r = new ReorgRT(readBUF<int>(buf)); //stride
|
||||
int strideTemp = readBUF<int>(buf);
|
||||
ReorgRT *r = new ReorgRT(strideTemp);
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -699,27 +727,34 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
return r;
|
||||
assert(buf == bufCheck + serialLength);
|
||||
}
|
||||
|
||||
if(name.find("Pooling") == 0) {
|
||||
MaxPoolFixedSizeRT *r = new MaxPoolFixedSizeRT( readBUF<int>(buf), //c
|
||||
readBUF<int>(buf), //h
|
||||
readBUF<int>(buf), //w
|
||||
readBUF<int>(buf), //n
|
||||
readBUF<int>(buf), //strideH
|
||||
readBUF<int>(buf), //strideW
|
||||
readBUF<int>(buf), //winSize
|
||||
readBUF<int>(buf)); //padding
|
||||
int cTemp = readBUF<int>(buf);
|
||||
int hTemp = readBUF<int>(buf);
|
||||
int wTemp = readBUF<int>(buf);
|
||||
int nTemp = readBUF<int>(buf);
|
||||
int strideHTemp = readBUF<int>(buf);
|
||||
int strideWTemp = readBUF<int>(buf);
|
||||
int winSizeTemp = readBUF<int>(buf);
|
||||
int paddingTemp = readBUF<int>(buf);
|
||||
|
||||
MaxPoolFixedSizeRT* r = new MaxPoolFixedSizeRT(cTemp, hTemp, wTemp, nTemp, strideHTemp, strideWTemp, winSizeTemp, paddingTemp);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
|
||||
if(name.find("Resize") == 0) {
|
||||
ResizeLayerRT *r = new ResizeLayerRT(readBUF<int>(buf), //o_c
|
||||
readBUF<int>(buf), //o_h
|
||||
readBUF<int>(buf)); //o_w
|
||||
int o_cTemp = readBUF<int>(buf);
|
||||
int o_hTemp = readBUF<int>(buf);
|
||||
int o_wTemp = readBUF<int>(buf);
|
||||
ResizeLayerRT* r = new ResizeLayerRT(o_cTemp, o_hTemp, o_wTemp);
|
||||
|
||||
r->i_c = readBUF<int>(buf);
|
||||
r->i_h = readBUF<int>(buf);
|
||||
r->i_w = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -730,6 +765,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
r->w = readBUF<int>(buf);
|
||||
r->rows = readBUF<int>(buf);
|
||||
r->cols = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -741,19 +777,28 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
new_dim.h = readBUF<int>(buf);
|
||||
new_dim.w = readBUF<int>(buf);
|
||||
ReshapeRT *r = new ReshapeRT(new_dim);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
if(name.find("Yolo") == 0) {
|
||||
YoloRT *r = new YoloRT(readBUF<int>(buf), //classes
|
||||
readBUF<int>(buf), //num
|
||||
nullptr,
|
||||
readBUF<int>(buf)); //n_masks
|
||||
|
||||
int classes_temp = readBUF<int>(buf);
|
||||
int num_temp = readBUF<int>(buf);
|
||||
int n_masks_temp = readBUF<int>(buf);
|
||||
float scale_xy_temp = readBUF<float>(buf);
|
||||
float nms_thresh_temp = readBUF<float>(buf);
|
||||
int nms_kind_temp = readBUF<int>(buf);
|
||||
int new_coords_temp = readBUF<int>(buf);
|
||||
|
||||
YoloRT *r = new YoloRT(classes_temp,num_temp,nullptr,n_masks_temp,scale_xy_temp,nms_thresh_temp,nms_kind_temp,new_coords_temp);
|
||||
|
||||
|
||||
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
r->scaleXY = readBUF<float>(buf);
|
||||
for(int i=0; i<r->n_masks; i++)
|
||||
r->mask[i] = readBUF<dnnType>(buf);
|
||||
for(int i=0; i<r->n_masks*2*r->num; i++)
|
||||
@@ -767,36 +812,54 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
tmp[j] = readBUF<char>(buf);
|
||||
r->classesNames[i] = std::string(tmp);
|
||||
}
|
||||
assert(buf == bufCheck + serialLength);
|
||||
|
||||
yolos[n_yolos++] = r;
|
||||
return r;
|
||||
}
|
||||
if(name.find("Upsample") == 0) {
|
||||
UpsampleRT *r = new UpsampleRT(readBUF<int>(buf)); //stride
|
||||
int strideTemp = readBUF<int>(buf);
|
||||
UpsampleRT* r = new UpsampleRT(strideTemp);
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
/*
|
||||
|
||||
if(name.find("Route") == 0) {
|
||||
RouteRT *r = new RouteRT();
|
||||
int groupsTemp = readBUF<int>(buf);
|
||||
int group_idTemp = readBUF<int>(buf);
|
||||
RouteRT* r = new RouteRT(groupsTemp, group_idTemp);
|
||||
r->in = readBUF<int>(buf);
|
||||
for(int i=0; i<RouteRT::MAX_INPUTS; i++)
|
||||
r->c_in[i] = readBUF<int>(buf);
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
*/
|
||||
|
||||
if(name.find("Deformable") == 0) {
|
||||
DeformableConvRT *r = new DeformableConvRT(readBUF<int>(buf), readBUF<int>(buf), readBUF<int>(buf),
|
||||
readBUF<int>(buf), readBUF<int>(buf), readBUF<int>(buf),
|
||||
readBUF<int>(buf), readBUF<int>(buf),
|
||||
readBUF<int>(buf),readBUF<int>(buf),readBUF<int>(buf),readBUF<int>(buf),
|
||||
readBUF<int>(buf),readBUF<int>(buf),readBUF<int>(buf),readBUF<int>(buf),
|
||||
nullptr);
|
||||
int chuck_dimTemp = readBUF<int>(buf);
|
||||
int khTemp = readBUF<int>(buf);
|
||||
int kwTemp = readBUF<int>(buf);
|
||||
int shTemp = readBUF<int>(buf);
|
||||
int swTemp = readBUF<int>(buf);
|
||||
int phTemp = readBUF<int>(buf);
|
||||
int pwTemp = readBUF<int>(buf);
|
||||
int deformableGroupTemp = readBUF<int>(buf);
|
||||
int i_nTemp = readBUF<int>(buf);
|
||||
int i_cTemp = readBUF<int>(buf);
|
||||
int i_hTemp = readBUF<int>(buf);
|
||||
int i_wTemp = readBUF<int>(buf);
|
||||
int o_nTemp = readBUF<int>(buf);
|
||||
int o_cTemp = readBUF<int>(buf);
|
||||
int o_hTemp = readBUF<int>(buf);
|
||||
int o_wTemp = readBUF<int>(buf);
|
||||
|
||||
DeformableConvRT* r = new DeformableConvRT(chuck_dimTemp, khTemp, kwTemp, shTemp, swTemp, phTemp, pwTemp, deformableGroupTemp, i_nTemp, i_cTemp, i_hTemp, i_wTemp, o_nTemp, o_cTemp, o_hTemp, o_wTemp, nullptr);
|
||||
dnnType *aus = new dnnType[r->chunk_dim*2];
|
||||
for(int i=0; i<r->chunk_dim*2; i++)
|
||||
aus[i] = readBUF<dnnType>(buf);
|
||||
@@ -827,6 +890,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
aus[i] = readBUF<dnnType>(buf);
|
||||
checkCuda( cudaMemcpy(r->ones_d2, aus, sizeof(dnnType)*r->dim_ones, cudaMemcpyHostToDevice) );
|
||||
free(aus);
|
||||
assert(buf == bufCheck + serialLength);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user