MCPcopy Create free account
hub / github.com/TorchSSL/TorchSSL / _plot_stats

Method _plot_stats

custom_writer.py:100–133  ·  view source on GitHub ↗
(self, keys: Sequence[str], key2: str)

Source from the content-addressed store, hash-verified

98 plt.savefig(p)
99
100 def _plot_stats(self, keys: Sequence[str], key2: str):
101 # str is also Sequence[str]
102 if isinstance(keys, str):
103 raise TypeError(f"Input as [{keys}]")
104
105 import matplotlib
106
107 matplotlib.use("agg")
108 import matplotlib.pyplot as plt
109 import matplotlib.ticker as ticker
110
111 plt.clf()
112
113 epochs = sorted(list(self.stats.keys()))
114 for key in keys:
115 y = [
116 self.stats[e][key][key2]
117 if e in self.stats
118 and key in self.stats[e]
119 and key2 in self.stats[e][key]
120 else np.nan
121 for e in epochs
122 ]
123 assert len(epochs) == len(y), "Bug?"
124
125 plt.plot(epochs, y, label=key2, marker="x")
126 plt.legend()
127 plt.title(f"iteration vs {key2}")
128 # Force integer tick for x-axis
129 plt.gca().get_xaxis().set_major_locator(ticker.MaxNLocator(integer=True))
130 plt.xlabel("iteration")
131 plt.ylabel(key2)
132 plt.grid()
133 return plt
134
135 def to_numpy(self, a):
136 if isinstance(a, list):

Callers 1

matplotlib_plotMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected