├── LICENSE ├── README.md ├── beautify.py └── figure ├── example.png └── tf_example.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Ching-Yao Chuang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tensorboard2Seaborn 🌈 2 | Plot Tensorflow event in a beautiful way (using seaborn actually) instead of using Tensorboard. Currently this repo will plot all the scalars store by ```tf.summary()```. 3 | 4 | 5 | ## Requirement 6 | - Tensorflow 7 | - python 2.7 8 | - matplotlib 9 | - seaborn 10 | 11 | ## Usage 12 | Read and plot tf event 13 | 14 | ``` 15 | python beautify.py --logdir=./logdir --smooth=100 --color=#4169E1 16 | ``` 17 | - **logdir**: logdir to event file 18 | - **smooth**: step size for average smoothing 19 | - **color**: pick a color you like :) 20 | 21 | ## Example 22 | ### After 23 | 24 | 25 | ### Before 26 | 27 | 28 | ## Reference 29 | - [Tensorboard](https://www.tensorflow.org/get_started/summaries_and_tensorboard) 30 | -------------------------------------------------------------------------------- /beautify.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import tensorflow as tf 3 | from tensorflow.python.summary import event_accumulator as ea 4 | 5 | from matplotlib import pyplot as plt 6 | from matplotlib import colors as colors 7 | import seaborn as sns 8 | sns.set(style="darkgrid") 9 | sns.set_context("paper") 10 | 11 | def plot(params): 12 | ''' beautify tf log 13 | Use better library (seaborn) to plot tf event file''' 14 | 15 | log_path = params['logdir'] 16 | smooth_space = params['smooth'] 17 | color_code = params['color'] 18 | 19 | acc = ea.EventAccumulator(log_path) 20 | acc.Reload() 21 | 22 | # only support scalar now 23 | scalar_list = acc.Tags()['scalars'] 24 | 25 | x_list = [] 26 | y_list = [] 27 | x_list_raw = [] 28 | y_list_raw = [] 29 | for tag in scalar_list: 30 | x = [int(s.step) for s in acc.Scalars(tag)] 31 | y = [s.value for s in acc.Scalars(tag)] 32 | 33 | # smooth curve 34 | x_ = [] 35 | y_ = [] 36 | for i in range(0, len(x), smooth_space): 37 | x_.append(x[i]) 38 | y_.append(sum(y[i:i+smooth_space]) / float(smooth_space)) 39 | x_.append(x[-1]) 40 | y_.append(y[-1]) 41 | x_list.append(x_) 42 | y_list.append(y_) 43 | 44 | # raw curve 45 | x_list_raw.append(x) 46 | y_list_raw.append(y) 47 | 48 | 49 | for i in range(len(x_list)): 50 | plt.figure(i) 51 | plt.subplot(111) 52 | plt.title(scalar_list[i]) 53 | plt.plot(x_list_raw[i], y_list_raw[i], color=colors.to_rgba(color_code, alpha=0.4)) 54 | plt.plot(x_list[i], y_list[i], color=color_code, linewidth=1.5) 55 | plt.show() 56 | 57 | 58 | if __name__ == '__main__': 59 | 60 | parser = argparse.ArgumentParser() 61 | parser.add_argument('--logdir', default='./logdir', type=str, help='logdir to event file') 62 | parser.add_argument('--smooth', default=100, type=float, help='window size for average smoothing') 63 | parser.add_argument('--color', default='#4169E1', type=str, help='HTML code for the figure') 64 | 65 | args = parser.parse_args() 66 | params = vars(args) # convert to ordinary dict 67 | 68 | plot(params) 69 | -------------------------------------------------------------------------------- /figure/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chingyaoc/Tensorboard2Seaborn/18f36f995fe68615a8ff0ff481f50a3a40645b3c/figure/example.png -------------------------------------------------------------------------------- /figure/tf_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chingyaoc/Tensorboard2Seaborn/18f36f995fe68615a8ff0ff481f50a3a40645b3c/figure/tf_example.png --------------------------------------------------------------------------------