├── README.md ├── Makefile ├── common.cpp ├── common.h ├── upsample_layer.h ├── upsample_layer.cu ├── sampleYOLOV3.cpp └── PluginFactory.h /README.md: -------------------------------------------------------------------------------- 1 | # tensorRTyoloV3 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | OUTNAME_RELEASE = sampleYOLOV3 2 | OUTNAME_DEBUG = sampleYOLOV3_debug 3 | MAKEFILE ?= ../Makefile.config 4 | include $(MAKEFILE) 5 | -------------------------------------------------------------------------------- /common.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | std::string locateFile(const std::string& input, const std::vector & directories) 3 | { 4 | std::string file; 5 | const int MAX_DEPTH{10}; 6 | bool found{false}; 7 | for (auto &dir : directories) 8 | { 9 | file = dir + input; 10 | for (int i = 0; i < MAX_DEPTH && !found; i++) 11 | { 12 | std::ifstream checkFile(file); 13 | found = checkFile.is_open(); 14 | if (found) break; 15 | file = "../" + file; 16 | } 17 | if (found) break; 18 | file.clear(); 19 | } 20 | 21 | assert(!file.empty() && "Could not find a file due to it not existing in the data directory."); 22 | return file; 23 | } 24 | 25 | void readPGMFile(const std::string& fileName, uint8_t *buffer, int inH, int inW) 26 | { 27 | std::ifstream infile(fileName, std::ifstream::binary); 28 | assert(infile.is_open() && "Attempting to read from a file that is not open."); 29 | std::string magic, h, w, max; 30 | infile >> magic >> h >> w >> max; 31 | infile.seekg(1, infile.cur); 32 | infile.read(reinterpret_cast(buffer), inH*inW); 33 | } 34 | -------------------------------------------------------------------------------- /common.h: -------------------------------------------------------------------------------- 1 | #ifndef _TRT_COMMON_H_ 2 | #define _TRT_COMMON_H_ 3 | #include "NvInfer.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define CHECK(status) \ 11 | { \ 12 | if (status != 0) \ 13 | { \ 14 | std::cout << "Cuda failure: " << status; \ 15 | abort(); \ 16 | } \ 17 | } 18 | 19 | 20 | // Logger for GIE info/warning/errors 21 | class Logger : public nvinfer1::ILogger 22 | { 23 | public: 24 | void log(nvinfer1::ILogger::Severity severity, const char* msg) override 25 | { 26 | // suppress info-level messages 27 | if (severity == Severity::kINFO) return; 28 | 29 | switch (severity) 30 | { 31 | case Severity::kINTERNAL_ERROR: std::cerr << "INTERNAL_ERROR: "; break; 32 | case Severity::kERROR: std::cerr << "ERROR: "; break; 33 | case Severity::kWARNING: std::cerr << "WARNING: "; break; 34 | case Severity::kINFO: std::cerr << "INFO: "; break; 35 | default: std::cerr << "UNKNOWN: "; break; 36 | } 37 | std::cerr << msg << std::endl; 38 | } 39 | }; 40 | 41 | std::string locateFile(const std::string& input, const std::vector & directories); 42 | void readPGMFile(const std::string& fileName, uint8_t *buffer, int inH, int inW); 43 | #endif // _TRT_COMMON_H_ 44 | -------------------------------------------------------------------------------- /upsample_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef CAFFE_UPSAMPLE_LAYER_HPP_ 2 | #define CAFFE_UPSAMPLE_LAYER_HPP_ 3 | 4 | #include 5 | 6 | #include "glog/logging.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include // cuda driver types 12 | 13 | 14 | // CUDA: use 512 threads per block 15 | const int CAFFE_CUDA_NUM_THREADS = 512; 16 | 17 | // CUDA: number of blocks for threads. 18 | inline int CAFFE_GET_BLOCKS(const int N) { 19 | return (N + CAFFE_CUDA_NUM_THREADS - 1) / CAFFE_CUDA_NUM_THREADS; 20 | } 21 | 22 | // CUDA: various checks for different function calls. 23 | #define CUDA_CHECK(condition) \ 24 | /* Code block avoids redefinition of cudaError_t error */ \ 25 | do { \ 26 | cudaError_t error = condition; \ 27 | CHECK_EQ(error, cudaSuccess) << " " << cudaGetErrorString(error); \ 28 | } while (0) 29 | 30 | #define CUBLAS_CHECK(condition) \ 31 | do { \ 32 | cublasStatus_t status = condition; \ 33 | CHECK_EQ(status, CUBLAS_STATUS_SUCCESS) << " " \ 34 | << caffe::cublasGetErrorString(status); \ 35 | } while (0) 36 | 37 | #define CURAND_CHECK(condition) \ 38 | do { \ 39 | curandStatus_t status = condition; \ 40 | CHECK_EQ(status, CURAND_STATUS_SUCCESS) << " " \ 41 | << caffe::curandGetErrorString(status); \ 42 | } while (0) 43 | 44 | 45 | 46 | // CUDA: check for error after kernel execution and exit loudly if there is one. 47 | #define CUDA_POST_KERNEL_CHECK CUDA_CHECK(cudaPeekAtLastError()) 48 | 49 | 50 | 51 | #define CUDA_KERNEL_LOOP(i, n) \ 52 | for (int i = blockIdx.x * blockDim.x + threadIdx.x; \ 53 | i < (n); \ 54 | i += blockDim.x * gridDim.x) 55 | 56 | 57 | __global__ void ReLUForward(const int n, const float* in, float* out, 58 | float negative_slope); 59 | void Forward_gpu( 60 | float* input,int b,int c,int w,int h,int stride_, float* output ); 61 | 62 | 63 | void ReluForward_gpu(const float* bottom, 64 | float* top,int b,int c,int w,int h,float negative_slope); 65 | 66 | 67 | #endif // CAFFE_UPSAMPLE_LAYER_HPP_ 68 | -------------------------------------------------------------------------------- /upsample_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include "upsample_layer.h" 3 | #include 4 | 5 | template 6 | __global__ void upsample_kernel(size_t N, const Dtype *x, int w, int h, int c, int batch, int stride, int forward, float scale, Dtype *out) 7 | { 8 | #if 1 9 | // printf("ReLUForwardsss 01 enqueue line=%d",__LINE__); 10 | for (int i = blockIdx.x * blockDim.x + threadIdx.x; \ 11 | i < (N); \ 12 | i += blockDim.x * gridDim.x) 13 | { 14 | 15 | int out_index = i; 16 | int out_w = i%(w*stride); 17 | i = i/(w*stride); 18 | int out_h = i%(h*stride); 19 | i = i/(h*stride); 20 | int out_c = i%c; 21 | i = i/c; 22 | int b = i%batch; 23 | 24 | int in_w = out_w / stride; 25 | int in_h = out_h / stride; 26 | int in_c = out_c; 27 | 28 | int in_index = b*w*h*c + in_c*w*h + in_h*w + in_w; 29 | 30 | // out[out_index] += scale * x[in_index]; 31 | 32 | out[out_index] = scale*x[in_index];//坑死了 33 | 34 | } 35 | 36 | 37 | 38 | 39 | //} 40 | 41 | 42 | 43 | #else 44 | 45 | #endif 46 | /* 47 | size_t i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; 48 | if(i >= N) return; 49 | int out_index = i; 50 | int out_w = i%(w*stride); 51 | i = i/(w*stride); 52 | int out_h = i%(h*stride); 53 | i = i/(h*stride); 54 | int out_c = i%c; 55 | i = i/c; 56 | int b = i%batch; 57 | 58 | int in_w = out_w / stride; 59 | int in_h = out_h / stride; 60 | int in_c = out_c; 61 | 62 | int in_index = b*w*h*c + in_c*w*h + in_h*w + in_w; 63 | 64 | 65 | out[out_index] += scale * x[in_index]; 66 | 67 | */ 68 | // else atomicAdd(x+in_index, scale * out[out_index]); 69 | } 70 | 71 | 72 | 73 | __global__ void ReLUForward(const int n, const float* in, float* out, 74 | float negative_slope) { 75 | CUDA_KERNEL_LOOP(index, n) { 76 | // printf("ReLUForwardsss 01 enqueue line=%d",__LINE__); 77 | out[index] = in[index] > 0 ? in[index] : in[index] * negative_slope; 78 | } 79 | } 80 | 81 | 82 | 83 | 84 | void ReluForward_gpu(const float* bottom, 85 | float* top,int b,int c,int w,int h,float negative_slope) { 86 | const int nthreads =b*c*w*h; 87 | // NOLINT_NEXT_LINE(whitespace/operators) 88 | // printf("ReLUForwardsss 01 enqueue line=%d threads:%d %d %d %d %d \n",__LINE__,nthreads,b,c,w,h); 89 | ReLUForward <<>>( 90 | nthreads, bottom, top, negative_slope); 91 | CUDA_POST_KERNEL_CHECK; 92 | 93 | } 94 | 95 | 96 | 97 | 98 | void Forward_gpu( 99 | float* input,int b,int c,int w,int h,int stride_, float* output ) { 100 | 101 | //const Dtype* bottom_data = bottom[0]->gpu_data(); 102 | //Dtype* top_data = top[0]->mutable_gpu_data(); 103 | //const int count = top[0]->count(); 104 | const int nthreads =b*c*w*h*stride_*stride_; 105 | 106 | //vector buttom_shape = bottom[0]->shape(); 107 | 108 | // printf("ReLUForwardsss 01 enqueue line=%d",__LINE__); 109 | upsample_kernel<<>>( nthreads, input,h, w, c,b,stride_, 1,1, output); 110 | CUDA_POST_KERNEL_CHECK; 111 | 112 | 113 | } 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /sampleYOLOV3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "NvInfer.h" 16 | #include "NvCaffeParser.h" 17 | #include "common.h" 18 | #include "PluginFactory.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | 26 | using namespace nvinfer1; 27 | using namespace nvcaffeparser1; 28 | // stuff we know about the network and the caffe input/output blobs 29 | static const int INPUT_H = 416; 30 | static const int INPUT_W = 416; 31 | static const int INPUT_C = 3; 32 | 33 | static const int TIMING_ITERATIONS = 1000; 34 | struct PPM 35 | { 36 | std::string magic, fileName; 37 | int h, w, max; 38 | uint8_t buffer[INPUT_C*INPUT_H*INPUT_W]; 39 | }; 40 | #if 0 41 | box3 = out['layer105-conv'] 42 | box2 = out['layer93-conv'] 43 | box1 = out['layer81-conv'] 44 | #box1=np.transpose(box1, (0,2,3,1)) 45 | ##box2=np.transpose(box2, (0,2,3,1)) 46 | #box3=np.transpose(box3, (0,2,3,1)) 47 | 48 | print(box1.shape) 49 | print(box2.shape) 50 | print(box3.shape) 51 | 52 | (1, 255, 13, 13) 53 | (1, 255, 26, 26) 54 | (1, 255, 52, 52) 55 | #endif 56 | 57 | 58 | static const int OUTPUT_SIZE0 = 255*13*13; 59 | static const int OUTPUT_SIZE1 = 255*26*26; 60 | static const int OUTPUT_SIZE2 = 255*52*52; 61 | 62 | 63 | static Logger gLogger; 64 | 65 | const char* INPUT_BLOB_NAME = "data"; 66 | 67 | const char* OUTPUT_BLOB_NAME0 = "layer81-conv";//"mbox_loc";//"detection_out"; 68 | const char* OUTPUT_BLOB_NAME1 = "layer93-conv";//"detection_out"; 69 | const char* OUTPUT_BLOB_NAME2 = "layer105-conv";//"detection_out"; 70 | 71 | struct Profiler : public IProfiler 72 | { 73 | typedef std::pair Record; 74 | std::vector mProfile; 75 | 76 | virtual void reportLayerTime(const char* layerName, float ms) 77 | { 78 | auto record = std::find_if(mProfile.begin(), mProfile.end(), [&](const Record& r){ return r.first == layerName; }); 79 | if (record == mProfile.end()) 80 | mProfile.push_back(std::make_pair(layerName, ms)); 81 | else 82 | record->second += ms; 83 | } 84 | 85 | void printLayerTimes() 86 | { 87 | float totalTime = 0; 88 | for (size_t i = 0; i < mProfile.size(); i++) 89 | { 90 | printf("%-40.40s %4.3fms\n", mProfile[i].first.c_str(), mProfile[i].second / TIMING_ITERATIONS); 91 | totalTime += mProfile[i].second; 92 | } 93 | printf("Time over all layers: %4.3f\n", totalTime / TIMING_ITERATIONS); 94 | } 95 | 96 | } gProfiler; 97 | 98 | 99 | std::string locateFile(const std::string& input) 100 | { 101 | std::vector dirs{"data/samples/mnist/", "data/mnist/"}; 102 | return locateFile(input, dirs); 103 | } 104 | 105 | // simple PGM (portable greyscale map) reader 106 | void readPGMFile(const std::string& filename, uint8_t buffer[INPUT_H*INPUT_W]) 107 | { 108 | readPGMFile(locateFile(filename), buffer, INPUT_H, INPUT_W); 109 | } 110 | 111 | void caffeToGIEModel(const std::string& deployFile, // name for caffe prototxt 112 | const std::string& modelFile, // name for model 113 | const std::vector& outputs, // network outputs 114 | unsigned int maxBatchSize, // batch size - NB must be at least as large as the batch we want to run with) 115 | nvcaffeparser1::IPluginFactory* pluginFactory, // factory for plugin layers 116 | IHostMemory *&gieModelStream) // output stream for the GIE model 117 | { 118 | // create the builder 119 | std::cout << "start parsing model..." << std::endl; 120 | IBuilder* builder = createInferBuilder(gLogger); 121 | std::cout << "start1 parsing model..." << std::endl; 122 | // parse the caffe model to populate the network, then set the outputs 123 | INetworkDefinition* network = builder->createNetwork(); 124 | ICaffeParser* parser = createCaffeParser(); 125 | parser->setPluginFactory(pluginFactory); 126 | std::cout << "start2 parsing model..." << std::endl; 127 | bool fp16 = builder->platformHasFastFp16(); 128 | const IBlobNameToTensor* blobNameToTensor = parser->parse( deployFile.c_str(), 129 | modelFile.c_str(), 130 | *network, 131 | fp16 ? DataType::kHALF : DataType::kFLOAT); 132 | std::cout << "start3 parsing model..." << std::endl; 133 | // specify which tensors are outputs 134 | for (auto& s : outputs) 135 | network->markOutput(*blobNameToTensor->find(s.c_str())); 136 | 137 | std::cout << "start4 parsing model..." << std::endl; 138 | // Build the engine 139 | builder->setMaxBatchSize(maxBatchSize); 140 | builder->setMaxWorkspaceSize(10 << 20); 141 | builder->setHalf2Mode(fp16); 142 | 143 | ICudaEngine* engine = builder->buildCudaEngine(*network); 144 | assert(engine); 145 | std::cout << "start5 parsing model..." << std::endl; 146 | // we don't need the network any more, and we can destroy the parser 147 | network->destroy(); 148 | parser->destroy(); 149 | std::cout << "start6 parsing model..." << std::endl; 150 | // serialize the engine, then close everything down 151 | gieModelStream = engine->serialize(); 152 | 153 | engine->destroy(); 154 | builder->destroy(); 155 | shutdownProtobufLibrary(); 156 | 157 | std::cout << "End parsing model.qq.." << std::endl; 158 | } 159 | 160 | void doInference(IExecutionContext& context, float* input, float* output0, float* output1, float* output2, int batchSize) 161 | { 162 | const ICudaEngine& engine = context.getEngine(); 163 | // input and output buffer pointers that we pass to the engine - the engine requires exactly IEngine::getNbBindings(), 164 | // of these, but in this case we know that there is exactly one input and one output. 165 | std::cout<> ppm.magic >> ppm.w >> ppm.h >> ppm.max; 215 | std::cout << ppm.magic<<"---"<< ppm.w<<"---"<(ppm.buffer), ppm.w * ppm.h * 3); 218 | } 219 | 220 | 221 | cv::Mat Preprocess(const cv::Mat& img) { 222 | /* Convert the input image to the input image format of the network. */ 223 | cv::Mat sample; 224 | int num_channels_=3; 225 | if (img.channels() == 3 && num_channels_ == 1) 226 | cv::cvtColor(img, sample, cv::COLOR_BGR2GRAY); 227 | else if (img.channels() == 4 && num_channels_ == 1) 228 | cv::cvtColor(img, sample, cv::COLOR_BGRA2GRAY); 229 | else if (img.channels() == 4 && num_channels_ == 3) 230 | cv::cvtColor(img, sample, cv::COLOR_BGRA2BGR); 231 | else if (img.channels() == 1 && num_channels_ == 3) 232 | cv::cvtColor(img, sample, cv::COLOR_GRAY2BGR); 233 | else 234 | sample = img; 235 | 236 | cv::Mat sample_resized; 237 | if (sample.size() != cv::Size(416,416)) 238 | cv::resize(sample, sample_resized, cv::Size(416,416)); 239 | else 240 | sample_resized = sample; 241 | 242 | cv::Mat sample_float; 243 | if (num_channels_ == 3) 244 | sample_resized.convertTo(sample_float, CV_32FC3); 245 | else 246 | sample_resized.convertTo(sample_float, CV_32FC1); 247 | 248 | 249 | // cv::imshow( "Display window1", sample_resized); 250 | // cv::waitKey(0); 251 | 252 | // cv::cvtColor(sample_resized, sample_resized, cv::COLOR_BGR2RGB); 253 | // sample_float=(sample_float-127.5); 254 | // sample_float*=1/127.0; 255 | 256 | return sample_resized; 257 | } 258 | using namespace std; 259 | 260 | float prob1[OUTPUT_SIZE0]={0}; 261 | float prob2[OUTPUT_SIZE1]={0}; 262 | float prob3[OUTPUT_SIZE2]={0}; 263 | 264 | int main(int argc, char** argv) 265 | { 266 | // create a GIE model from the caffe model and serialize it to a stream 267 | PluginFactory pluginFactory; 268 | IHostMemory *gieModelStream{ nullptr }; 269 | caffeToGIEModel("yyy.prototxt", "yyy.caffemodel", std::vector < std::string > { OUTPUT_BLOB_NAME0 ,OUTPUT_BLOB_NAME1,OUTPUT_BLOB_NAME2}, 1, &pluginFactory, gieModelStream); 270 | pluginFactory.destroyPlugin(); 271 | std::cout << "staraaat deserializeCudaEngine model..." << std::endl; 272 | 273 | 274 | cv::Mat img = cv::imread("/opt/dog.jpg", 1); 275 | //CHECK(!img.empty()) << "Unable to decode image " << "/opt/deep_learn/traffic_light/2018.1.4/videoShot20171214/35.jpg"; 276 | std::cout << "\n\n\n---------------------------3" << "\n\n\n" << std::endl; 277 | img=Preprocess(img); 278 | 279 | 280 | 281 | PPM imagePPM[1]; 282 | // int num = rand() % 10; 283 | readPPMFile( "Free-Converter.com-14515-5164734.ppm", imagePPM[0]); 284 | 285 | // print an ascii representation 286 | 287 | //for (int i = 0; i < INPUT_H*INPUT_W; i++) 288 | // std::cout << (" .:-=+*#%@"[fileData[i] / 26]) << (((i + 1) % INPUT_W) ? "" : "\n"); 289 | 290 | memcpy(imagePPM[0].buffer,img.data,INPUT_C*INPUT_H*INPUT_W); 291 | 292 | float* data = new float[1*INPUT_C*INPUT_H*INPUT_W]; 293 | // memcpy(imagePPM[0].buffer,img.data,INPUT_C*INPUT_H*INPUT_W); 294 | // pixel mean used by the Faster R-CNN's author 295 | //float pixelMean[3]{ 127.5f, 127.5f, 127.5f }; // also in BGR order 296 | 297 | for (int i = 0, volImg = INPUT_C*INPUT_H*INPUT_W; i < 1; ++i) 298 | { 299 | for (int c = 0; c < INPUT_C; ++c) 300 | { 301 | // the color image to input should be in RGB order 302 | for (unsigned j = 0, volChl = INPUT_H*INPUT_W; j < volChl; ++j) 303 | data[i*volImg + c*volChl + j] = (float(imagePPM[i].buffer[j*INPUT_C + 2 - c]))*1/255.0; 304 | } 305 | } 306 | 307 | 308 | 309 | 310 | 311 | 312 | //ICaffeParser* parser = createCaffeParser(); 313 | //IBinaryProtoBlob* meanBlob = parser->parseBinaryProto(locateFile("mnist_mean.binaryproto").c_str()); 314 | //parser->destroy(); 315 | 316 | // parse the mean file and subtract it from the image 317 | //const float *meanData = reinterpret_cast(meanBlob->getData()); 318 | 319 | //float data[INPUT_H*INPUT_W]; 320 | //for (int i = 0; i < INPUT_H*INPUT_W; i++) 321 | // data[i] = float(fileData[i])-meanData[i]; 322 | 323 | //meanBlob->destroy(); 324 | 325 | // deserialize the engine 326 | IRuntime* runtime = createInferRuntime(gLogger); 327 | std::cout << "start deserializeCudaEngine model..." << std::endl; 328 | ICudaEngine* engine = runtime->deserializeCudaEngine(gieModelStream->data(), gieModelStream->size(), &pluginFactory); 329 | std::cout << "end deserializeCudaEngine model..." << std::endl; 330 | IExecutionContext *context = engine->createExecutionContext(); 331 | context->setProfiler(&gProfiler); 332 | 333 | 334 | // run inference 335 | 336 | doInference(*context, data, prob1,prob2,prob3, 1); 337 | 338 | printf("%f %f %f %f %f\n",prob1[0],prob1[1],prob1[2],prob1[3],prob1[4]); 339 | printf("%f %f %f %f %f\n",prob2[0],prob2[1],prob2[2],prob2[3],prob2[4]); 340 | printf("%f %f %f %f %f\n",prob3[0],prob3[1],prob3[2],prob3[3],prob3[4]); 341 | // destroy the engine 342 | context->destroy(); 343 | engine->destroy(); 344 | gProfiler.printLayerTimes(); 345 | runtime->destroy(); 346 | pluginFactory.destroyPlugin(); 347 | 348 | // print a histogram of the output distribution 349 | 350 | 351 | return 1; 352 | } 353 | -------------------------------------------------------------------------------- /PluginFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLUGIN_FACTORY_H__ 2 | #define __PLUGIN_FACTORY_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "NvCaffeParser.h" 11 | #include "NvInferPlugin.h" 12 | #include "upsample_layer.h" 13 | 14 | 15 | using namespace nvinfer1; 16 | using namespace nvcaffeparser1; 17 | using namespace plugin; 18 | #if 0 19 | //Concat layer . TensorRT Concat only support cross channel 20 | class ConcatPlugin : public IPlugin 21 | { 22 | public: 23 | ConcatPlugin(int axis){ _axis = axis; }; 24 | // ConcatPlugin(int axis, const void* buffer, size_t size); 25 | ConcatPlugin::ConcatPlugin(int axis, const void* buffer, size_t size) 26 | { 27 | assert(size == (18*sizeof(int))); 28 | const int* d = reinterpret_cast(buffer); 29 | 30 | dimsConv4_3 = DimsCHW{d[0], d[1], d[2]}; 31 | dimsFc7 = DimsCHW{d[3], d[4], d[5]}; 32 | dimsConv6 = DimsCHW{d[6], d[7], d[8]}; 33 | dimsConv7 = DimsCHW{d[9], d[10], d[11]}; 34 | dimsConv8 = DimsCHW{d[12], d[13], d[14]}; 35 | dimsConv9 = DimsCHW{d[15], d[16], d[17]}; 36 | 37 | _axis = axis; 38 | 39 | } 40 | 41 | 42 | inline int getNbOutputs() const override {return 1;}; 43 | // Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override ; 44 | 45 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) 46 | { 47 | assert(nbInputDims == 6); 48 | 49 | if(_axis == 1) 50 | { 51 | top_concat_axis = inputs[0].d[0] + inputs[1].d[0] + inputs[2].d[0] + inputs[3].d[0] + inputs[4].d[0] + inputs[5].d[0]; 52 | return DimsCHW(top_concat_axis, 1, 1); 53 | }else if(_axis == 2){ 54 | top_concat_axis = inputs[0].d[1] + inputs[1].d[1] + inputs[2].d[1] + inputs[3].d[1] + inputs[4].d[1] + inputs[5].d[1]; 55 | return DimsCHW(2, top_concat_axis, 1); 56 | }else{//_param.concat_axis == 3 57 | 58 | return DimsCHW(0, 0, 0); 59 | } 60 | } 61 | 62 | 63 | // int initialize() 64 | 65 | 66 | int initialize() 67 | { 68 | inputs_size = 6;//6个bottom层 69 | 70 | if(_axis == 1)//c 71 | { 72 | top_concat_axis = dimsConv4_3.c() + dimsFc7.c() + dimsConv6.c() + dimsConv7.c() + dimsConv8.c() + dimsConv9.c(); 73 | bottom_concat_axis[0] = dimsConv4_3.c(); bottom_concat_axis[1] = dimsFc7.c(); bottom_concat_axis[2] = dimsConv6.c(); 74 | bottom_concat_axis[3] = dimsConv7.c(); bottom_concat_axis[4] = dimsConv8.c(); bottom_concat_axis[5] = dimsConv9.c(); 75 | 76 | concat_input_size_[0] = dimsConv4_3.h() * dimsConv4_3.w(); concat_input_size_[1] = dimsFc7.h() * dimsFc7.w(); 77 | concat_input_size_[2] = dimsConv6.h() * dimsConv6.w(); concat_input_size_[3] = dimsConv7.h() * dimsConv7.w(); 78 | concat_input_size_[4] = dimsConv8.h() * dimsConv8.w(); concat_input_size_[5] = dimsConv9.h() * dimsConv9.w(); 79 | 80 | num_concats_[0] = dimsConv4_3.c(); num_concats_[1] = dimsFc7.c(); num_concats_[2] = dimsConv6.c(); 81 | num_concats_[3] = dimsConv7.c(); num_concats_[4] = dimsConv8.c(); num_concats_[5] = dimsConv9.c(); 82 | }else if(_axis == 2){//h 83 | top_concat_axis = dimsConv4_3.h() + dimsFc7.h() + dimsConv6.h() + dimsConv7.h() + dimsConv8.h() + dimsConv9.h(); 84 | bottom_concat_axis[0] = dimsConv4_3.h(); bottom_concat_axis[1] = dimsFc7.h(); bottom_concat_axis[2] = dimsConv6.h(); 85 | bottom_concat_axis[3] = dimsConv7.h(); bottom_concat_axis[4] = dimsConv8.h(); bottom_concat_axis[5] = dimsConv9.h(); 86 | 87 | concat_input_size_[0] = dimsConv4_3.w(); concat_input_size_[1] = dimsFc7.w(); concat_input_size_[2] = dimsConv6.w(); 88 | concat_input_size_[3] = dimsConv7.w(); concat_input_size_[4] = dimsConv8.w(); concat_input_size_[5] = dimsConv9.w(); 89 | 90 | num_concats_[0] = dimsConv4_3.c() * dimsConv4_3.h(); num_concats_[1] = dimsFc7.c() * dimsFc7.h(); 91 | num_concats_[2] = dimsConv6.c() * dimsConv6.h(); num_concats_[3] = dimsConv7.c() * dimsConv7.h(); 92 | num_concats_[4] = dimsConv8.c() * dimsConv8.h(); num_concats_[5] = dimsConv9.c() * dimsConv9.h(); 93 | 94 | }else{//_param.concat_axis == 3 , w 95 | top_concat_axis = dimsConv4_3.w() + dimsFc7.w() + dimsConv6.w() + dimsConv7.w() + dimsConv8.w() + dimsConv9.w(); 96 | bottom_concat_axis[0] = dimsConv4_3.w(); bottom_concat_axis[1] = dimsFc7.w(); bottom_concat_axis[2] = dimsConv6.w(); 97 | bottom_concat_axis[3] = dimsConv7.w(); bottom_concat_axis[4] = dimsConv8.w(); bottom_concat_axis[5] = dimsConv9.w(); 98 | 99 | concat_input_size_[0] = 1; concat_input_size_[1] = 1; concat_input_size_[2] = 1; 100 | concat_input_size_[3] = 1; concat_input_size_[4] = 1; concat_input_size_[5] = 1; 101 | return 0; 102 | } 103 | 104 | return 0; 105 | } 106 | 107 | // inline void terminate() override; 108 | void terminate() 109 | { 110 | //CUDA_CHECK(cudaFree(scale_data)); 111 | delete[] bottom_concat_axis; 112 | delete[] concat_input_size_; 113 | delete[] num_concats_; 114 | } 115 | 116 | 117 | 118 | inline size_t getWorkspaceSize(int) const override { return 0; }; 119 | //int enqueue(int batchSize, const void*const *inputs, void** outputs, void*, cudaStream_t stream) override; 120 | 121 | int enqueue(int batchSize, const void*const *inputs, void** outputs, void*, cudaStream_t stream) 122 | { 123 | float *top_data = reinterpret_cast(outputs[0]); 124 | int offset_concat_axis = 0; 125 | const bool kForward = true; 126 | for (int i = 0; i < inputs_size; ++i) { 127 | const float *bottom_data = reinterpret_cast(inputs[i]); 128 | 129 | const int nthreads = num_concats_[i] * concat_input_size_[i]; 130 | //const int nthreads = bottom_concat_size * num_concats_[i]; 131 | ConcatLayer(nthreads, bottom_data, kForward, num_concats_[i], concat_input_size_[i], top_concat_axis, bottom_concat_axis[i], offset_concat_axis, top_data, stream); 132 | 133 | offset_concat_axis += bottom_concat_axis[i]; 134 | } 135 | 136 | return 0; 137 | } 138 | 139 | // size_t getSerializationSize() override; 140 | size_t getSerializationSize() 141 | { 142 | return 18*sizeof(int); 143 | } 144 | 145 | 146 | // void serialize(void* buffer) override; 147 | 148 | void serialize(void* buffer) 149 | { 150 | int* d = reinterpret_cast(buffer); 151 | d[0] = dimsConv4_3.c(); d[1] = dimsConv4_3.h(); d[2] = dimsConv4_3.w(); 152 | d[3] = dimsFc7.c(); d[4] = dimsFc7.h(); d[5] = dimsFc7.w(); 153 | d[6] = dimsConv6.c(); d[7] = dimsConv6.h(); d[8] = dimsConv6.w(); 154 | d[9] = dimsConv7.c(); d[10] = dimsConv7.h(); d[11] = dimsConv7.w(); 155 | d[12] = dimsConv8.c(); d[13] = dimsConv8.h(); d[14] = dimsConv8.w(); 156 | d[15] = dimsConv9.c(); d[16] = dimsConv9.h(); d[17] = dimsConv9.w(); 157 | } 158 | 159 | 160 | 161 | // void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override; 162 | 163 | void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) 164 | { 165 | dimsConv4_3 = DimsCHW{inputs[0].d[0], inputs[0].d[1], inputs[0].d[2]}; 166 | dimsFc7 = DimsCHW{inputs[1].d[0], inputs[1].d[1], inputs[1].d[2]}; 167 | dimsConv6 = DimsCHW{inputs[2].d[0], inputs[2].d[1], inputs[2].d[2]}; 168 | dimsConv7 = DimsCHW{inputs[3].d[0], inputs[3].d[1], inputs[3].d[2]}; 169 | dimsConv8 = DimsCHW{inputs[4].d[0], inputs[4].d[1], inputs[4].d[2]}; 170 | dimsConv9 = DimsCHW{inputs[5].d[0], inputs[5].d[1], inputs[5].d[2]}; 171 | } 172 | 173 | 174 | 175 | 176 | 177 | protected: 178 | DimsCHW dimsConv4_3, dimsFc7, dimsConv6, dimsConv7, dimsConv8, dimsConv9; 179 | int inputs_size; 180 | int top_concat_axis;//top 层 concat后的维度 181 | int* bottom_concat_axis = new int[9];//记录每个bottom层concat维度的shape 182 | int* concat_input_size_ = new int[9]; 183 | int* num_concats_ = new int[9]; 184 | int _axis; 185 | }; 186 | 187 | #endif 188 | 189 | //SSD Reshape layer : shape{0,-1,21} 190 | template 191 | class Reshape : public IPlugin 192 | { 193 | public: 194 | Reshape() {} 195 | Reshape(const void* buffer, size_t size) 196 | { 197 | assert(size == sizeof(mCopySize)); 198 | mCopySize = *reinterpret_cast(buffer); 199 | } 200 | 201 | int getNbOutputs() const override 202 | { 203 | return 1; 204 | } 205 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override 206 | { 207 | assert(nbInputDims == 1); 208 | assert(index == 0); 209 | assert(inputs[index].nbDims == 3); 210 | assert((inputs[0].d[0])*(inputs[0].d[1]) % OutC == 0); 211 | return DimsCHW(OutC, inputs[0].d[0] * inputs[0].d[1] / OutC, inputs[0].d[2]); 212 | } 213 | 214 | int initialize() override 215 | { 216 | return 0; 217 | } 218 | 219 | void terminate() override 220 | { 221 | } 222 | 223 | size_t getWorkspaceSize(int) const override 224 | { 225 | return 0; 226 | } 227 | 228 | // currently it is not possible for a plugin to execute "in place". Therefore we memcpy the data from the input to the output buffer 229 | int enqueue(int batchSize, const void*const *inputs, void** outputs, void*, cudaStream_t stream) override 230 | { 231 | CHECK(cudaMemcpyAsync(outputs[0], inputs[0], mCopySize * batchSize, cudaMemcpyDeviceToDevice, stream)); 232 | return 0; 233 | } 234 | 235 | 236 | size_t getSerializationSize() override 237 | { 238 | return sizeof(mCopySize); 239 | } 240 | 241 | void serialize(void* buffer) override 242 | { 243 | *reinterpret_cast(buffer) = mCopySize; 244 | } 245 | 246 | void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override 247 | { 248 | mCopySize = inputs[0].d[0] * inputs[0].d[1] * inputs[0].d[2] * sizeof(float); 249 | } 250 | 251 | protected: 252 | size_t mCopySize; 253 | }; 254 | 255 | 256 | 257 | class SofaMaxChannelLayer: public IPlugin 258 | { 259 | public: 260 | SofaMaxChannelLayer(int axis): _axis(axis),inner_num_(1),outer_num_(3462){} 261 | 262 | SofaMaxChannelLayer(int axis,const void* buffer,size_t size) 263 | { 264 | _axis = axis; 265 | } 266 | 267 | inline int getNbOutputs() const override { return 1; }; 268 | 269 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override 270 | { 271 | 272 | return DimsCHW(1,3462, 2); 273 | } 274 | 275 | int initialize() override 276 | { 277 | return 0; 278 | } 279 | inline void terminate() override 280 | { 281 | } 282 | 283 | inline size_t getWorkspaceSize(int) const override { return 0; } 284 | int enqueue(int batchSize, const void*const *inputs, void** outputs, void*, cudaStream_t stream) override 285 | { 286 | 287 | return 0; 288 | } 289 | 290 | 291 | size_t getSerializationSize() override 292 | { 293 | return 0; 294 | } 295 | 296 | void serialize(void* buffer) override 297 | { 298 | 299 | } 300 | 301 | void configure(const Dims* inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override 302 | { 303 | 304 | #if 0 305 | int dim = bottom[0]->count() / outer_num_; 306 | caffe_copy(bottom[0]->count(), bottom_data, top_data); 307 | // We need to subtract the max to avoid numerical issues, compute the exp, 308 | // and then normalize. 309 | for (int i = 0; i < outer_num_; ++i) { 310 | // initialize scale_data to the first plane 311 | caffe_copy(inner_num_, bottom_data + i * dim, scale_data); 312 | for (int j = 0; j < ; j++) { 313 | for (int k = 0; k < inner_num_; k++) { 314 | scale_data[k] = std::max(scale_data[k], 315 | bottom_data[i * dim + j * inner_num_ + k]); 316 | } 317 | } 318 | // subtraction 319 | caffe_cpu_gemm(CblasNoTrans, CblasNoTrans, channels, inner_num_, 320 | 1, -1., sum_multiplier_.cpu_data(), scale_data, 1., top_data); 321 | // exponentiation 322 | caffe_exp(dim, top_data, top_data); 323 | // sum after exp 324 | caffe_cpu_gemv(CblasTrans, channels, inner_num_, 1., 325 | top_data, sum_multiplier_.cpu_data(), 0., scale_data); 326 | // division 327 | for (int j = 0; j < channels; j++) { 328 | caffe_div(inner_num_, top_data, scale_data, top_data); 329 | top_data += inner_num_; 330 | } 331 | } 332 | 333 | 334 | #endif 335 | 336 | 337 | 338 | } 339 | 340 | protected: 341 | int _axis; 342 | int _size; 343 | float* scale = new float [3462]; //scale 344 | int inner_num_; 345 | int outer_num_; 346 | 347 | 348 | 349 | }; 350 | 351 | # if 0 352 | __global__ void ReLUForward1(const int n, const float* in, float* out, 353 | float negative_slope) { 354 | CUDA_KERNEL_LOOP(index, n) { 355 | printf("ReLUForwardsss 01 enqueue line=%d",__LINE__); 356 | out[index] = in[index] > 0 ? in[index] : in[index] * negative_slope; 357 | } 358 | } 359 | #endif 360 | 361 | //SSD Flatten layer 362 | class LReluLayer : public IPlugin 363 | { 364 | public: 365 | LReluLayer(){} 366 | LReluLayer(float para):para_(para) 367 | { 368 | 369 | 370 | std::cout<<"LReluLayer0"<(buffer); 379 | float* p=(float*)(d+3); 380 | para_=p[0]; 381 | channel_=d[0]; 382 | w_=d[1]; 383 | h_=d[2]; 384 | 385 | //std::cout<<"LReluLayer1"<>>(batchSize*channel_*w_*h_,inputs[0],outputs[0],para_); 421 | 422 | //std::cout<<"flatten enqueue:"<(buffer); 447 | int* d = reinterpret_cast(buffer); 448 | d[0] = channel_; d[1] = w_; d[2] = h_; 449 | q[4]=para_; 450 | 451 | //serializeFromDevice(d, mKernelWeights); 452 | //serializeFromDevice(d, mBiasWeights); 453 | 454 | 455 | 456 | } 457 | 458 | void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override 459 | { 460 | // dimBottom = DimsCHW(inputs[0].d[0], inputs[0].d[1], inputs[0].d[2]); 461 | channel_=inputs[0].d[0]; 462 | w_=inputs[0].d[1]; 463 | h_=inputs[0].d[2]; 464 | 465 | } 466 | 467 | protected: 468 | float para_; 469 | int channel_; 470 | int w_; 471 | int h_; 472 | }; 473 | 474 | 475 | 476 | 477 | 478 | //SSD Flatten layer 479 | class UpsampleLayer : public IPlugin 480 | { 481 | public: 482 | UpsampleLayer(){} 483 | UpsampleLayer(size_t stride):stride_(stride) 484 | { 485 | std::cout<<"UpsampleLayer0"<(buffer); 494 | 495 | channel_=d[0]; 496 | w_=d[1]; 497 | h_=d[2]; 498 | 499 | 500 | std::cout<<"UpsampleLayer1"<(buffer); 552 | d[0] = channel_; d[1] = w_; d[2] = h_; 553 | d[3]=stride_; 554 | 555 | } 556 | 557 | void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override 558 | { 559 | // dimBottom = DimsCHW(inputs[0].d[0], inputs[0].d[1], inputs[0].d[2]); 560 | channel_=inputs[0].d[0]; 561 | w_=inputs[0].d[1]; 562 | h_=inputs[0].d[2]; 563 | 564 | } 565 | 566 | protected: 567 | int stride_; 568 | int channel_; 569 | int w_; 570 | int h_; 571 | }; 572 | 573 | 574 | 575 | 576 | 577 | //SSD Flatten layer 578 | class FlattenLayer : public IPlugin 579 | { 580 | public: 581 | FlattenLayer(){} 582 | FlattenLayer(const void* buffer,size_t size) 583 | { 584 | assert(size == 3 * sizeof(int)); 585 | const int* d = reinterpret_cast(buffer); 586 | _size = d[0] * d[1] * d[2]; 587 | dimBottom = DimsCHW{d[0], d[1], d[2]}; 588 | } 589 | 590 | inline int getNbOutputs() const override { return 1; }; 591 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override 592 | { 593 | assert(1 == nbInputDims); 594 | assert(0 == index); 595 | assert(3 == inputs[index].nbDims); 596 | _size = inputs[0].d[0] * inputs[0].d[1] * inputs[0].d[2]; 597 | return DimsCHW(_size, 1, 1); 598 | } 599 | 600 | int initialize() override 601 | { 602 | return 0; 603 | } 604 | inline void terminate() override 605 | { 606 | } 607 | 608 | inline size_t getWorkspaceSize(int) const override { return 0; } 609 | int enqueue(int batchSize, const void*const *inputs, void** outputs, void*, cudaStream_t stream) override 610 | { 611 | std::cout<<"flatten enqueue:"<(buffer); 625 | d[0] = dimBottom.c(); d[1] = dimBottom.h(); d[2] = dimBottom.w(); 626 | } 627 | 628 | void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override 629 | { 630 | dimBottom = DimsCHW(inputs[0].d[0], inputs[0].d[1], inputs[0].d[2]); 631 | } 632 | 633 | protected: 634 | DimsCHW dimBottom; 635 | int _size; 636 | }; 637 | 638 | 639 | 640 | 641 | 642 | class PluginFactory : public nvinfer1::IPluginFactory, public nvcaffeparser1::IPluginFactory { 643 | public: 644 | 645 | // caffe parser plugin implementation 646 | bool isPlugin(const char* name) override 647 | { 648 | printf("isPlugin %s\n",name); 649 | return (!strcmp(name, "conv11_mbox_loc_perm") 650 | || !strcmp(name, "conv11_mbox_conf_flat") 651 | || !strcmp(name, "conv11_mbox_conf_perm") 652 | || !strcmp(name, "conv11_mbox_loc_flat") 653 | || !strcmp(name, "conv11_mbox_priorbox") 654 | 655 | || !strcmp(name, "conv13_mbox_loc_perm") 656 | || !strcmp(name, "conv13_mbox_loc_flat") 657 | || !strcmp(name, "conv13_mbox_conf_perm") 658 | || !strcmp(name, "conv13_mbox_conf_flat") 659 | || !strcmp(name, "conv13_mbox_priorbox") 660 | 661 | || !strcmp(name, "conv14_2_mbox_loc_perm") 662 | || !strcmp(name, "conv14_2_mbox_loc_flat") 663 | || !strcmp(name, "conv14_2_mbox_conf_perm") 664 | || !strcmp(name, "conv14_2_mbox_conf_flat") 665 | || !strcmp(name, "conv14_2_mbox_priorbox") 666 | 667 | || !strcmp(name, "conv15_2_mbox_loc_perm") 668 | || !strcmp(name, "conv15_2_mbox_loc_flat") 669 | || !strcmp(name, "conv15_2_mbox_conf_perm") 670 | || !strcmp(name, "conv15_2_mbox_conf_flat") 671 | || !strcmp(name, "conv15_2_mbox_priorbox") 672 | 673 | || !strcmp(name, "conv16_2_mbox_loc_perm") 674 | || !strcmp(name, "conv16_2_mbox_loc_flat") 675 | || !strcmp(name, "conv16_2_mbox_conf_perm") 676 | || !strcmp(name, "conv16_2_mbox_conf_flat") 677 | || !strcmp(name, "conv16_2_mbox_priorbox") 678 | 679 | || !strcmp(name, "conv17_2_mbox_loc_perm") 680 | || !strcmp(name, "conv17_2_mbox_loc_flat") 681 | || !strcmp(name, "conv17_2_mbox_conf_perm") 682 | || !strcmp(name, "conv17_2_mbox_conf_flat") 683 | || !strcmp(name, "conv17_2_mbox_priorbox") 684 | 685 | || !strcmp(name, "mbox_conf_reshape") 686 | || !strcmp(name, "mbox_conf_flatten") 687 | || !strcmp(name, "detection_out") 688 | 689 | || !strcmp(name, "mbox_loc") 690 | || !strcmp(name, "mbox_conf") 691 | || !strcmp(name, "mbox_priorbox") 692 | || !strcmp(name, "mbox_conf_softmax") 693 | 694 | || !strcmp(name, "layer85-upsample") 695 | || !strcmp(name, "layer97-upsample") 696 | 697 | || !strcmp(name, "layer104-act") 698 | || !strcmp(name, "layer28-act") 699 | || !strcmp(name, "layer0-act") 700 | || !strcmp(name, "layer2-act") 701 | || !strcmp(name, "layer1-act") 702 | || !strcmp(name, "layer103-act") 703 | || !strcmp(name, "layer102-act") 704 | || !strcmp(name, "layer101-act") 705 | || !strcmp(name, "layer100-act") 706 | || !strcmp(name, "layer99-act") 707 | || !strcmp(name, "layer96-act") 708 | || !strcmp(name, "layer92-act") 709 | || !strcmp(name, "layer91-act") 710 | || !strcmp(name, "layer90-act") 711 | || !strcmp(name, "layer89-act") 712 | || !strcmp(name, "layer88-act") 713 | || !strcmp(name, "layer87-act") 714 | || !strcmp(name, "layer84-act") 715 | || !strcmp(name, "layer80-act") 716 | || !strcmp(name, "layer79-act") 717 | || !strcmp(name, "layer78-act") 718 | 719 | 720 | 721 | || !strcmp(name, "layer77-act") 722 | || !strcmp(name, "layer76-act") 723 | || !strcmp(name, "layer75-act") 724 | || !strcmp(name, "layer73-act") 725 | || !strcmp(name, "layer72-act") 726 | || !strcmp(name, "layer70-act") 727 | || !strcmp(name, "layer69-act") 728 | || !strcmp(name, "layer67-act") 729 | || !strcmp(name, "layer66-act") 730 | || !strcmp(name, "layer64-act") 731 | || !strcmp(name, "layer63-act") 732 | || !strcmp(name, "layer62-act") 733 | || !strcmp(name, "layer60-act") 734 | || !strcmp(name, "layer59-act") 735 | || !strcmp(name, "layer57-act") 736 | || !strcmp(name, "layer56-act") 737 | || !strcmp(name, "layer54-act") 738 | || !strcmp(name, "layer53-act") 739 | // 740 | 741 | || !strcmp(name, "layer51-act") 742 | || !strcmp(name, "layer50-act") 743 | || !strcmp(name, "layer48-act") 744 | || !strcmp(name, "layer47-act") 745 | || !strcmp(name, "layer45-act") 746 | || !strcmp(name, "layer44-act") 747 | || !strcmp(name, "layer42-act") 748 | || !strcmp(name, "layer41-act") 749 | || !strcmp(name, "layer39-act") 750 | || !strcmp(name, "layer38-act") 751 | || !strcmp(name, "layer37-act") 752 | || !strcmp(name, "layer35-act") 753 | || !strcmp(name, "layer34-act") 754 | || !strcmp(name, "layer32-act") 755 | || !strcmp(name, "layer31-act") 756 | || !strcmp(name, "layer29-act") 757 | || !strcmp(name, "layer26-act") 758 | || !strcmp(name, "layer25-act") 759 | 760 | 761 | 762 | || !strcmp(name, "layer23-act") 763 | || !strcmp(name, "layer22-act") 764 | || !strcmp(name, "layer20-act") 765 | || !strcmp(name, "layer19-act") 766 | || !strcmp(name, "layer17-act") 767 | || !strcmp(name, "layer16-act") 768 | || !strcmp(name, "layer14-act") 769 | || !strcmp(name, "layer13-act") 770 | || !strcmp(name, "layer12-act") 771 | || !strcmp(name, "layer10-act") 772 | || !strcmp(name, "layer9-act") 773 | || !strcmp(name, "layer7-act") 774 | || !strcmp(name, "layer6-act") 775 | || !strcmp(name, "layer5-act") 776 | || !strcmp(name, "layer3-act") 777 | 778 | 779 | ); 780 | 781 | } 782 | 783 | virtual IPlugin* createPlugin(const char* layerName, const Weights* weights, int nbWeights) override 784 | { 785 | // there's no way to pass parameters through from the model definition, so we have to define it here explicitly 786 | if(!strcmp(layerName, "conv4_3_norm")){ 787 | 788 | //INvPlugin * plugin::createSSDNormalizePlugin (const Weights *scales, bool acrossSpatial, bool channelShared, float eps) 789 | 790 | _nvPlugins[layerName] = plugin::createSSDNormalizePlugin(weights,false,false,1e-10); 791 | 792 | return _nvPlugins.at(layerName); 793 | 794 | }else if(!strcmp(layerName, "conv11_mbox_loc_perm") 795 | || !strcmp(layerName, "conv11_mbox_conf_perm") 796 | || !strcmp(layerName, "conv13_mbox_loc_perm") 797 | || !strcmp(layerName,"conv13_mbox_conf_perm") 798 | || !strcmp(layerName,"conv14_2_mbox_loc_perm") 799 | || !strcmp(layerName,"conv14_2_mbox_conf_perm") 800 | || !strcmp(layerName,"conv15_2_mbox_loc_perm") 801 | || !strcmp(layerName,"conv15_2_mbox_conf_perm") 802 | || !strcmp(layerName,"conv16_2_mbox_loc_perm") 803 | || !strcmp(layerName,"conv16_2_mbox_conf_perm") 804 | || !strcmp(layerName,"conv17_2_mbox_loc_perm") 805 | || !strcmp(layerName,"conv17_2_mbox_conf_perm") 806 | ){ 807 | 808 | _nvPlugins[layerName] = plugin::createSSDPermutePlugin(Quadruple({0,2,3,1})); 809 | return _nvPlugins.at(layerName); 810 | 811 | } else if(!strcmp(layerName,"conv11_mbox_priorbox")){ 812 | 813 | plugin::PriorBoxParameters params = {0}; 814 | float minSize[1] = {60.0f}; 815 | //float maxSize[1] = {60.0f}; 816 | float aspectRatios[1] = {2.0f}; 817 | params.minSize = (float*)minSize; 818 | //params.maxSize = (float*)maxSize; 819 | params.aspectRatios = (float*)aspectRatios; 820 | params.numMinSize = 1; 821 | params.numMaxSize = 0; 822 | params.numAspectRatios = 1; 823 | params.flip = true; 824 | params.clip = false; 825 | params.variance[0] = 0.10000000149; 826 | params.variance[1] = 0.10000000149; 827 | params.variance[2] = 0.20000000298; 828 | params.variance[3] = 0.20000000298; 829 | params.imgH = 0; 830 | params.imgW = 0; 831 | params.stepH = 0.0f; 832 | params.stepW = 0.0f; 833 | params.offset = 0.5f; 834 | _nvPlugins[layerName] = plugin::createSSDPriorBoxPlugin(params); 835 | 836 | return _nvPlugins.at(layerName); 837 | }else if(!strcmp(layerName,"conv13_mbox_priorbox")){ 838 | 839 | plugin::PriorBoxParameters params = {0}; 840 | float minSize[1] = {105.0f}; 841 | float maxSize[1] = {150.0f}; 842 | float aspectRatios[2] = {2.0f, 3.0f}; 843 | params.minSize = (float*)minSize; 844 | params.maxSize = (float*)maxSize; 845 | params.aspectRatios = (float*)aspectRatios; 846 | params.numMinSize = 1; 847 | params.numMaxSize = 1; 848 | params.numAspectRatios = 2; 849 | params.flip = true; 850 | params.clip = false; 851 | params.variance[0] = 0.10000000149; 852 | params.variance[1] = 0.10000000149; 853 | params.variance[2] = 0.20000000298; 854 | params.variance[3] = 0.20000000298; 855 | params.imgH = 0; 856 | params.imgW = 0; 857 | params.stepH = 0.0f; 858 | params.stepW = 0.0f; 859 | params.offset = 0.5f; 860 | _nvPlugins[layerName] = plugin::createSSDPriorBoxPlugin(params); 861 | 862 | return _nvPlugins.at(layerName); 863 | }else if(!strcmp(layerName,"conv14_2_mbox_priorbox")){ 864 | plugin::PriorBoxParameters params = {0}; 865 | float minSize[1] = {150.0f}; 866 | float maxSize[1] = {195.0f}; 867 | float aspectRatios[2] = {2.0f, 3.0f}; 868 | params.minSize = (float*)minSize; 869 | params.maxSize = (float*)maxSize; 870 | params.aspectRatios = (float*)aspectRatios; 871 | params.numMinSize = 1; 872 | params.numMaxSize = 1; 873 | params.numAspectRatios = 2; 874 | params.flip = true; 875 | params.clip = false; 876 | params.variance[0] = 0.10000000149; 877 | params.variance[1] = 0.10000000149; 878 | params.variance[2] = 0.20000000298; 879 | params.variance[3] = 0.20000000298; 880 | params.imgH = 0; 881 | params.imgW = 0; 882 | params.stepH = 0.0f; 883 | params.stepW = 0.0f; 884 | params.offset = 5.0f; 885 | _nvPlugins[layerName] = plugin::createSSDPriorBoxPlugin(params); 886 | 887 | return _nvPlugins.at(layerName); 888 | }else if(!strcmp(layerName,"conv15_2_mbox_priorbox")){ 889 | 890 | plugin::PriorBoxParameters params = {0}; 891 | float minSize[1] = {195.0f}; 892 | float maxSize[1] = {240.0f}; 893 | float aspectRatios[2] = {2.0f, 3.0f}; 894 | params.minSize = (float*)minSize; 895 | params.maxSize = (float*)maxSize; 896 | params.aspectRatios = (float*)aspectRatios; 897 | params.numMinSize = 1; 898 | params.numMaxSize = 1; 899 | params.numAspectRatios = 2; 900 | params.flip = true; 901 | params.clip = false; 902 | params.variance[0] = 0.10000000149; 903 | params.variance[1] = 0.10000000149; 904 | params.variance[2] = 0.20000000298; 905 | params.variance[3] = 0.20000000298; 906 | params.imgH = 0; 907 | params.imgW = 0; 908 | params.stepH = 0.0f; 909 | params.stepW = 0.0f; 910 | params.offset = 0.5f; 911 | _nvPlugins[layerName] = plugin::createSSDPriorBoxPlugin(params); 912 | 913 | return _nvPlugins.at(layerName); 914 | }else if(!strcmp(layerName,"conv16_2_mbox_priorbox")){ 915 | 916 | plugin::PriorBoxParameters params = {0}; 917 | float minSize[1] = {240.0f}; 918 | float maxSize[1] = {285.0f}; 919 | float aspectRatios[2] = {2.0f,3.0f}; 920 | params.minSize = (float*)minSize; 921 | params.maxSize = (float*)maxSize; 922 | params.aspectRatios = (float*)aspectRatios; 923 | params.numMinSize = 1; 924 | params.numMaxSize = 1; 925 | params.numAspectRatios = 2; 926 | params.flip = true; 927 | params.clip = false; 928 | params.variance[0] = 0.10000000149; 929 | params.variance[1] = 0.10000000149; 930 | params.variance[2] = 0.20000000298; 931 | params.variance[3] = 0.20000000298; 932 | params.imgH = 0; 933 | params.imgW = 0; 934 | params.stepH = 0.0f; 935 | params.stepW = 0.0f; 936 | params.offset = 0.5f; 937 | _nvPlugins[layerName] = plugin::createSSDPriorBoxPlugin(params); 938 | 939 | return _nvPlugins.at(layerName); 940 | }else if(!strcmp(layerName,"conv17_2_mbox_priorbox")){ 941 | plugin::PriorBoxParameters params = {0}; 942 | float minSize[1] = {285.0f}; 943 | float maxSize[1] = {300.0f}; 944 | float aspectRatios[2] = {2.0f,3.0f}; 945 | params.minSize = (float*)minSize; 946 | params.maxSize = (float*)maxSize; 947 | params.aspectRatios = (float*)aspectRatios; 948 | params.numMinSize = 1; 949 | params.numMaxSize = 1; 950 | params.numAspectRatios = 2; 951 | params.flip = true; 952 | params.clip = false; 953 | params.variance[0] = 0.10000000149; 954 | params.variance[1] = 0.10000000149; 955 | params.variance[2] = 0.20000000298; 956 | params.variance[3] = 0.20000000298; 957 | params.imgH = 0; 958 | params.imgW = 0; 959 | params.stepH = 0.0f; 960 | params.stepW = 0.0f; 961 | params.offset = 0.5f; 962 | _nvPlugins[layerName] = plugin::createSSDPriorBoxPlugin(params); 963 | 964 | return _nvPlugins.at(layerName); 965 | }else if(!strcmp(layerName,"detection_out")){ 966 | /* 967 | bool shareLocation 968 | bool varianceEncodedInTarget 969 | int backgroundLabelId 970 | int numClasses 971 | int topK 972 | int keepTopK 973 | float confidenceThreshold 974 | float nmsThreshold 975 | CodeType_t codeType 976 | */ 977 | plugin::DetectionOutputParameters params = {0}; 978 | params.numClasses = 2; 979 | params.shareLocation = true; 980 | params.varianceEncodedInTarget = false; 981 | params.backgroundLabelId = 0; 982 | params.keepTopK = 100; 983 | params.codeType = CENTER_SIZE; 984 | params.nmsThreshold = 0.45; 985 | params.topK = 100; 986 | params.confidenceThreshold = 0.25; 987 | std::cout << "detection_out..." << std::endl; 988 | _nvPlugins[layerName] = plugin::createSSDDetectionOutputPlugin(params); 989 | return _nvPlugins.at(layerName); 990 | 991 | }else if ( 992 | !strcmp(layerName, "conv11_mbox_conf_flat") 993 | ||!strcmp(layerName,"conv11_mbox_loc_flat") 994 | ||!strcmp(layerName,"conv13_mbox_loc_flat") 995 | ||!strcmp(layerName,"conv13_mbox_conf_flat") 996 | ||!strcmp(layerName,"conv14_2_mbox_loc_flat") 997 | ||!strcmp(layerName,"conv14_2_mbox_conf_flat") 998 | ||!strcmp(layerName,"conv15_2_mbox_loc_flat") 999 | ||!strcmp(layerName,"conv15_2_mbox_conf_flat") 1000 | ||!strcmp(layerName,"conv16_2_mbox_loc_flat") 1001 | ||!strcmp(layerName,"conv16_2_mbox_conf_flat") 1002 | ||!strcmp(layerName,"conv17_2_mbox_loc_flat") 1003 | ||!strcmp(layerName,"conv17_2_mbox_conf_flat") 1004 | ||!strcmp(layerName,"mbox_conf_flatten") 1005 | ){ 1006 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new FlattenLayer()); 1007 | return _nvPlugins.at(layerName); 1008 | }else if(!strcmp(layerName,"mbox_conf_reshape")){ 1009 | _nvPlugins[layerName] = (plugin::INvPlugin*)new Reshape<2>(); 1010 | return _nvPlugins.at(layerName); 1011 | }else if(!strcmp(layerName,"mbox_loc")){ 1012 | _nvPlugins[layerName] = plugin::createConcatPlugin (1,false); 1013 | return _nvPlugins.at(layerName); 1014 | }else if(!strcmp(layerName,"mbox_conf")){ 1015 | _nvPlugins[layerName] = plugin::createConcatPlugin (1,false); 1016 | return _nvPlugins.at(layerName); 1017 | }else if(!strcmp(layerName,"mbox_priorbox")){ 1018 | _nvPlugins[layerName] = plugin::createConcatPlugin (2,false); 1019 | return _nvPlugins.at(layerName); 1020 | }else if(!strcmp(layerName, "mbox_conf_softmax")) 1021 | { 1022 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new SofaMaxChannelLayer(2)); 1023 | return _nvPlugins.at(layerName); 1024 | 1025 | 1026 | 1027 | }else if(!strcmp(layerName, "layer85-upsample")) 1028 | { 1029 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new UpsampleLayer(2)); 1030 | return _nvPlugins.at(layerName); 1031 | 1032 | 1033 | 1034 | }else if(!strcmp(layerName, "layer97-upsample")) 1035 | { 1036 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new UpsampleLayer(2)); 1037 | return _nvPlugins.at(layerName); 1038 | }else if ( !strcmp(layerName, "layer2-act") 1039 | || !strcmp(layerName, "layer104-act") 1040 | || !strcmp(layerName, "layer1-act") 1041 | || !strcmp(layerName, "layer0-act") 1042 | || !strcmp(layerName, "layer28-act") 1043 | || !strcmp(layerName, "layer103-act") 1044 | || !strcmp(layerName, "layer102-act") 1045 | || !strcmp(layerName, "layer101-act") 1046 | || !strcmp(layerName, "layer100-act") 1047 | || !strcmp(layerName, "layer99-act") 1048 | || !strcmp(layerName, "layer96-act") 1049 | || !strcmp(layerName, "layer92-act") 1050 | || !strcmp(layerName, "layer91-act") 1051 | || !strcmp(layerName, "layer90-act") 1052 | || !strcmp(layerName, "layer89-act") 1053 | || !strcmp(layerName, "layer88-act") 1054 | || !strcmp(layerName, "layer87-act") 1055 | || !strcmp(layerName, "layer84-act") 1056 | || !strcmp(layerName, "layer80-act") 1057 | || !strcmp(layerName, "layer79-act") 1058 | || !strcmp(layerName, "layer78-act") 1059 | 1060 | 1061 | 1062 | || !strcmp(layerName, "layer77-act") 1063 | || !strcmp(layerName, "layer76-act") 1064 | || !strcmp(layerName, "layer75-act") 1065 | || !strcmp(layerName, "layer73-act") 1066 | || !strcmp(layerName, "layer72-act") 1067 | || !strcmp(layerName, "layer70-act") 1068 | || !strcmp(layerName, "layer69-act") 1069 | || !strcmp(layerName, "layer67-act") 1070 | || !strcmp(layerName, "layer66-act") 1071 | || !strcmp(layerName, "layer64-act") 1072 | || !strcmp(layerName, "layer63-act") 1073 | || !strcmp(layerName, "layer62-act") 1074 | || !strcmp(layerName, "layer60-act") 1075 | || !strcmp(layerName, "layer59-act") 1076 | || !strcmp(layerName, "layer57-act") 1077 | || !strcmp(layerName, "layer56-act") 1078 | || !strcmp(layerName, "layer54-act") 1079 | || !strcmp(layerName, "layer53-act") 1080 | // 1081 | 1082 | || !strcmp(layerName, "layer51-act") 1083 | || !strcmp(layerName, "layer50-act") 1084 | || !strcmp(layerName, "layer48-act") 1085 | || !strcmp(layerName, "layer47-act") 1086 | || !strcmp(layerName, "layer45-act") 1087 | || !strcmp(layerName, "layer44-act") 1088 | || !strcmp(layerName, "layer42-act") 1089 | || !strcmp(layerName, "layer41-act") 1090 | || !strcmp(layerName, "layer39-act") 1091 | || !strcmp(layerName, "layer38-act") 1092 | || !strcmp(layerName, "layer37-act") 1093 | || !strcmp(layerName, "layer35-act") 1094 | || !strcmp(layerName, "layer34-act") 1095 | || !strcmp(layerName, "layer32-act") 1096 | || !strcmp(layerName, "layer31-act") 1097 | || !strcmp(layerName, "layer29-act") 1098 | || !strcmp(layerName, "layer26-act") 1099 | || !strcmp(layerName, "layer25-act") 1100 | 1101 | 1102 | 1103 | || !strcmp(layerName, "layer23-act") 1104 | || !strcmp(layerName, "layer22-act") 1105 | || !strcmp(layerName, "layer20-act") 1106 | || !strcmp(layerName, "layer19-act") 1107 | || !strcmp(layerName, "layer17-act") 1108 | || !strcmp(layerName, "layer16-act") 1109 | || !strcmp(layerName, "layer14-act") 1110 | || !strcmp(layerName, "layer13-act") 1111 | || !strcmp(layerName, "layer12-act") 1112 | || !strcmp(layerName, "layer10-act") 1113 | || !strcmp(layerName, "layer9-act") 1114 | || !strcmp(layerName, "layer7-act") 1115 | || !strcmp(layerName, "layer6-act") 1116 | || !strcmp(layerName, "layer5-act") 1117 | || !strcmp(layerName, "layer3-act") 1118 | ){ 1119 | 1120 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new LReluLayer(0.1)); 1121 | return _nvPlugins.at(layerName); 1122 | 1123 | 1124 | }else{ 1125 | assert(0); 1126 | return nullptr; 1127 | } 1128 | } 1129 | 1130 | // deserialization plugin implementation 1131 | IPlugin* createPlugin(const char* layerName, const void* serialData, size_t serialLength) override { 1132 | if(!strcmp(layerName, "conv4_3_norm")) 1133 | { 1134 | _nvPlugins[layerName] = plugin::createSSDNormalizePlugin(serialData, serialLength); 1135 | return _nvPlugins.at(layerName); 1136 | 1137 | }else if( !strcmp(layerName, "conv11_mbox_loc_perm") 1138 | || !strcmp(layerName, "conv11_mbox_conf_perm") 1139 | || !strcmp(layerName, "conv13_mbox_loc_perm") 1140 | || !strcmp(layerName,"conv13_mbox_conf_perm") 1141 | || !strcmp(layerName,"conv14_2_mbox_loc_perm") 1142 | || !strcmp(layerName,"conv14_2_mbox_conf_perm") 1143 | || !strcmp(layerName,"conv15_2_mbox_loc_perm") 1144 | || !strcmp(layerName,"conv15_2_mbox_conf_perm") 1145 | || !strcmp(layerName,"conv16_2_mbox_loc_perm") 1146 | || !strcmp(layerName,"conv16_2_mbox_conf_perm") 1147 | || !strcmp(layerName,"conv17_2_mbox_loc_perm") 1148 | || !strcmp(layerName,"conv17_2_mbox_conf_perm") 1149 | ){ 1150 | _nvPlugins[layerName] = plugin::createSSDPermutePlugin(serialData, serialLength); 1151 | return _nvPlugins.at(layerName); 1152 | 1153 | 1154 | }else if(!strcmp(layerName,"conv11_mbox_priorbox") 1155 | || !strcmp(layerName,"conv13_mbox_priorbox") 1156 | || !strcmp(layerName,"conv14_2_mbox_priorbox") 1157 | || !strcmp(layerName,"conv15_2_mbox_priorbox") 1158 | || !strcmp(layerName,"conv16_2_mbox_priorbox") 1159 | || !strcmp(layerName,"conv17_2_mbox_priorbox") 1160 | ){ 1161 | _nvPlugins[layerName] = plugin::createSSDPriorBoxPlugin (serialData, serialLength); 1162 | return _nvPlugins.at(layerName); 1163 | 1164 | }else if(!strcmp(layerName,"detection_out")){ 1165 | _nvPlugins[layerName] = plugin::createSSDDetectionOutputPlugin (serialData, serialLength); 1166 | return _nvPlugins.at(layerName); 1167 | }else if(!strcmp(layerName,"mbox_conf_reshape")){ 1168 | _nvPlugins[layerName] = (plugin::INvPlugin*)new Reshape<21>(serialData, serialLength); 1169 | return _nvPlugins.at(layerName); 1170 | }else if ( 1171 | !strcmp(layerName, "conv11_mbox_conf_flat") 1172 | ||!strcmp(layerName,"conv11_mbox_loc_flat") 1173 | ||!strcmp(layerName,"conv13_mbox_loc_flat") 1174 | ||!strcmp(layerName,"conv13_mbox_conf_flat") 1175 | ||!strcmp(layerName,"conv14_2_mbox_loc_flat") 1176 | ||!strcmp(layerName,"conv14_2_mbox_conf_flat") 1177 | ||!strcmp(layerName,"conv15_2_mbox_loc_flat") 1178 | ||!strcmp(layerName,"conv15_2_mbox_conf_flat") 1179 | ||!strcmp(layerName,"conv16_2_mbox_loc_flat") 1180 | ||!strcmp(layerName,"conv16_2_mbox_conf_flat") 1181 | ||!strcmp(layerName,"conv17_2_mbox_loc_flat") 1182 | ||!strcmp(layerName,"conv17_2_mbox_conf_flat") 1183 | ||!strcmp(layerName,"mbox_conf_flatten") 1184 | ){ 1185 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new FlattenLayer(serialData, serialLength)); 1186 | return _nvPlugins.at(layerName); 1187 | }else if(!strcmp(layerName,"mbox_loc")){ 1188 | _nvPlugins[layerName] = plugin::createConcatPlugin (serialData, serialLength); 1189 | return _nvPlugins.at(layerName); 1190 | }else if(!strcmp(layerName,"mbox_conf")){ 1191 | _nvPlugins[layerName] = plugin::createConcatPlugin (serialData, serialLength); 1192 | return _nvPlugins.at(layerName); 1193 | }else if(!strcmp(layerName,"mbox_priorbox")){ 1194 | _nvPlugins[layerName] = plugin::createConcatPlugin (serialData, serialLength); 1195 | return _nvPlugins.at(layerName); 1196 | }else if(!strcmp(layerName, "mbox_conf_softmax")) 1197 | { 1198 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new SofaMaxChannelLayer(2,serialData, serialLength)); 1199 | return _nvPlugins.at(layerName); 1200 | }else if(!strcmp(layerName, "layer85-upsample")) 1201 | { 1202 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new UpsampleLayer(serialData, serialLength,2)); 1203 | return _nvPlugins.at(layerName); 1204 | 1205 | 1206 | 1207 | }else if(!strcmp(layerName, "layer97-upsample")) 1208 | { 1209 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new UpsampleLayer(serialData, serialLength,2)); 1210 | return _nvPlugins.at(layerName); 1211 | 1212 | 1213 | }else if ( !strcmp(layerName, "layer2-act") 1214 | || !strcmp(layerName, "layer1-act") 1215 | || !strcmp(layerName, "layer104-act") 1216 | || !strcmp(layerName, "layer0-act") 1217 | || !strcmp(layerName, "layer28-act") 1218 | || !strcmp(layerName, "layer103-act") 1219 | || !strcmp(layerName, "layer102-act") 1220 | || !strcmp(layerName, "layer101-act") 1221 | || !strcmp(layerName, "layer100-act") 1222 | || !strcmp(layerName, "layer99-act") 1223 | || !strcmp(layerName, "layer96-act") 1224 | || !strcmp(layerName, "layer92-act") 1225 | || !strcmp(layerName, "layer91-act") 1226 | || !strcmp(layerName, "layer90-act") 1227 | || !strcmp(layerName, "layer89-act") 1228 | || !strcmp(layerName, "layer88-act") 1229 | || !strcmp(layerName, "layer87-act") 1230 | || !strcmp(layerName, "layer84-act") 1231 | || !strcmp(layerName, "layer80-act") 1232 | || !strcmp(layerName, "layer79-act") 1233 | || !strcmp(layerName, "layer78-act") 1234 | 1235 | 1236 | 1237 | || !strcmp(layerName, "layer77-act") 1238 | || !strcmp(layerName, "layer76-act") 1239 | || !strcmp(layerName, "layer75-act") 1240 | || !strcmp(layerName, "layer73-act") 1241 | || !strcmp(layerName, "layer72-act") 1242 | || !strcmp(layerName, "layer70-act") 1243 | || !strcmp(layerName, "layer69-act") 1244 | || !strcmp(layerName, "layer67-act") 1245 | || !strcmp(layerName, "layer66-act") 1246 | || !strcmp(layerName, "layer64-act") 1247 | || !strcmp(layerName, "layer63-act") 1248 | || !strcmp(layerName, "layer62-act") 1249 | || !strcmp(layerName, "layer60-act") 1250 | || !strcmp(layerName, "layer59-act") 1251 | || !strcmp(layerName, "layer57-act") 1252 | || !strcmp(layerName, "layer56-act") 1253 | || !strcmp(layerName, "layer54-act") 1254 | || !strcmp(layerName, "layer53-act") 1255 | // 1256 | 1257 | || !strcmp(layerName, "layer51-act") 1258 | || !strcmp(layerName, "layer50-act") 1259 | || !strcmp(layerName, "layer48-act") 1260 | || !strcmp(layerName, "layer47-act") 1261 | || !strcmp(layerName, "layer45-act") 1262 | || !strcmp(layerName, "layer44-act") 1263 | || !strcmp(layerName, "layer42-act") 1264 | || !strcmp(layerName, "layer41-act") 1265 | || !strcmp(layerName, "layer39-act") 1266 | || !strcmp(layerName, "layer38-act") 1267 | || !strcmp(layerName, "layer37-act") 1268 | || !strcmp(layerName, "layer35-act") 1269 | || !strcmp(layerName, "layer34-act") 1270 | || !strcmp(layerName, "layer32-act") 1271 | || !strcmp(layerName, "layer31-act") 1272 | || !strcmp(layerName, "layer29-act") 1273 | || !strcmp(layerName, "layer26-act") 1274 | || !strcmp(layerName, "layer25-act") 1275 | 1276 | 1277 | 1278 | || !strcmp(layerName, "layer23-act") 1279 | || !strcmp(layerName, "layer22-act") 1280 | || !strcmp(layerName, "layer20-act") 1281 | || !strcmp(layerName, "layer19-act") 1282 | || !strcmp(layerName, "layer17-act") 1283 | || !strcmp(layerName, "layer16-act") 1284 | || !strcmp(layerName, "layer14-act") 1285 | || !strcmp(layerName, "layer13-act") 1286 | || !strcmp(layerName, "layer12-act") 1287 | || !strcmp(layerName, "layer10-act") 1288 | || !strcmp(layerName, "layer9-act") 1289 | || !strcmp(layerName, "layer7-act") 1290 | || !strcmp(layerName, "layer6-act") 1291 | || !strcmp(layerName, "layer5-act") 1292 | || !strcmp(layerName, "layer3-act") 1293 | ){ 1294 | 1295 | _nvPlugins[layerName] = (plugin::INvPlugin*)(new LReluLayer(serialData, serialLength,0.1)); 1296 | return _nvPlugins.at(layerName); 1297 | 1298 | 1299 | }else{ 1300 | assert(0); 1301 | return nullptr; 1302 | } 1303 | } 1304 | 1305 | void destroyPlugin() 1306 | { 1307 | for (auto it=_nvPlugins.begin(); it!=_nvPlugins.end(); ++it){ 1308 | std::cout<first<second->destroy(); 1310 | _nvPlugins.erase(it); 1311 | } 1312 | } 1313 | 1314 | 1315 | private: 1316 | 1317 | std::map _nvPlugins; 1318 | }; 1319 | 1320 | 1321 | 1322 | #endif 1323 | 1324 | --------------------------------------------------------------------------------