| 97 | }; |
| 98 | |
| 99 | Color 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 | |
| 123 | void GetArrayColorAndShape(const Model& model, const string& array_name, |
| 124 | Color* color, string* shape) { |
no test coverage detected