博客
关于我
TensorRT/parsers/caffe/caffeParser/caffeParser.h源碼研讀
阅读量:289 次
发布时间:2019-03-03

本文共 5496 字,大约阅读时间需要 18 分钟。

TensorRT/parsers/caffe/caffeParser/caffeParser.h源碼研讀

前言

caffeParser.h中宣告了CaffeParser這個類別。其具體實作則位於 caffeParser.cpp

因為caffeParser.cpp內容較多,它的介紹共分為:

, , , 等幾篇。

TensorRT/parsers/caffe/caffeParser/caffeParser.h

/* * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#ifndef TRT_CAFFE_PARSER_CAFFE_PARSER_H#define TRT_CAFFE_PARSER_CAFFE_PARSER_H#include 
#include
#include
#include
#include "NvCaffeParser.h"#include "caffeWeightFactory.h"#include "blobNameToTensor.h"#include "trtcaffe.pb.h"namespace nvcaffeparser1{ //繼承自TensorRT/include/NvCaffeParser.h裡的抽象類別ICaffeParser//ICafferParser裡宣告的都是virtual function,在這個ICafferParser的子類別中會賦予它們具體的定義class CaffeParser : public ICaffeParser{ public: const IBlobNameToTensor* parse(const char* deploy, const char* model, nvinfer1::INetworkDefinition& network, nvinfer1::DataType weightType) override; const IBlobNameToTensor* parseBuffers(const char* deployBuffer, size_t deployLength, const char* modelBuffer, size_t modelLength, nvinfer1::INetworkDefinition& network, nvinfer1::DataType weightType) override; void setProtobufBufferSize(size_t size) override { mProtobufBufferSize = size; } void setPluginFactory(nvcaffeparser1::IPluginFactory* factory) override { mPluginFactory = factory; } void setPluginFactoryExt(nvcaffeparser1::IPluginFactoryExt* factory) override { mPluginFactory = factory; mPluginFactoryIsExt = true; } void setPluginFactoryV2(nvcaffeparser1::IPluginFactoryV2* factory) override { mPluginFactoryV2 = factory; } void setPluginNamespace(const char* libNamespace) override { mPluginNamespace = libNamespace; } IBinaryProtoBlob* parseBinaryProto(const char* fileName) override; void destroy() override { delete this; } //以下二函數override ICaffeParser中的函數,但未實做 //(void)recorder的作用是? void setErrorRecorder(nvinfer1::IErrorRecorder* recorder) override { (void)recorder; assert(!"TRT- Not implemented."); } nvinfer1::IErrorRecorder* getErrorRecorder() const override { assert(!"TRT- Not implemented."); return nullptr; }private: ~CaffeParser() override; /* 以下五個函數的作用都是將trtcaffe::LayerParameter裡的資料 整理成std::vector
的格式後回傳 */ std::vector
parseNormalizeParam(const trtcaffe::LayerParameter& msg, CaffeWeightFactory& weightFactory, BlobNameToTensor& tensors); std::vector
parsePriorBoxParam(const trtcaffe::LayerParameter& msg, CaffeWeightFactory& weightFactory, BlobNameToTensor& tensors); std::vector
parseDetectionOutputParam(const trtcaffe::LayerParameter& msg, CaffeWeightFactory& weightFactory, BlobNameToTensor& tensors); std::vector
parseLReLUParam(const trtcaffe::LayerParameter& msg, CaffeWeightFactory& weightFactory, BlobNameToTensor& tensors); std::vector
parseRPROIParam(const trtcaffe::LayerParameter& msg, CaffeWeightFactory& weightFactory, BlobNameToTensor& tensors); //分配size(默認為1)大小的T型別的空間,然後放到mTmpAllocs裡集中管理 template
T* allocMemory(int size = 1) { T* tmpMem = static_cast
(malloc(sizeof(T) * size)); mTmpAllocs.push_back(tmpMem); return tmpMem; } const IBlobNameToTensor* parse(nvinfer1::INetworkDefinition& network, nvinfer1::DataType weightType, bool hasModel);private: //用於表示模型架構 std::shared_ptr
mDeploy; //用於儲存模型權重 std::shared_ptr
mModel; /* 為CaffeWeightFactory所用, 用於記錄分配或轉換權重時,使用malloc新申請的記憶體 */ std::vector
mTmpAllocs; /* BlobNameToTensor 定義於TensorRT/parsers/caffe/blobNameToTensor.h 其核心為mMap這個字典,用於把blob name對應到ITensor* */ BlobNameToTensor* mBlobNameToTensor{ nullptr}; /* 為TensorRT/parsers/caffe/caffeParser/readProto.h中的函數readBinaryProto所用, 表示stream讀取的最大byte數 */ size_t mProtobufBufferSize{ INT_MAX}; /* nvcaffeparser1::IPluginFactory 定義於TensorRT/include/NvCaffeParser.h Plugin factory used to configure plugins. */ nvcaffeparser1::IPluginFactory* mPluginFactory{ nullptr}; /* nvcaffeparser1::IPluginFactoryV2 定義於TensorRT/include/NvCaffeParser.h Plugin factory used to configure plugins. */ nvcaffeparser1::IPluginFactoryV2* mPluginFactoryV2{ nullptr}; bool mPluginFactoryIsExt{ false}; //用於存放nvinfer1::IPluginV2的向量 std::vector
mNewPlugins; //用於儲存的plugin名稱對應到nvinfer1::IPluginCreator*字典 std::unordered_map
mPluginRegistry; //作為nvcaffeparser1::IPluginFactoryV2::createPlugin函數的參數使用 std::string mPluginNamespace = "";};} //namespace nvcaffeparser1#endif //TRT_CAFFE_PARSER_CAFFE_PARSER_H

