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

本文深入探讨TensorRT中BinaryProtoBlob类的实现细节,该类继承自IBinaryProtoBlob,用于存储和查询从Caffe的binaryproto文件中提取的数据,包括数据类型和维度等元数据。文章解析了BinaryProtoBlob的构造函数、数据获取、类型和维度查询以及销毁方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TensorRT/parsers/caffe/binaryProtoBlob.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_BINARY_PROTO_BLOB_H
#define TRT_CAFFE_PARSER_BINARY_PROTO_BLOB_H
#include <stdlib.h>

#include "NvCaffeParser.h"
#include "NvInfer.h"

namespace nvcaffeparser1
{
/*
class IBinaryProtoBlob
宣告於TensorRT/include/NvCaffeParser.h
class IBinaryProtoBlob
{
public:
    virtual const void* getData() TRTNOEXCEPT = 0;
    virtual nvinfer1::DimsNCHW getDimensions() TRTNOEXCEPT = 0;
    virtual nvinfer1::DataType getDataType() TRTNOEXCEPT = 0;
    virtual void destroy() TRTNOEXCEPT = 0;

protected:
    virtual ~IBinaryProtoBlob() {}
};
Object used to store and query data extracted from a binaryproto file using the ICaffeParser.
用於儲存及查詢binaryproto檔裡抽取出來的數據
warning Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
*/
/*
BinaryProtoBlob繼承自IBinaryProtoBlob,
用於儲存及查詢binaryproto檔裡抽取出來的數據,
並記錄它的metadata,如型別及維度。
*/
class BinaryProtoBlob : public IBinaryProtoBlob
{
public:
    BinaryProtoBlob(void* memory, nvinfer1::DataType type, nvinfer1::DimsNCHW dimensions)
        : mMemory(memory)
        , mDataType(type)
        , mDimensions(dimensions)
    {
    }

    nvinfer1::DimsNCHW getDimensions() override
    {
        return mDimensions;
    }

    nvinfer1::DataType getDataType() override
    {
        return mDataType;
    }

    const void* getData() override
    {
        return mMemory;
    }

    //為何除了destructor還要定義這個函數?
    void destroy() override
    {
        delete this;
    }

    ~BinaryProtoBlob() override
    {
        free(mMemory);
    }

    void* mMemory;
    nvinfer1::DataType mDataType;
    nvinfer1::DimsNCHW mDimensions;
};
} // namespace nvcaffeparser1
#endif // TRT_CAFFE_PARSER_BINARY_PROTO_BLOB_H

BinaryProtoBlob繼承自IBinaryProtoBlob,用於儲存及查詢binaryproto檔裡抽取出來的數據,並記錄它的metadata,如型別及維度。

繼承IBinaryProtoBlob

IBinaryProtoBlob裡的註釋寫說不要繼承該類別,但BinaryProtoBlob卻繼承了?

delete this

destroy中用到了delete this,詳見C++ delete this

參考連結

C++ delete this

raceback (most recent call last): File "pandas/_libs/parsers.pyx", line 1119, in pandas._libs.parsers.TextReader._convert_tokens File "pandas/_libs/parsers.pyx", line 1244, in pandas._libs.parsers.TextReader._convert_with_dtype File "pandas/_libs/parsers.pyx", line 1259, in pandas._libs.parsers.TextReader._string_convert File "pandas/_libs/parsers.pyx", line 1450, in pandas._libs.parsers._string_box_utf8 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 0: invalid continuation byte During handling of the above exception, another exception occurred: Traceback (most recent call last): File "4.1-stu.py", line 8, in <module> master=pd.read_csv('Training_Master.csv') File "/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py", line 688, in read_csv return _read(filepath_or_buffer, kwds) File "/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py", line 460, in _read data = parser.read(nrows) File "/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py", line 1198, in read ret = self._engine.read(nrows) File "/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py", line 2157, in read data = self._reader.read(nrows) File "pandas/_libs/parsers.pyx", line 847, in pandas._libs.parsers.TextReader.read File "pandas/_libs/parsers.pyx", line 862, in pandas._libs.parsers.TextReader._read_low_memory File "pandas/_libs/parsers.pyx", line 941, in pandas._libs.parsers.TextReader._read_rows File "pandas/_libs/parsers.pyx", line 1073, in pandas._libs.parsers.TextReader._convert_column_data File "pandas/_libs/parsers.pyx", line 1126, in pandas._libs.parsers.TextReader._convert_tokens File "pandas/_libs/parsers.pyx", line 1244, in pandas._libs.parsers.TextReader._convert_with_dtype File "pandas/_libs/parsers.pyx", line 1259, in pandas._libs.parsers.TextReader._string_convert File "pandas/_libs/parsers.pyx", line 1450, in pandas._libs.parsers._string_box_utf8 UnicodeDecodeError: 'utf-8' codec
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值