/usr/local/lib64/python3.6/site-packages/torch/utils/tensorboard/__pycache__
NameSizeModeActions
summary.cpython-36.pyc221990644editdlrm
writer.cpython-36.pyc426680644editdlrm
_caffe2_graph.cpython-36.pyc249570644editdlrm
_convert_np.cpython-36.pyc11470644editdlrm
_embedding.cpython-36.pyc32000644editdlrm
_onnx_graph.cpython-36.pyc18870644editdlrm
_proto_graph.cpython-36.pyc18550644editdlrm
_pytorch_graph.cpython-36.pyc100520644editdlrm
_utils.cpython-36.pyc43090644editdlrm
__init__.cpython-36.pyc5700644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/utils/tensorboard/__pycache__/writer.cpython-36.pyc (42668B)
3 Eg@sdZddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZd d lmZd d lmZmZmZmZmZd d lmZd d lmZd dlmZd dlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*Gddde+Z,Gddde+Z-dS)zlProvides an API for writing protocol buffers to event files to be consumed by TensorBoard for visualization.N)tf) SessionLog)Event) event_pb2)ProjectorConfig)EventFileWriter)make_np)make_mat make_spritemake_tsv write_pbtxtget_embedding_info)load_onnx_graph)graph)figure_to_image) scalar histogram histogram_rawimageaudiotextpr_curve pr_curve_rawvideocustom_scalars image_boxesmeshhparamsc@sbeZdZdZdddZddZdd d Zdd d ZdddZdddZ ddZ ddZ ddZ d S) FileWriteraWrites protocol buffers to event files to be consumed by TensorBoard. The `FileWriter` class provides a mechanism to create an event file in a given directory and add summaries and events to it. The class updates the file contents asynchronously. This allows a training program to call methods to add data to the file directly from the training loop, without slowing down training. xcCst|}t|||||_dS)agCreates a `FileWriter` and an event file. On construction the writer creates a new event file in `log_dir`. The other arguments to the constructor control the asynchronous writes to the event file. Args: log_dir: A string. Directory where event file will be written. max_queue: Integer. Size of the queue for pending events and summaries before one of the 'add' calls forces a flush to disk. Default is ten items. flush_secs: Number. How often, in seconds, to flush the pending events and summaries to disk. Default is every two minutes. filename_suffix: A string. Suffix added to all event filenames in the log_dir directory. More details on filename construction in tensorboard.summary.writer.event_file_writer.EventFileWriter. N)strr event_writer)selflog_dir max_queue flush_secsfilename_suffixr*J/usr/local/lib64/python3.6/site-packages/torch/utils/tensorboard/writer.py__init__&szFileWriter.__init__cCs |jjS)z7Returns the directory where event file will be written.)r$ get_logdir)r%r*r*r+r-?szFileWriter.get_logdirNcCs8|dkrtjn||_|dk r(t||_|jj|dS)a]Adds an event to the event file. Args: event: An `Event` protocol buffer. step: Number. Optional global step value for training process to record with the event. walltime: float. Optional walltime to override the default (current) walltime (from time.time()) seconds after epoch N)timeZ wall_timeintstepr$ add_event)r%eventr0walltimer*r*r+r1Cs  zFileWriter.add_eventcCstj|d}|j|||dS)aAdds a `Summary` protocol buffer to the event file. This method wraps the provided summary in an `Event` protocol buffer and adds it to the event file. Args: summary: A `Summary` protocol buffer. global_step: Number. Optional global step value for training process to record with the summary. walltime: float. Optional walltime to override the default (current) walltime (from time.time()) seconds after epoch )summaryN)rrr1)r%r4 global_stepr3r2r*r*r+ add_summarySs zFileWriter.add_summarycCs^|d}|d}tj|jd}|j|d|tjd|jd}tj|d}|j|d|dS)a&Adds a `Graph` and step stats protocol buffer to the event file. Args: graph_profile: A `Graph` and step stats protocol buffer. walltime: float. Optional walltime to override the default (current) walltime (from time.time()) seconds after epoch rr) graph_defNZstep1)tagZ run_metadata)Ztagged_run_metadata)rrSerializeToStringr1ZTaggedRunMetadata)r%Z graph_profiler3rZ stepstatsr2Ztrmr*r*r+ add_graphbs zFileWriter.add_graphcCs"tj|jd}|j|d|dS)zAdds a `Graph` protocol buffer to the event file. Args: graph: A `Graph` protocol buffer. walltime: float. Optional walltime to override the default (current) _get_file_writerfrom time.time()) )r7N)rrr9r1)r%rr3r2r*r*r+add_onnx_graphtszFileWriter.add_onnx_graphcCs|jjdS)zFlushes the event file to disk. Call this method to make sure that all pending events have been written to disk. N)r$flush)r%r*r*r+r<szFileWriter.flushcCs|jjdS)zFlushes the event file to disk and close the file. Call this method when you do not need the summary writer anymore. N)r$close)r%r*r*r+r=szFileWriter.closecCs|jjdS)zReopens the EventFileWriter. Can be called after `close()` to add more events in the same directory. The events will go into a new events file. Does nothing if the EventFileWriter was not closed. N)r$reopen)r%r*r*r+r>szFileWriter.reopen)r r!r")NN)NN)N)N) __name__ __module__ __qualname____doc__r,r-r1r6r:r;r<r=r>r*r*r*r+rs     rc@s,eZdZdZdMddZdd Zd d Zd d ZdNddZdOddZ dPddZ dQddZ dRddZ dSddZ dTddZdUd!d"ZdVd$d%ZdWd'd(ZdXd*d+ZdYd,d-Zd.d/ZdZd0d1Zed2d3Zd[d5d6Zd\d8d9Zd]d:d;Zd^d=d>Zd_d?d@ZdAdBZd`dCdDZdEdFZdGdHZ dIdJZ!dKdLZ"dS)a SummaryWriteraWrites entries directly to event files in the log_dir to be consumed by TensorBoard. The `SummaryWriter` class provides a high-level API to create an event file in a given directory and add summaries and events to it. The class updates the file contents asynchronously. This allows a training program to call methods to add data to the file directly from the training loop, without slowing down training. Nr"r r!c Cstjjd|sPddl}ddlm}|jjd} tjj d| d|j |}||_ ||_ ||_ ||_||_d|_|_|jd} g} g} x*| d kr| j| | j| | d 9} qW| ddd dg| |_dS) aCreates a `SummaryWriter` that will write out events and summaries to the event file. Args: log_dir (string): Save directory location. Default is runs/**CURRENT_DATETIME_HOSTNAME**, which changes after each run. Use hierarchical folder structure to compare between runs easily. e.g. pass in 'runs/exp1', 'runs/exp2', etc. for each new experiment to compare across them. comment (string): Comment log_dir suffix appended to the default ``log_dir``. If ``log_dir`` is assigned, this argument has no effect. purge_step (int): When logging crashes at step :math:`T+X` and restarts at step :math:`T`, any events whose global_step larger or equal to :math:`T` will be purged and hidden from TensorBoard. Note that crashed and resumed experiments should have the same ``log_dir``. max_queue (int): Size of the queue for pending events and summaries before one of the 'add' calls forces a flush to disk. Default is ten items. flush_secs (int): How often, in seconds, to flush the pending events and summaries to disk. Default is every two minutes. filename_suffix (string): Suffix added to all event filenames in the log_dir directory. More details on filename construction in tensorboard.summary.writer.event_file_writer.EventFileWriter. Examples:: from torch.utils.tensorboard import SummaryWriter # create a summary writer with automatically generated folder name. writer = SummaryWriter() # folder location: runs/May04_22-14-54_s-MacBook-Pro.local/ # create a summary writer using the specified folder name. writer = SummaryWriter("my_experiment") # folder location: my_experiment # create a summary writer with comment appended. writer = SummaryWriter(comment="LR_0.1_BATCH_16") # folder location: runs/May04_22-14-54_s-MacBook-Pro.localLR_0.1_BATCH_16/ z tensorboard.create.summarywriterrN)datetimez %b%d_%H-%M-%Sruns_g-q=g@xDg?r)torch_C_log_api_usage_oncesocketrDnowstrftimeospathjoin gethostnamer& purge_stepr'r(r) file_writer all_writers_get_file_writerappend default_bins) r%r&commentrRr'r(r)rKrD current_timevZbucketsZ neg_bucketsr*r*r+r,s,,       zSummaryWriter.__init__cCs t|tS)ag Caffe2 users have the option of passing a string representing the name of a blob in the workspace instead of passing the actual Tensor/array containing the numeric values. Thus, we need to check if we received a string as input instead of an actual Tensor/array, and if so, we need to fetch the Blob from the workspace corresponding to that name. Fetching can be done with the following: from caffe2.python import workspace (if not already imported) workspace.FetchBlob(blob_name) workspace.FetchBlobs([blob_name1, blob_name2, ...]) ) isinstancer#)r%itemr*r*r+_check_caffe2_blobs z SummaryWriter._check_caffe2_blobcCs|jdks|jdkrt|j|j|j|j|_|jj|ji|_|jdk r|j}|jj t |dd|jj t |t t j ddd|_|jS)z@Returns the default FileWriter instance. Recreates it if closed.Nz brain.Event:2)r0Z file_version)status)r0Z session_log) rTrSrr&r'r(r)r-rRr1rrSTART)r%Zmost_recent_stepr*r*r+rUs  zSummaryWriter._get_file_writercCs|jS)z8Returns the directory where event files will be written.)r&)r%r*r*r+r-szSummaryWriter.get_logdirc Cstjjdt|tk s$t|tk r,tdt|||\}}}|sNttj}t j j |j j |}t|dL} | jj|| jj|| jj|x |jD]\} } | j| | qWWdQRXdS)aAdd a set of hyperparameters to be compared in TensorBoard. Args: hparam_dict (dict): Each key-value pair in the dictionary is the name of the hyper parameter and it's corresponding value. The type of the value can be one of `bool`, `string`, `float`, `int`, or `None`. metric_dict (dict): Each key-value pair in the dictionary is the name of the metric and it's corresponding value. Note that the key used here should be unique in the tensorboard record. Otherwise the value you added by ``add_scalar`` will be displayed in hparam plugin. In most cases, this is unwanted. hparam_domain_discrete: (Optional[Dict[str, List[Any]]]) A dictionary that contains names of the hyperparameters and all discrete values they can hold run_name (str): Name of the run, to be included as part of the logdir. If unspecified, will use current timestamp. Examples:: from torch.utils.tensorboard import SummaryWriter with SummaryWriter() as w: for i in range(5): w.add_hparams({'lr': 0.1*i, 'bsize': i}, {'hparam/accuracy': 10*i, 'hparam/loss': 10*i}) Expected result: .. image:: _static/img/tensorboard/add_hparam.png :scale: 50 % ztensorboard.logging.add_hparamsz1hparam_dict and metric_dict should be dictionary.)r&N)rHrIrJtypedict TypeErrorrr#r.rNrOrPrUr-rCrSr6items add_scalar) r%Z hparam_dictZ metric_dictZhparam_domain_discreteZrun_nameexpZssiZseiZlogdirZw_hpkrZr*r*r+ add_hparams s"      zSummaryWriter.add_hparamsFc CsRtjjd|j|r,ddlm}|j|}t||||d}|jj |||dS)ahAdd scalar data to summary. Args: tag (string): Data identifier scalar_value (float or string/blobname): Value to save global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) with seconds after epoch of event new_style (boolean): Whether to use new style (tensor field) or old style (simple_value field). New style could lead to faster data loading. Examples:: from torch.utils.tensorboard import SummaryWriter writer = SummaryWriter() x = range(100) for i in x: writer.add_scalar('y=2x', i * 2, i) writer.close() Expected result: .. image:: _static/img/tensorboard/add_scalar.png :scale: 50 % ztensorboard.logging.add_scalarr) workspace) new_styledouble_precisionN) rHrIrJr] caffe2.pythonrh FetchBlobrrUr6) r%r8 scalar_valuer5r3rirjrhr4r*r*r+rd;s"    zSummaryWriter.add_scalarc Cstjjd|dkrtjn|}|jj}x|jD]\}}|d|jddd|}|jdk sht ||jj kr|j|} nt ||j |j |j} | |j|<|j|rddlm} | j|}| jt||||q6WdS)aAdds many scalar data to summary. Args: main_tag (string): The parent name for the tags tag_scalar_dict (dict): Key-value pair storing the tag and corresponding values global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Examples:: from torch.utils.tensorboard import SummaryWriter writer = SummaryWriter() r = 5 for i in range(100): writer.add_scalars('run_14h', {'xsinx':i*np.sin(i/r), 'xcosx':i*np.cos(i/r), 'tanx': np.tan(i/r)}, i) writer.close() # This call adds three values to the same scalar plot with the tag # 'run_14h' in TensorBoard's scalar section. Expected result: .. image:: _static/img/tensorboard/add_scalars.png :scale: 50 % ztensorboard.logging.add_scalarsN/rFr)rh)rHrIrJr.rUr-rcreplacerTAssertionErrorkeysrr'r(r)r]rkrhrlr6r) r%Zmain_tagZtag_scalar_dictr5r3Z fw_logdirr8rmZfw_tagfwrhr*r*r+ add_scalarsgs          zSummaryWriter.add_scalars tensorflowcCsftjjd|j|r,ddlm}|j|}t|trD|dkrD|j }|j j t ||||d||dS)aAdd 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 walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Examples:: from torch.utils.tensorboard import SummaryWriter import numpy as np writer = SummaryWriter() for i in range(10): x = np.random.random(1000) writer.add_histogram('distribution centers', x + i, i) writer.close() Expected result: .. image:: _static/img/tensorboard/add_histogram.png :scale: 50 % z!tensorboard.logging.add_histogramr)rhrt)max_binsN) rHrIrJr]rkrhrlr[r#rWrUr6r)r%r8valuesr5Zbinsr3rurhr*r*r+ add_histograms    zSummaryWriter.add_histogramc CsLtjjdt|t|kr$td|jjt||||||||| | dS)aAdds histogram with raw data. Args: tag (string): Data identifier min (float or int): Min value max (float or int): Max value num (int): Number of values sum (float or int): Sum of all values sum_squares (float or int): Sum of squares for all values bucket_limits (torch.Tensor, numpy.array): Upper value per bucket. The number of elements of it should be the same as `bucket_counts`. bucket_counts (torch.Tensor, numpy.array): Number of values per bucket global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) seconds after epoch of event see: https://github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/histogram/README.md Examples:: from torch.utils.tensorboard import SummaryWriter import numpy as np writer = SummaryWriter() dummy_data = [] for idx, value in enumerate(range(50)): dummy_data += [idx + 0.001] * value bins = list(range(50+2)) bins = np.array(bins) values = np.array(dummy_data).astype(float).reshape(-1) counts, limits = np.histogram(values, bins=bins) sum_sq = values.dot(values) writer.add_histogram_raw( tag='histogram_with_raw_data', min=values.min(), max=values.max(), num=len(values), sum=values.sum(), sum_squares=sum_sq, bucket_limits=limits[1:].tolist(), bucket_counts=counts.tolist(), global_step=0) writer.close() Expected result: .. image:: _static/img/tensorboard/add_histogram_raw.png :scale: 50 % z%tensorboard.logging.add_histogram_rawz;len(bucket_limits) != len(bucket_counts), see the document.N)rHrIrJlen ValueErrorrUr6r) r%r8minmaxnumsumZ sum_squaresZ bucket_limitsZ bucket_countsr5r3r*r*r+add_histogram_raws4 zSummaryWriter.add_histogram_rawCHWcCsLtjjd|j|r,ddlm}|j|}|jjt |||d||dS)aAdd image data to summary. Note that this requires the ``pillow`` package. Args: tag (string): Data identifier img_tensor (torch.Tensor, numpy.array, or string/blobname): Image data global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Shape: img_tensor: Default is :math:`(3, H, W)`. You can use ``torchvision.utils.make_grid()`` to convert a batch of tensor into 3xHxW format or call ``add_images`` and let us do the job. Tensor with :math:`(1, H, W)`, :math:`(H, W)`, :math:`(H, W, 3)` is also suitable as long as corresponding ``dataformats`` argument is passed, e.g. ``CHW``, ``HWC``, ``HW``. Examples:: from torch.utils.tensorboard import SummaryWriter import numpy as np img = np.zeros((3, 100, 100)) img[0] = np.arange(0, 10000).reshape(100, 100) / 10000 img[1] = 1 - np.arange(0, 10000).reshape(100, 100) / 10000 img_HWC = np.zeros((100, 100, 3)) img_HWC[:, :, 0] = np.arange(0, 10000).reshape(100, 100) / 10000 img_HWC[:, :, 1] = 1 - np.arange(0, 10000).reshape(100, 100) / 10000 writer = SummaryWriter() writer.add_image('my_image', img, 0) # If you have non-default dimension setting, set the dataformats argument. writer.add_image('my_image_HWC', img_HWC, 0, dataformats='HWC') writer.close() Expected result: .. image:: _static/img/tensorboard/add_image.png :scale: 50 % ztensorboard.logging.add_imager)rh) dataformatsN) rHrIrJr]rkrhrlrUr6r)r%r8 img_tensorr5r3rrhr*r*r+ add_images *    zSummaryWriter.add_imageNCHWcCsLtjjd|j|r,ddlm}|j|}|jjt |||d||dS)a6Add batched image data to summary. Note that this requires the ``pillow`` package. Args: tag (string): Data identifier img_tensor (torch.Tensor, numpy.array, or string/blobname): Image data global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) seconds after epoch of event dataformats (string): Image data format specification of the form NCHW, NHWC, CHW, HWC, HW, WH, etc. Shape: img_tensor: Default is :math:`(N, 3, H, W)`. If ``dataformats`` is specified, other shape will be accepted. e.g. NCHW or NHWC. Examples:: from torch.utils.tensorboard import SummaryWriter import numpy as np img_batch = np.zeros((16, 3, 100, 100)) for i in range(16): img_batch[i, 0] = np.arange(0, 10000).reshape(100, 100) / 10000 / 16 * i img_batch[i, 1] = (1 - np.arange(0, 10000).reshape(100, 100) / 10000) / 16 * i writer = SummaryWriter() writer.add_images('my_image_batch', img_batch, 0) writer.close() Expected result: .. image:: _static/img/tensorboard/add_images.png :scale: 30 % ztensorboard.logging.add_imagesr)rh)rN) rHrIrJr]rkrhrlrUr6r)r%r8rr5r3rrhr*r*r+ add_images/s %    zSummaryWriter.add_imagesrc Cstjjd|j|r,ddlm} | j|}|j|rLddlm} | j|}|dk rzt|trd|g}t ||j dkrzd}|j j t ||||||d||dS)auAdd image and draw bounding boxes on the image. Args: tag (string): Data identifier img_tensor (torch.Tensor, numpy.array, or string/blobname): Image data box_tensor (torch.Tensor, numpy.array, or string/blobname): Box data (for detected objects) box should be represented as [x1, y1, x2, y2]. global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) seconds after epoch of event rescale (float): Optional scale override dataformats (string): Image data format specification of the form NCHW, NHWC, CHW, HWC, HW, WH, etc. labels (list of string): The label to be shown for each bounding box. Shape: img_tensor: Default is :math:`(3, H, W)`. It can be specified with ``dataformats`` argument. e.g. CHW or HWC box_tensor: (torch.Tensor, numpy.array, or string/blobname): NX4, where N is the number of boxes and each 4 elements in a row represents (xmin, ymin, xmax, ymax). z(tensorboard.logging.add_image_with_boxesr)rhN)rescalerlabels)rHrIrJr]rkrhrlr[r#rxshaperUr6r) r%r8rZ box_tensorr5r3rrrrhr*r*r+add_image_with_boxes[s         z"SummaryWriter.add_image_with_boxesTcCsPtjjdt|tr2|j|t||||ddn|j|t||||dddS)aRender matplotlib figure into an image and add it to summary. Note that this requires the ``matplotlib`` package. Args: tag (string): Data identifier figure (matplotlib.pyplot.figure) or list of figures: Figure or a list of figures global_step (int): Global step value to record close (bool): Flag to automatically close the figure walltime (float): Optional override default walltime (time.time()) seconds after epoch of event ztensorboard.logging.add_figurer)rrN)rHrIrJr[listrr)r%r8figurer5r=r3r*r*r+ add_figures  zSummaryWriter.add_figurecCs*tjjd|jjt|||||dS)a>Add video data to summary. Note that this requires the ``moviepy`` package. Args: tag (string): Data identifier vid_tensor (torch.Tensor): Video data global_step (int): Global step value to record fps (float or int): Frames per second walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Shape: vid_tensor: :math:`(N, T, C, H, W)`. The values should lie in [0, 255] for type `uint8` or [0, 1] for type `float`. ztensorboard.logging.add_videoN)rHrIrJrUr6r)r%r8Z vid_tensorr5Zfpsr3r*r*r+ add_videos zSummaryWriter.add_videoDcCsLtjjd|j|r,ddlm}|j|}|jjt |||d||dS)aAdd audio data to summary. Args: tag (string): Data identifier snd_tensor (torch.Tensor): Sound data global_step (int): Global step value to record sample_rate (int): sample rate in Hz walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Shape: snd_tensor: :math:`(1, L)`. The values should lie between [-1, 1]. ztensorboard.logging.add_audior)rh) sample_rateN) rHrIrJr]rkrhrlrUr6r)r%r8Z snd_tensorr5rr3rhr*r*r+ add_audios    zSummaryWriter.add_audiocCs(tjjd|jjt||||dS)aAdd text data to summary. Args: tag (string): Data identifier text_string (string): String to save global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Examples:: writer.add_text('lstm', 'This is an lstm', 0) writer.add_text('rnn', 'This is an rnn', 10) ztensorboard.logging.add_textN)rHrIrJrUr6r)r%r8Z text_stringr5r3r*r*r+add_texts zSummaryWriter.add_textcCs"tjjd|jjt|dS)Nz"tensorboard.logging.add_onnx_graph)rHrIrJrUr;r)r%Zprototxtr*r*r+r;s zSummaryWriter.add_onnx_graphc Cstjjdt|dr0|jjt||||nddlm}ddl m }ddl m }m }m} t|trt|d|jr||} qt|d|jr| |} n||} tj| jd} |jj| d S) a Add graph data to summary. Args: model (torch.nn.Module): Model to draw. input_to_model (torch.Tensor or list of torch.Tensor): A variable or a tuple of variables to be fed. verbose (bool): Whether to print graph structure in console. use_strict_trace (bool): Whether to pass keyword argument `strict` to `torch.jit.trace`. Pass False when you want the tracer to record your mutable container types (list, dict) ztensorboard.logging.add_graphZforwardr) caffe2_pb2)corer)model_to_graph_defnets_to_graph_defprotos_to_graph_def)r7N)rHrIrJhasattrrUr:rZ caffe2.protorrkrZ _caffe2_graphrrrr[rZNetZNetDefrrr9r1) r%modelZinput_to_modelverboseZuse_strict_tracerrrrrZ current_graphr2r*r*r+r:s        zSummaryWriter.add_graphcCsD|}|jddtd}|jddtd}|jddtd}|S)N%z%%%02xrn\)roord)Zrawstrretvalr*r*r+_encodes zSummaryWriter._encodedefaultc Csvtjjdt|}|dkr d}dt|jd|j|f}tjj |j j |}t j jj|} | j|r| j|r~tdqtd|n | j||dk r|jdt|kstdt|||d |dk r|jd|jdkstd t|||jd kstd t||t|d s&t|_t||| |||} |jj j!| gddl"m#} | j$|j} t%|j j | dS)aAdd embedding projector data to summary. Args: mat (torch.Tensor or numpy.array): A matrix which each row is the feature vector of the data point metadata (list): A list of labels, each element will be convert to string label_img (torch.Tensor): Images correspond to each data point global_step (int): Global step value to record tag (string): Name for the embedding Shape: mat: :math:`(N, D)`, where N is number of data and D is feature dimension label_img: :math:`(N, C, H, W)` Examples:: import keyword import torch meta = [] while len(meta)<100: meta = meta+keyword.kwlist # get some strings meta = meta[:100] for i, v in enumerate(meta): meta[i] = v+str(i) label_img = torch.rand(100, 3, 10, 32) for i in range(100): label_img[i]*=i/100.0 writer.add_embedding(torch.randn(100, 5), metadata=meta, label_img=label_img) writer.add_embedding(torch.randn(100, 5), label_img=label_img) writer.add_embedding(torch.randn(100, 5), metadata=meta) z!tensorboard.logging.add_embeddingNrz%s/%szKwarning: Embedding dir exists, did you set global_step for add_embedding()?z1Path: `%s` exists, but is a file. Cannot proceed.z&#labels should equal with #data points)metadata_headerz&#images should equal with #data pointsz@mat should be 2D, where mat.size(0) is the number of data points_projector_config) text_format)&rHrIrJr r#zfillrrNrOrPrUr-rioZgfileZget_filesystemexistsisdirprint Exceptionmakedirsrrxrpr r ndimr rrrrZ embeddingsextendZgoogle.protobufrZMessageToStringr ) r%matmetadataZ label_imgr5r8rsubdirZ save_pathfsZembedding_inforZ config_pbtxtr*r*r+ add_embeddings<"          zSummaryWriter.add_embeddingcCs@tjjdt|t|}}|jjt|||||||dS)arAdds precision recall curve. Plotting a precision-recall curve lets you understand your model's performance under different threshold settings. With this function, you provide the ground truth labeling (T/F) and prediction confidence (usually the output of your model) for each target. The TensorBoard UI will let you choose the threshold interactively. Args: tag (string): Data identifier labels (torch.Tensor, numpy.array, or string/blobname): Ground truth data. Binary label for each element. predictions (torch.Tensor, numpy.array, or string/blobname): The probability that an element be classified as true. Value should be in [0, 1] global_step (int): Global step value to record num_thresholds (int): Number of thresholds used to draw the curve. walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Examples:: from torch.utils.tensorboard import SummaryWriter import numpy as np labels = np.random.randint(2, size=100) # binary label predictions = np.random.rand(100) writer = SummaryWriter() writer.add_pr_curve('pr_curve', labels, predictions, 0) writer.close() z tensorboard.logging.add_pr_curveN)rHrIrJr rUr6r)r%r8rZ predictionsr5num_thresholdsweightsr3r*r*r+ add_pr_curveNs zSummaryWriter.add_pr_curvec Cs6tjjd|jjt|||||||| | || dS)aAdds precision recall curve with raw data. Args: tag (string): Data identifier true_positive_counts (torch.Tensor, numpy.array, or string/blobname): true positive counts false_positive_counts (torch.Tensor, numpy.array, or string/blobname): false positive counts true_negative_counts (torch.Tensor, numpy.array, or string/blobname): true negative counts false_negative_counts (torch.Tensor, numpy.array, or string/blobname): false negative counts precision (torch.Tensor, numpy.array, or string/blobname): precision recall (torch.Tensor, numpy.array, or string/blobname): recall global_step (int): Global step value to record num_thresholds (int): Number of thresholds used to draw the curve. walltime (float): Optional override default walltime (time.time()) seconds after epoch of event see: https://github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/pr_curve/README.md z$tensorboard.logging.add_pr_curve_rawN)rHrIrJrUr6r) r%r8Ztrue_positive_countsZfalse_positive_countsZtrue_negative_countsZfalse_negative_countsZ precisionZrecallr5rrr3r*r*r+add_pr_curve_rawts zSummaryWriter.add_pr_curve_rawuntitledcCs2tjjd||d|gii}|jjt|dS)aJShorthand for creating multilinechart. Similar to ``add_custom_scalars()``, but the only necessary argument is *tags*. Args: tags (list): list of tags that have been used in ``add_scalar()`` Examples:: writer.add_custom_scalars_multilinechart(['twse/0050', 'twse/2330']) z5tensorboard.logging.add_custom_scalars_multilinechartZ MultilineN)rHrIrJrUr6r)r%tagscategorytitlelayoutr*r*r+!add_custom_scalars_multilinecharts z/SummaryWriter.add_custom_scalars_multilinechartcCsBtjjdt|dkst||d|gii}|jjt|dS)awShorthand for creating marginchart. Similar to ``add_custom_scalars()``, but the only necessary argument is *tags*, which should have exactly 3 elements. Args: tags (list): list of tags that have been used in ``add_scalar()`` Examples:: writer.add_custom_scalars_marginchart(['twse/0050', 'twse/2330', 'twse/2006']) z2tensorboard.logging.add_custom_scalars_marginchartZMarginN)rHrIrJrxrprUr6r)r%rrrrr*r*r+add_custom_scalars_margincharts z,SummaryWriter.add_custom_scalars_marginchartcCs"tjjd|jjt|dS)aCreate special chart by collecting charts tags in 'scalars'. Note that this function can only be called once for each SummaryWriter() object. Because it only provides metadata to tensorboard, the function can be called before or after the training loop. Args: layout (dict): {categoryName: *charts*}, where *charts* is also a dictionary {chartName: *ListOfProperties*}. The first element in *ListOfProperties* is the chart's type (one of **Multiline** or **Margin**) and the second element should be a list containing the tags you have used in add_scalar function, which will be collected into the new chart. Examples:: layout = {'Taiwan':{'twse':['Multiline',['twse/0050', 'twse/2330']]}, 'USA':{ 'dow':['Margin', ['dow/aaa', 'dow/bbb', 'dow/ccc']], 'nasdaq':['Margin', ['nasdaq/aaa', 'nasdaq/bbb', 'nasdaq/ccc']]}} writer.add_custom_scalars(layout) z&tensorboard.logging.add_custom_scalarsN)rHrIrJrUr6r)r%rr*r*r+add_custom_scalarss z SummaryWriter.add_custom_scalarscCs.tjjd|jjt|||||||dS)afAdd meshes or 3D point clouds to TensorBoard. The visualization is based on Three.js, so it allows users to interact with the rendered object. Besides the basic definitions such as vertices, faces, users can further provide camera parameter, lighting condition, etc. Please check https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene for advanced usage. Args: tag (string): Data identifier vertices (torch.Tensor): List of the 3D coordinates of vertices. colors (torch.Tensor): Colors for each vertex faces (torch.Tensor): Indices of vertices within each triangle. (Optional) config_dict: Dictionary with ThreeJS classes names and configuration. global_step (int): Global step value to record walltime (float): Optional override default walltime (time.time()) seconds after epoch of event Shape: vertices: :math:`(B, N, 3)`. (batch, number_of_vertices, channels) colors: :math:`(B, N, 3)`. The values should lie in [0, 255] for type `uint8` or [0, 1] for type `float`. faces: :math:`(B, N, 3)`. The values should lie in [0, number_of_vertices] for type `uint8`. Examples:: from torch.utils.tensorboard import SummaryWriter vertices_tensor = torch.as_tensor([ [1, 1, 1], [-1, -1, 1], [1, -1, -1], [-1, 1, -1], ], dtype=torch.float).unsqueeze(0) colors_tensor = torch.as_tensor([ [255, 0, 0], [0, 255, 0], [0, 0, 255], [255, 0, 255], ], dtype=torch.int).unsqueeze(0) faces_tensor = torch.as_tensor([ [0, 2, 3], [0, 3, 1], [0, 1, 2], [1, 3, 2], ], dtype=torch.int).unsqueeze(0) writer = SummaryWriter() writer.add_mesh('my_mesh', vertices=vertices_tensor, colors=colors_tensor, faces=faces_tensor) writer.close() ztensorboard.logging.add_meshN)rHrIrJrUr6r)r%r8ZverticescolorsZfacesZ config_dictr5r3r*r*r+add_meshs3 zSummaryWriter.add_meshcCs.|jdkrdSx|jjD] }|jqWdS)zFlushes the event file to disk. Call this method to make sure that all pending events have been written to disk. N)rTrvr<)r%writerr*r*r+r<s zSummaryWriter.flushcCsB|jdkrdSx"|jjD]}|j|jqWd|_|_dS)N)rTrvr<r=rS)r%rr*r*r+r=s   zSummaryWriter.closecCs|S)Nr*)r%r*r*r+ __enter__szSummaryWriter.__enter__cCs |jdS)N)r=)r%exc_typeexc_valexc_tbr*r*r+__exit__szSummaryWriter.__exit__)Nr"Nr r!r")NN)NNFF)NN)NrtNN)NN)NNr)NNr)NNrrN)NTN)NrN)NrN)NN)NFT)NNNrN)NrNN)NrNN)rr)rr)NNNNN)#r?r@rArBr,r]rUr-rgrdrsrwr~rrrrrrrr;r: staticmethodrrrrrrrrr<r=rrr*r*r*r+rCsR  G 4 % / & A 1 , %     # Q +    6 rC).rBrNr.rHZtensorboard.compatrZ"tensorboard.compat.proto.event_pb2rrZtensorboard.compat.protorZ2tensorboard.plugins.projector.projector_config_pb2rZ,tensorboard.summary.writer.event_file_writerrZ _convert_npr Z _embeddingr r r r rZ _onnx_graphrZ_pytorch_graphr_utilsrr4rrrrrrrrrrrrrobjectrrCr*r*r*r+s"          <y