def add_mpl_plot(self, tag, fig, global_step): if self.__show_mpl: import matplotlib.pyplot as plt plt.show() else: from PIL import Image import io fig.canvas.draw() pil_image = Image.frombytes('RGB', fig.canvas.get_width_height(), fig.canvas.tostring_rgb()) output = io.BytesIO() pil_image.save(output, format='PNG') pil_image_string = output.getvalue() output.close() img_summary = Summary.Image(height=pil_image.height, width=pil_image.width, colorspace=3, encoded_image_string=pil_image_string) summary = Summary( value=[Summary.Value(tag=_clean_tag(tag), image=img_summary)]) self.file_writer.add_summary(summary, global_step=global_step)
def add_scalar(self, tag, value, step): summary = Summary(value=[Summary.Value(tag=tag, simple_value=value)]) self.summary_writer.add_summary(summary, global_step=step)
def scalar_summary( self, tag, value, step ): ##to save various summary(tag: action, train-loss,valreward,actor,critic obtained in trainer_rl_typeloss file summary = Summary(value=[Summary.Value(tag=tag, simple_value=value)]) self.summary_writer.add_summary(summary, global_step=step)
def histogram(name, values, bins, collections=None): name = _clean_tag(name) values = make_np(values) hist = make_histogram(values.astype(float), bins) return Summary(value=[Summary.Value(tag=name, histo=hist)])
def counter(name, counter_dict): name = _clean_tag(name) hist = make_histogram_from_counter(counter_dict) return Summary(value=[Summary.Value(tag=name, histo=hist)])
def _to_image_summary_safe(tag, tensor): tag = _clean_tag(tag) img = make_image_summary(to_image(tensor)) return Summary(value=[Summary.Value(tag=tag, image=img)])