1 Star 0 Fork 0

snowingbear/onnx-tensorrt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
OnnxAttrs.hpp 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
Sheng Zha 提交于 2021-05-14 02:31 +08:00 . relicense to Apache License v2 (#657)
/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <NvInfer.h>
#include <onnx/onnx_pb.h>
#include <unordered_map>
#include <vector>
#include "ImporterContext.hpp"
class OnnxAttrs
{
template <typename T>
using string_map = std::unordered_map<std::string, T>;
typedef string_map<::ONNX_NAMESPACE::AttributeProto const*> AttrMap;
AttrMap _attrs;
onnx2trt::IImporterContext* mCtx;
public:
explicit OnnxAttrs(::ONNX_NAMESPACE::NodeProto const& onnx_node, onnx2trt::IImporterContext* ctx)
: mCtx{ctx}
{
for (auto const& attr : onnx_node.attribute())
{
_attrs.insert({attr.name(), &attr});
}
}
bool count(const std::string& key) const
{
return _attrs.count(key);
}
::ONNX_NAMESPACE::AttributeProto const* at(std::string key) const
{
if (!_attrs.count(key))
{
throw std::out_of_range("Attribute not found: " + key);
}
return _attrs.at(key);
}
::ONNX_NAMESPACE::AttributeProto::AttributeType type(const std::string& key) const
{
return this->at(key)->type();
}
template <typename T>
T get(const std::string& key) const;
template <typename T>
T get(const std::string& key, T const& default_value) const
{
return _attrs.count(key) ? this->get<T>(key) : default_value;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/snowingbear/onnx-tensorrt.git
git@gitee.com:snowingbear/onnx-tensorrt.git
snowingbear
onnx-tensorrt
onnx-tensorrt
main

搜索帮助