Skip to content

Commit

Permalink
write summary table for numerical stats
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 8, 2021
1 parent a02a7ff commit e6abc5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions neural_monitor/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Dict,
Any
)
import pandas as pd

try:
import visdom
Expand Down Expand Up @@ -1157,13 +1158,19 @@ def hist(self, name, value: Union[T.Tensor, np.ndarray], n_bins: int = 20, lates
self.writer.add_histogram(prefix + name.replace(' ', '-'), value, global_step=self.iter, **kwargs)

def _plot(self, nums, prints):
summary = pd.DataFrame()
fig = plt.figure()
plt.xlabel('iteration')
for name, val in list(nums.items()):
smooth = self._options[name].get('smooth')
filter_outliers = self._options[name].get('filter_outliers')
prec = self._options[name].get('precision')

# csv summary
tmp = pd.DataFrame(val.values(), index=val.keys(), columns=[name], dtype='float32')
summary = summary.join(tmp, how='outer')

# plot
self._num_since_beginning[name].update(val)
plt.ylabel(name)
x_vals = sorted(self._num_since_beginning[name].keys())
Expand All @@ -1188,6 +1195,9 @@ def _plot(self, nums, prints):
fig.savefig(os.path.join(self.plot_folder, name.replace(' ', '_') + '.jpg'))
fig.clear()
plt.close()
csv_file = os.path.join(self.current_folder, 'summary.csv')
summary.sort_index() # makes sure the rows are in chronological order
summary.to_csv(csv_file, mode='a', header=True if not os.path.exists(csv_file) else False)

def _plot_matrix(self, mats):
fig = plt.figure()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ matplotlib <= 3.1.0
tensorboard
imageio
git-python
pandas

0 comments on commit e6abc5e

Please sign in to comment.