delete this

destroy函數的內容是delete this,詳見。

std::unordered_map

caffeParser.h中宣告了CaffeParser類別,其中有一個成員mPluginRegistrystd::unordered_map型別的:

std::unordered_map
mPluginRegistry;

std::map內部的元素會依其key被排序; 而std::unordered_map則沒有。如果要隨機存取一個元素,使用std::unordered_map的速度會比較快。

參考連結

转载地址:http://bltm.baihongyu.com/

你可能感兴趣的文章
2021年车工(高级)考试总结及车工(高级)试题及答案
查看>>
2021年压力焊证考试及压力焊实操考试视频
查看>>
2021年低压电工考试及低压电工考试申请表
查看>>
2021年低压电工考试及低压电工考试申请表
查看>>
2021年A特种设备相关管理(电梯)考试APP及A特种设备相关管理(电梯)复审考试
查看>>
2021年美容师(初级)考试报名及美容师(初级)新版试题
查看>>
2021年N1叉车司机考试题及N1叉车司机复审模拟考试
查看>>
2021年危险化学品经营单位主要负责人考试APP及危险化学品经营单位主要负责人多少钱
查看>>
2021年T电梯修理考试技巧及T电梯修理模拟考试软件
查看>>
2021年电工(初级)考试及电工(初级)证考试
查看>>
2021年安全员-B证-项目负责人(广东省)新版试题及安全员-B证-项目负责人(广东省)考试试卷
查看>>
2021年安全员-A证-主要负责人(广东省)复审考试及安全员-A证-主要负责人(广东省)操作证考试
查看>>
2021年G1工业锅炉司炉考试报名及G1工业锅炉司炉模拟考试题库
查看>>
大数据学习之Spark——00Spark项目的pom.xml文件
查看>>
大数据学习之Spark——01Spark概述
查看>>
从 MFC 移植程序到 wxWidgets 界面库 ——《定时执行专家 5.0》的界面实现
查看>>
CodeBlocks开发wxWidgets环境配置详细
查看>>
wxSqlite3 和 wxPropertyGrid 类库的说明
查看>>
天涯人脉通讯录 - 设计草图
查看>>
wxWidgets 最新版2.8.11,终于放出来了
查看>>