MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / HashStringToColor

Function HashStringToColor

tensorflow/lite/toco/dump_graphviz.cc:99–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97};
98
99Color HashStringToColor(string s) {
100 // Return a unique color for a name.
101 //
102 // This function removes Tensorflow anti-collision suffixes (eg "_2"), hashes
103 // the string to a uint_32, then twiddles some bits to get a light and subtle
104 // color. This seems to be a good heuristic for keeping enough of the name to
105 // hash to a unique color while still revealing structure through naming
106 // similarities.
107 //
108 // The regular expression "_\d+" matches any underscore followed by numbers,
109 // which we strip out. Examples:
110 //
111 // "Conv" -> "Conv"
112 // "Conv_2" -> "Conv"
113 // "Conv_72" -> "Conv"
114 // "Pad_1_bias -> "Pad_bias"
115 // "Conv_abc" -> "Conv_abc"
116
117 RE2::GlobalReplace(&s, R"CODE(_\d+)CODE", "");
118 uint32 color_word = std::hash<std::string>{}(s);
119 color_word |= 0x00E0E0E0;
120 return Color(color_word);
121}
122
123void GetArrayColorAndShape(const Model& model, const string& array_name,
124 Color* color, string* shape) {

Callers 1

DumpSubgraphHeaderFunction · 0.85

Calls 1

ColorClass · 0.85

Tested by

no test coverage detected