ó
    ÷›èh:!  ã                   ó<   • S SK rS SK Jr  SSKJr  Sq " S S5      rg)é    N)ÚValueé   )ÚSummaryWriterc                   ól   • \ rS rSrSr   SS jrSS jrSS jrSS jr\	S 5       r
\S	 5       rS
 rSrg)ÚGlobalSummaryWriteré
   aÔ  A class that implements an event writer that supports concurrent logging and global logging across
different modules.

The GlobalSummaryWriter class provides a set of API to write TensorBoard events from different processes.
The writer instance can be accessed from different processes or modules. Also, the instance maintains
the ``global_step`` value itself so that the interleaved requests to write an event will not conflict
each other. This ensures that the resulting event file is TensorBoard compatible.
With GlobalSummaryWriter, you can easily log the metrics of your parallel-trained model.
The GlobalSummaryWriter and also be used like the ``logging`` module of Python.
See how ``getSummaryWriter`` is used below.
Nc
                 óì  • [        XX4XVUUS9U l        [        R                  " 5       U l        [        R
                  " 5       R                  5       U l        [        R
                  " 5       R                  5       U l        [        R
                  " 5       R                  5       U l	        [        R
                  " 5       R                  5       U l
        [        R
                  " 5       R                  5       U l        g)aY  
Initialize a GlobalSummaryWriter. The resulting instance will maintain a monotonically
increasing ``global_step`` for the the event to be written. So there is no need to pass
the global_step when calling its member functions such as ``add_scalar()``.
All arguments for the constructor will be passed to the ordinary ``SummaryWriter.__init__()`` directly.

Examples::

    import multiprocessing as mp
    import numpy as np
    import time
    from tensorboardX import GlobalSummaryWriter
    w = GlobalSummaryWriter()

    def train(x):
        w.add_scalar('poolmap/1', x*np.random.randn())
        time.sleep(0.05*np.random.randint(0, 10))
        w.add_scalar('poolmap/2', x*np.random.randn())

    with mp.Pool() as pool:
        pool.map(train, range(100))

Expected result:

.. image:: _static/img/tensorboard/add_scalar_global.png
   :scale: 50 %

)ÚlogdirÚcommentÚ
purge_stepÚ	max_queueÚ
flush_secsÚfilename_suffixÚwrite_to_diskÚlog_dirN)r   ÚsmwÚmpÚLockÚlockÚManagerÚdictÚscalar_tag_to_stepÚimage_tag_to_stepÚhistogram_tag_to_stepÚtext_tag_to_stepÚaudio_tag_to_step)Úselfr
   r   r   r   r   r   r   r   Úcoalesce_processÚkwargss              ÚT/var/www/fran/franai/venv/lib/python3.13/site-packages/tensorboardX/global_writer.pyÚ__init__ÚGlobalSummaryWriter.__init__   s    € ô@ !¨ÈJØ,6ÐgtØ)0ñ2ˆŒô —G’G“IˆŒ	Ü"$§*¢*£,×"3Ñ"3Ó"5ˆÔÜ!#§¢£×!2Ñ!2Ó!4ˆÔÜ%'§Z¢Z£\×%6Ñ%6Ó%8ˆÔ"Ü "§
¢
£× 1Ñ 1Ó 3ˆÔÜ!#§¢£×!2Ñ!2Ó!4ˆÕó    c                 ó  • U R                      XR                  ;   a  U R                  U==   S-  ss'   OSU R                  U'   U R                  R                  XU R                  U   U5        SSS5        g! , (       d  f       g= f)z¾Add scalar data to summary.

Args:
    tag (string): Data identifier
    scalar_value (float): Value to save
    walltime (float): Optional override default walltime (time.time()) of event

r   r   N)r   r   r   Ú
add_scalar)r   ÚtagÚscalar_valueÚwalltimes       r    r%   ÚGlobalSummaryWriter.add_scalar@   si   € ð Y‹YØ×-Ñ-Ó-Ø×'Ñ'¨Ó,°Ñ1Ô,à/0×'Ñ'¨Ñ,àH‰H×Ñ °4×3JÑ3JÈ3Ñ3OÐQYÔZ÷ YŽYús   A!A7Á7
Bc           	      ó  • U R                      XR                  ;   a  U R                  U==   S-  ss'   OSU R                  U'   U R                  R                  XU R                  U   X4S9  SSS5        g! , (       d  f       g= f)aÝ  Add image data to summary.

