You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose we have a network with (not all distinct) layer names
layer
layer_1
layer
When ImporterContext sees "layer", it sees it's not in mLayerNameCounts,
and sets mLayerNameCounts["layer"] = 1 and adds a TRT layer with name "layer".
It then sees "layer_1", concludes it's not in mLayerNameCounts, so it sets
mLayerNameCounts["layer_1"] = 1 and adds a TRT layer with name "layer_1".
NOW when it sees "layer", it sees that mLayerNameCounts["layer"] == 1,
so we produce a "uniqueName" of
"layer" + "_" + std::to_string(mLayerNameCounts["layer"] ), ie "layer_1",
which is a name conflict for the TRT net.
This change keeps track of all inserted names in a set and in the case of
duplicates, tries suffix-appended modifications of the duplicated name
by ever increasing integers until a name appears which has not been used.
Copy file name to clipboardExpand all lines: ImporterContext.hpp
+36-17Lines changed: 36 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -26,11 +26,12 @@
26
26
#include"onnx2trt_utils.hpp"
27
27
28
28
#include<list>
29
+
#include<set>
30
+
#include<string>
29
31
#include<unordered_map>
30
32
31
33
namespaceonnx2trt
32
34
{
33
-
34
35
classImporterContextfinal : public IImporterContext
35
36
{
36
37
nvinfer1::INetworkDefinition* _network;
@@ -44,13 +45,17 @@ class ImporterContext final : public IImporterContext
44
45
StringMap<float> mTensorRangeMins;
45
46
StringMap<float> mTensorRangeMaxes;
46
47
StringMap<nvinfer1::DataType> mLayerPrecisions;
47
-
StringMap<size_t>
48
-
mTensorNameCounts; // Keep track of how many times a tensor name shows up, to avoid duplicate naming in TRT.
49
-
StringMap<size_t>
50
-
mLayerNameCounts; // Keep track of how many times a tensor name shows up, to avoid duplicate naming in TRT.
51
-
std::unordered_set<std::string> mUnsupportedShapeTensors; // Container to hold output tensor names of layers that produce shape tensor outputs but do not natively support them.
52
-
StringMap<std::string> mLoopTensors; // Container to map subgraph tensors to their original outer graph names.
53
-
std::string mOnnxFileLocation; // Keep track of the directory of the parsed ONNX file
48
+
std::set<std::string> mTensorNames; // keep track of tensor names used so far,
49
+
// to avoid duplicate naming in TRT.
50
+
std::set<std::string> mLayerNames; // keep track of layer names used so far,
51
+
// to avoid duplicate naming in TRT.
52
+
int64_tmSuffixCounter = 0; // increasing suffix counter used to uniquify layer names.
53
+
std::unordered_set<std::string> mUnsupportedShapeTensors; // Container to hold any shape tensors that are
54
+
// the output of layers that do not support
55
+
// shape tensors.
56
+
StringMap<std::string> mLoopTensors; // Container to map subgraph tensors to
57
+
// their original outer graph names.
58
+
std::string mOnnxFileLocation; // Keep track of the directory of the parsed ONNX file
0 commit comments