MCPcopy Create free account
hub / github.com/Gabesarch/ICAL / plot_logs

Function plot_logs

TEACh/SOLQ/util/plot_utils.py:160–213  ·  view source on GitHub ↗

Function to plot specific fields from training log(s). Plots both training and test results. :: Inputs - logs = list containing Path objects, each pointing to individual dir with a log file - fields = which results to plot from each log file - plots both training and test for

(logs, fields=('class_error', 'loss_bbox_unscaled', 'mAP'), ewm_col=0, log_name='log.txt')

Source from the content-addressed store, hash-verified

158
159
160def plot_logs(logs, fields=('class_error', 'loss_bbox_unscaled', 'mAP'), ewm_col=0, log_name='log.txt'):
161 '''
162 Function to plot specific fields from training log(s). Plots both training and test results.
163
164 :: Inputs - logs = list containing Path objects, each pointing to individual dir with a log file
165 - fields = which results to plot from each log file - plots both training and test for each field.
166 - ewm_col = optional, which column to use as the exponential weighted smoothing of the plots
167 - log_name = optional, name of log file if different than default 'log.txt'.
168
169 :: Outputs - matplotlib plots of results in fields, color coded for each log file.
170 - solid lines are training results, dashed lines are test results.
171
172 '''
173 func_name = "plot_utils.py::plot_logs"
174
175 # verify logs is a list of Paths (list[Paths]) or single Pathlib object Path,
176 # convert single Path to list to avoid 'not iterable' error
177
178 if not isinstance(logs, list):
179 if isinstance(logs, PurePath):
180 logs = [logs]
181 print(f"{func_name} info: logs param expects a list argument, converted to list[Path].")
182 else:
183 raise ValueError(f"{func_name} - invalid argument for logs parameter.\n \
184 Expect list[Path] or single Path obj, received {type(logs)}")
185
186 # verify valid dir(s) and that every item in list is Path object
187 for i, dir in enumerate(logs):
188 if not isinstance(dir, PurePath):
189 raise ValueError(f"{func_name} - non-Path object in logs argument of {type(dir)}: \n{dir}")
190 if dir.exists():
191 continue
192 raise ValueError(f"{func_name} - invalid directory in logs argument:\n{dir}")
193
194 # load log file(s) and plot
195 dfs = [pd.read_json(Path(p) / log_name, lines=True) for p in logs]
196
197 fig, axs = plt.subplots(ncols=len(fields), figsize=(16, 5))
198
199 for df, color in zip(dfs, sns.color_palette(n_colors=len(logs))):
200 for j, field in enumerate(fields):
201 if field == 'mAP':
202 coco_eval = pd.DataFrame(pd.np.stack(df.test_coco_eval.dropna().values)[:, 1]).ewm(com=ewm_col).mean()
203 axs[j].plot(coco_eval, c=color)
204 else:
205 df.interpolate().ewm(com=ewm_col).mean().plot(
206 y=[f'train_{field}', f'test_{field}'],
207 ax=axs[j],
208 color=[color] * 2,
209 style=['-', '--']
210 )
211 for ax, field in zip(axs, fields):
212 ax.legend([Path(p).name for p in logs])
213 ax.set_title(field)
214
215
216def plot_precision_recall(files, naming_scheme='iter'):

Callers

nothing calls this directly

Calls 1

printFunction · 0.70

Tested by

no test coverage detected