# Path: tensorboardX/summary.py
# def compute_curve(labels, predictions, num_thresholds=None, weights=None):
#     _MINIMUM_COUNT = 1e-7
# 
#     if weights is None:
#         weights = 1.0
# 
#     # Compute bins of true positives and false positives.
#     bucket_indices = np.int32(np.floor(predictions * (num_thresholds - 1)))
#     float_labels = labels.astype(float)
#     histogram_range = (0, num_thresholds - 1)
#     tp_buckets, _ = np.histogram(
#         bucket_indices,
#         bins=num_thresholds,
#         range=histogram_range,
#         weights=float_labels * weights)
#     fp_buckets, _ = np.histogram(
#         bucket_indices,
#         bins=num_thresholds,
#         range=histogram_range,
#         weights=(1.0 - float_labels) * weights)
# 
#     # Obtain the reverse cumulative sum.
#     tp = np.cumsum(tp_buckets[::-1])[::-1]
#     fp = np.cumsum(fp_buckets[::-1])[::-1]
#     tn = fp[0] - fp
#     fn = tp[0] - tp
#     precision = tp / np.maximum(_MINIMUM_COUNT, tp + fp)
#     recall = tp / np.maximum(_MINIMUM_COUNT, tp + fn)
#     return np.stack((tp, fp, tn, fn, precision, recall))
# 
# Path: tensorboardX/utils.py
# def figure_to_image(figures, close=True):
#     """Render matplotlib figure to numpy format.
# 
#     Note that this requires the ``matplotlib`` package.
# 
#     Args:
#         figure (matplotlib.pyplot.figure) or list of figures: figure or a list of figures
#         close (bool): Flag to automatically close the figure
# 
#     Returns:
#         numpy.array: image in [CHW] order
#     """
#     import numpy as np
#     try:
#         import matplotlib.pyplot as plt
#         import matplotlib.backends.backend_agg as plt_backend_agg
#     except ModuleNotFoundError:
#         print('please install matplotlib')
# 
#     def render_to_rgb(figure):
#         canvas = plt_backend_agg.FigureCanvasAgg(figure)
#         canvas.draw()
#         data = np.frombuffer(canvas.buffer_rgba(), dtype=np.uint8)
#         w, h = figure.canvas.get_width_height()
#         image_hwc = data.reshape([h, w, 4])[:, :, 0:3]
#         image_chw = np.moveaxis(image_hwc, source=2, destination=0)
#         if close:
#             plt.close(figure)
#         return image_chw
# 
#     if isinstance(figures, list):
#         images = [render_to_rgb(figure) for figure in figures]
#         return np.stack(images)
#     else:
#         image = render_to_rgb(figures)
#         return image
# 
# Path: tensorboardX/x2num.py
# def make_np(x):
#     if isinstance(x, list):
#         return check_nan(np.array(x))
#     if isinstance(x, np.ndarray):
#         return check_nan(x)
#     if isinstance(x, six.string_types):  # Caffe2 will pass name of blob(s) to fetch
#         return check_nan(prepare_caffe2(x))
#     if np.isscalar(x):
#         return check_nan(np.array([x]))
#     if 'torch' in str(type(x)):
#         return check_nan(prepare_pytorch(x))
#     if 'chainer' in str(type(x)):
#         return check_nan(prepare_chainer(x))
#     if 'mxnet' in str(type(x)):
#         return check_nan(prepare_mxnet(x))
#     if 'jax' in str(type(x)):
#         return check_nan(np.array(x))
#     raise NotImplementedError(
#         'Got {}, but expected numpy array or torch tensor.'.format(type(x)))


import gc
import numpy as np
import math
import json
import time
                    import torch