Note that this requires the ``pillow`` package.

Args:
    tag (string): Data identifier
    img_tensor (torch.Tensor, numpy.array): An `uint8` or `float`
        Tensor of shape `[channel, height, width]` where `channel` is 1, 3, or 4.
        The elements in img_tensor can either have values in [0, 1] (float32) or [0, 255] (uint8).
        Users are responsible to scale the data in the correct range/type.
    walltime (float): Optional override default walltime (time.time()) of event.
    dataformats (string): This parameter specifies the meaning of each dimension of the input tensor.
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 use ``add_images()`` and let us do the job.
    Tensor with :math:`(1, H, W)`, :math:`(H, W)`, :math:`(H, W, 3)` is also suitible as long as
    corresponding ``dataformats`` argument is passed. e.g. CHW, HWC, HW.
r   r   )r(   ÚdataformatsN)r   r   r   Ú	add_image)r   r&   Ú
img_tensorr(   r+   s        r    r,   ÚGlobalSummaryWriter.add_imagei   sl   € ð& Y‹YØ×,Ñ,Ó,Ø×&Ñ& sÓ+¨qÑ0Ô+à./×&Ñ& sÑ+àH‰H×Ñ˜s°×0FÑ0FÀsÑ0KÐV^ÐÑx÷ YŽYúó   AA5Á5
Bc                 ó  • U R                      XR                  ;   a  U R                  U==   S-  ss'   OSU R                  U'   U R                  R                  XU R                  U   US9  SSS5        g! , (       d  f       g= f)z½Add text data to summary.

Args:
    tag (string): Data identifier
    text_string (string): String to save
    walltime (float): Optional override default walltime (time.time()) of event

r   r   )Úglobal_stepr(   N)r   r   r   Úadd_text)r   r&   Útext_stringr(   s       r    r2   ÚGlobalSummaryWriter.add_text˜   sm   € ð Y‹YØ×+Ñ+Ó+Ø×%Ñ% cÓ*¨aÑ/Ô*à-.×%Ñ% cÑ*àH‰H×Ñ˜c¸D×<QÑ<QÐRUÑ<VÐaiÐÑj÷ YŽYúr/   c                  óÒ   • [        [        S5      (       a  [        R                  c
  [        5       q[	        S[        R                  R
                  R                  5       5        [        $ )a	  Get the writer from global namespace.

Examples::

    # main.py
    import global_1
    import global_2

    # global1.py
    from tensorboardX import GlobalSummaryWriter
    writer = GlobalSummaryWriter.getSummaryWriter()  # This creates a new instance.
    writer.add_text('my_log', 'greeting from global1')

    # global2.py
    from tensorboardX import GlobalSummaryWriter
    writer = GlobalSummaryWriter.getSummaryWriter()  # Get the instance in global1.py.
    writer.add_text('my_log', 'greeting from global2')

r   zUsing the global logger in:)ÚhasattrÚ_writerr   r   ÚprintÚfile_writerÚ
get_logdir© r#   r    ÚgetSummaryWriterÚ$GlobalSummaryWriter.getSummaryWriter©   sE   € ô, ”w ×&Ñ&¬'¯+©+Ñ*=Ü)Ó+ˆGäÐ+¬W¯[©[×-DÑ-D×-OÑ-OÓ-QÔRÜˆr#   c                 ó6   • U R                   R                  5       $ ©N)r   Ú_get_file_writer©r   s    r    r9   ÚGlobalSummaryWriter.file_writerÅ   s   € àx‰x×(Ñ(Ó*Ð*r#   c                 ól   • U R                   R                  5         U R                   R                  5         g r?   )r   ÚflushÚcloserA   s    r    rE   ÚGlobalSummaryWriter.closeÉ   s   € Ø‰‰ÔØ‰‰Õr#   )r   r   r   r   r   r   r   )	NÚ Nr   éx   rG   TNTr?   )NÚCHW)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r!   r%   r,   r2   Ústaticmethodr<   Úpropertyr9   rE   Ú__static_attributes__r;   r#   r    r   r   
   s[   † ñ
ð LNØQUØ"&ô(5ôT[ôRyô^kð" ñó ðð6 ñ+ó ð+õr#   r   )Úmultiprocessingr   r   Úwriterr   r7   r   r;   r#   r    Ú<module>rT      s!   ðÛ Ý !å !ð €÷Aò Ar#   