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

Function plot_logs

TEACh/utils/plot_utils.py:167–220  ·  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

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

Callers

nothing calls this directly

Calls 1

printFunction · 0.70

Tested by

no test coverage detected