from .summary import compute_curve
from .utils import figure_to_image
from .x2num import make_np
            from visdom import Visdom
                'run_14h-arctanx'
            with the corresponding values.
        """
        for key in tag_scalar_dict.keys():
            self.add_scalar(key, tag_scalar_dict[key], global_step, main_tag)

    @_check_connection
    def export_scalars_to_json(self, path):
        """Exports to the given 'path' an ASCII file containing all the scalars written
        so far by this instance, with the following format:
        {writer_id : [[timestamp, step, value], ...], ...}

        The scalars saved by ``add_scalars()`` will be flushed after export.
        """
        with open(path, "w") as f:
            json.dump(self.scalar_dict, f)
        self.scalar_dict = {}

    @_check_connection
    def add_histogram(self, tag, values, global_step=None, bins='tensorflow'):
        """Add histogram to summary.

        Args:
            tag (string): Data identifier
            values (torch.Tensor, numpy.array, or string/blobname): Values to build histogram
            global_step (int): Global step value to record
            bins (string): one of {'tensorflow', 'auto', 'fd', ...}, this determines how the bins are made. You can find
              other options in: https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html
        """
        values = make_np(values)

# Path: tensorboardX/summary.py
# def compute_curve(labels, predictions, num_thresholds=None, weights=None):
#     _MINIMUM_COUNT = 1e-7
# 
#     if weights is None:
#         weights = 1.0
# 
#     # Compute bins of true positives and false positives.
#     bucket_indices = np.int32(np.floor(predictions * (num_thresholds - 1)))
#     float_labels = labels.astype(float)
#     histogram_range = (0, num_thresholds - 1)
#     tp_buckets, _ = np.histogram(
#         bucket_indices,
#         bins=num_thresholds,
#         range=histogram_range,
#         weights=float_labels * weights)
#     fp_buckets, _ = np.histogram(
#         bucket_indices,
#         bins=num_thresholds,
#         range=histogram_range,
#         weights=(1.0 - float_labels) * weights)
# 
#     # Obtain the reverse cumulative sum.
#     tp = np.cumsum(tp_buckets[::-1])[::-1]
#     fp = np.cumsum(fp_buckets[::-1])[::-1]
#     tn = fp[0] - fp
#     fn = tp[0] - tp
#     precision = tp / np.maximum(_MINIMUM_COUNT, tp + fp)
#     recall = tp / np.maximum(_MINIMUM_COUNT, tp + fn)
#     return np.stack((tp, fp, tn, fn, precision, recall))
# 
# Path: tensorboardX/utils.py
# def figure_to_image(figures, close=True):
#     """Render matplotlib figure to numpy format.
# 
#     Note that this requires the ``matplotlib`` package.
# 
#     Args:
#         figure (matplotlib.pyplot.figure) or list of figures: figure or a list of figures
#         close (bool): Flag to automatically close the figure
# 
#     Returns:
#         numpy.array: image in [CHW] order
#     """
#     import numpy as np
#     try:
#         import matplotlib.pyplot as plt
#         import matplotlib.backends.backend_agg as plt_backend_agg
#     except ModuleNotFoundError:
#         print('please install matplotlib')
# 
#     def render_to_rgb(figure):
#         canvas = plt_backend_agg.FigureCanvasAgg(figure)
#         canvas.draw()
#         data = np.frombuffer(canvas.buffer_rgba(), dtype=np.uint8)
#         w, h = figure.canvas.get_width_height()
#         image_hwc = data.reshape([h, w, 4])[:, :, 0:3]
#         image_chw = np.moveaxis(image_hwc, source=2, destination=0)
#         if close:
#             plt.close(figure)
#         return image_chw
# 
#     if isinstance(figures, list):
#         images = [render_to_rgb(figure) for figure in figures]
#         return np.stack(images)
#     else:
#         image = render_to_rgb(figures)
#         return image
# 
# Path: tensorboardX/x2num.py
# def make_np(x):
#     if isinstance(x, list):
#         return check_nan(np.array(x))
#     if isinstance(x, np.ndarray):
#         return check_nan(x)
#     if isinstance(x, six.string_types):  # Caffe2 will pass name of blob(s) to fetch
#         return check_nan(prepare_caffe2(x))
#     if np.isscalar(x):
#         return check_nan(np.array([x]))
#     if 'torch' in str(type(x)):
#         return check_nan(prepare_pytorch(x))
#     if 'chainer' in str(type(x)):
#         return check_nan(prepare_chainer(x))
#     if 'mxnet' in str(type(x)):
#         return check_nan(prepare_mxnet(x))
#     if 'jax' in str(type(x)):
#         return check_nan(np.array(x))
#     raise NotImplementedError(
#         'Got {}, but expected numpy array or torch tensor.'.format(type(x)))


# Path: tensorboardX/visdom_writer.py
import gc
import numpy as np
import math
import json
import time
                    import torch
from .summary import compute_curve
from .utils import figure_to_image
from .x2num import make_np
            from visdom import Visdom

                'run_14h-arctanx'
            with the corresponding values.
        """
        for key in tag_scalar_dict.keys():
            self.add_scalar(key, tag_scalar_dict[key], global_step, main_tag)

    @_check_connection
    def export_scalars_to_json(self, path):
        """Exports to the given 'path' an ASCII file containing all the scalars written
        so far by this instance, with the following format:
        {writer_id : [[timestamp, step, value], ...], ...}

        The scalars saved by ``add_scalars()`` will be flushed after export.
        """
        with open(path, "w") as f:
            json.dump(self.scalar_dict, f)
        self.scalar_dict = {}

    @_check_connection
    def add_histogram(self, tag, values, global_step=None, bins='tensorflow'):
        """Add histogram to summary.

        Args:
            tag (string): Data identifier
            values (torch.Tensor, numpy.array, or string/blobname): Values to build histogram
            global_step (int): Global step value to record
            bins (string): one of {'tensorflow', 'auto', 'fd', ...}, this determines how the bins are made. You can find
              other options in: https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html
        """
        values = make_np(values)

        self.vis.histogram(make_np(values), opts={'title': tag})