
    1Vh                        d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  ej4                         Z ej8                  d       G d d             Z ej8                  d       G d d             Z ej8                  d       G d d             Z ej8                  d       G d d             Z  ej8                  d       G d d             Z! ej8                  d       G d d             Z" ej8                  d       G d  d!             Z#d"d#d$d%d&d'Z$ejJ                  Z%ejL                  Z&ejN                  Z'ejP                  Z(ejR                  Z)ejT                  Z*ejV                  Z+ejX                  Z,ejZ                  Z-d(Z.e%d)e'd*e(d*e)d+e&d,e*d-iZ/e%de'de(de)de&de*diZ0 G d. d/      Z1d0 Z2d1 Z3y)2zATakes a generator of values, and accumulates them for a frontend.    N)OptionalSequenceTuple)directory_watcher)event_file_loader)
event_util)
io_wrapper)plugin_asset_util)	reservoir)	tag_types)
config_pb2)	event_pb2)	graph_pb2)meta_graph_pb2)
tensor_pb2)
compressor)
tb_loggingT)frozenc                   0    e Zd ZU dZeed<   eed<   eed<   y)ScalarEventzContains information of a scalar event.

    Attributes:
      wall_time: Timestamp of the event in seconds.
      step: Global step of the event.
      value: A float or int value of the scalar.
    	wall_timestepvalueN)__name__
__module____qualname____doc__float__annotations__int     f/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/backend/event_processing/event_accumulator.pyr   r   *   s     
ILr"   r   c                   @    e Zd ZU dZeed<   eed<   eeeef      ed<   y)CompressedHistogramEventa&  Contains information of a compressed histogram event.

    Attributes:
      wall_time: Timestamp of the event in seconds.
      step: Global step of the event.
      compressed_histogram_values: A sequence of tuples of basis points and
        associated values in a compressed histogram.
    r   r   compressed_histogram_valuesN)	r   r   r   r   r   r   r    r   r   r!   r"   r#   r%   r%   9   s(     
I!)%u*=!>>r"   r%   c                   d    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   ee   ed<   ee   ed<   y	)
HistogramValueaZ  Holds the information of the histogram values.

    Attributes:
      min: A float or int min value.
      max: A float or int max value.
      num: Total number of values.
      sum: Sum of all values.
      sum_squares: Sum of squares for all values.
      bucket_limit: Upper values per bucket.
      bucket: Numbers of values per bucket.
    minmaxnumsumsum_squaresbucket_limitbucketN)r   r   r   r   r   r   r    r   r!   r"   r#   r(   r(   I   s7    
 
J	J	H	J5/!SMr"   r(   c                   0    e Zd ZU dZeed<   eed<   eed<   y)HistogramEventzContains information of a histogram event.

    Attributes:
      wall_time: Timestamp of the event in seconds.
      step: Global step of the event.
      histogram_value: Information of the histogram values.
    r   r   histogram_valueN)r   r   r   r   r   r   r    r(   r!   r"   r#   r1   r1   `   s     
I##r"   r1   c                   D    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   y)
ImageEventa  Contains information of an image event.

    Attributes:
      wall_time: Timestamp of the event in seconds.
      step: Global step of the event.
      encoded_image_string: Image content encoded in bytes.
      width: Width of the image.
      height: Height of the image.
    r   r   encoded_image_stringwidthheightN)r   r   r   r   r   r   r    bytesr!   r"   r#   r4   r4   o   s$     
IJKr"   r4   c                   N    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   y)	
AudioEventa  Contains information of an audio event.

    Attributes:
      wall_time: Timestamp of the event in seconds.
      step: Global step of the event.
      encoded_audio_string: Audio content encoded in bytes.
      content_type: A string describes the type of the audio content.
      sample_rate: Sample rate of the audio in Hz. Must be positive.
      length_frames: Length of the audio in frames (samples per channel).
    r   r   encoded_audio_stringcontent_typesample_ratelength_framesN)	r   r   r   r   r   r   r    r8   strr!   r"   r#   r:   r:      s,    	 
Ir"   r:   c                   D    e Zd ZU dZeed<   eed<   ej                  ed<   y)TensorEventzA tensor event.

    Attributes:
      wall_time: Timestamp of the event in seconds.
      step: Global step of the event.
      tensor_proto: A `TensorProto`.
    r   r   tensor_protoN)	r   r   r   r   r   r   r    r   TensorProtor!   r"   r#   rA   rA      s      
I(((r"   rA   _ProcessScalar_ProcessHistogram_ProcessImage_ProcessAudio_ProcessTensor)simple_valuehistoimageaudiotensor)	r   i  i3  i  i  i  i   it$  '  i     rN      
   c                       e Zd ZdZdedfdZd Zd Zd Zd Z	d	e
e   fd
Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$y)#EventAccumulatora8  An `EventAccumulator` takes an event generator, and accumulates the
    values.

    The `EventAccumulator` is intended to provide a convenient Python interface
    for loading Event data written during a TensorFlow run. TensorFlow writes out
    `Event` protobuf objects, which have a timestamp and step number, and often
    contain a `Summary`. Summaries can have different kinds of data like an image,
    a scalar value, or a histogram. The Summaries also have a tag, which we use to
    organize logically related data. The `EventAccumulator` supports retrieving
    the `Event` and `Summary` data by its tag.

    Calling `Tags()` gets a map from `tagType` (e.g. `'images'`,
    `'compressedHistograms'`, `'scalars'`, etc) to the associated tags for those
    data types. Then, various functional endpoints (eg
    `Accumulator.Scalars(tag)`) allow for the retrieval of all data
    associated with that tag.

    The `Reload()` method synchronously loads all of the data written so far.

    Histograms, audio, and images are very large, so storing all of them is not
    recommended.

    Fields:
      audios: A reservoir.Reservoir of audio summaries.
      compressed_histograms: A reservoir.Reservoir of compressed
          histogram summaries.
      histograms: A reservoir.Reservoir of histogram summaries.
      images: A reservoir.Reservoir of image summaries.
      most_recent_step: Step of last Event proto added. This should only
          be accessed from the thread that calls Reload. This is -1 if
          nothing has been loaded yet.
      most_recent_wall_time: Timestamp of last Event proto added. This is
          a float containing seconds from the UNIX epoch, or -1 if
          nothing has been loaded yet. This should only be accessed from
          the thread that calls Reload.
      path: A file path to a directory containing tf events files, or a single
          tf events file. The accumulator will load events from this path.
      scalars: A reservoir.Reservoir of scalar summaries.
      tensors: A reservoir.Reservoir of tensor summaries.

    @@Tensors
    NTc                 ^   |xs t         }i }t         D ]  }||v r	||   ||<   t         |   ||<    d| _        t        j                  |t                 | _        d| _        d| _        d| _        i | _	        i | _
        t        j                  |t                 | _        t        j                  |t           d      | _        t        j                  |t                 | _        t        j                  |t"                 | _        t        j                  |t&                 | _        t+        j,                  t.              | _        t3        j4                         | _        || _        t;        |      | _        || _        || _         d| _!        d| _"        d| _#        d| _$        d| _%        i | _&        y)a  Construct the `EventAccumulator`.

        Args:
          path: A file path to a directory containing tf events files, or a single
            tf events file. The accumulator will load events from this path.
          size_guidance: Information on how much data the EventAccumulator should
            store in memory. The DEFAULT_SIZE_GUIDANCE tries not to store too much
            so as to avoid OOMing the client. The size_guidance should be a map
            from a `tagType` string to an integer representing the number of
            items to keep per tag for items of that `tagType`. If the size is 0,
            all events are stored.
          compression_bps: Information on how the `EventAccumulator` should compress
            histogram data for the `CompressedHistograms` tag (for details see
            `ProcessCompressedHistogram`).
          purge_orphaned_data: Whether to discard any events that were "orphaned" by
            a TensorFlow restart.
        N)sizeF)rU   always_keep_last)scalars
histogramscompressed_histogramsimagesaudios)'DEFAULT_SIZE_GUIDANCE_first_event_timestampr   	ReservoirSCALARSrX   _graph_graph_from_metagraph_meta_graph_tagged_metadatasummary_metadata
HISTOGRAMSrY   COMPRESSED_HISTOGRAMSrZ   IMAGESr[   AUDIOr\   TENSORStensorscollectionsdefaultdictdict_plugin_to_tag_to_content	threadingLock_generator_mutexpath_GeneratorFromPath
_generator_compression_bpspurge_orphaned_datamost_recent_stepmost_recent_wall_timefile_version_source_writeraccumulated_attrs_tensor_summaries)selfrs   size_guidancecompression_bpsrw   sizeskeys          r#   __init__zEventAccumulator.__init__   s   0 &>)>( 	8Cm#*3/c
237c
		8 '+# **g?%*" " "#--53DE%.%8%8,-&
"  ))uV}=))uU|< **g? *5)@)@)F& ) 0	,T2 /#6  "%'"  #"
 "$r"   c                     | j                   5  | j                  j                         D ]  }| j                  |        	 ddd       | S # 1 sw Y   | S xY w)zLoads all events added since the last call to `Reload`.

        If `Reload` was never called, loads all events in the file.

        Returns:
          The `EventAccumulator`.
        N)rr   ru   Load_ProcessEventr~   events     r#   ReloadzEventAccumulator.ReloadN  sU     "" 	*--/ *""5)*	* 	* s   1A		Ac                 B    t        j                  | j                  |      S )aH  Return a list of all plugin assets for the given plugin.

        Args:
          plugin_name: The string name of a plugin to retrieve assets for.

        Returns:
          A list of string plugin asset names, or empty list if none are available.
          If the plugin was not registered, an empty list is returned.
        )r
   
ListAssetsrs   r~   plugin_names     r#   PluginAssetszEventAccumulator.PluginAssets[  s     !++DII{CCr"   c                 D    t        j                  | j                  ||      S )a4  Return the contents of a given plugin asset.

        Args:
          plugin_name: The string name of a plugin.
          asset_name: The string name of an asset.

        Returns:
          The string contents of the plugin asset.

        Raises:
          KeyError: If the asset is not available.
        )r
   RetrieveAssetrs   )r~   r   
asset_names      r#   RetrievePluginAssetz$EventAccumulator.RetrievePluginAssetg  s"     !..II{J
 	
r"   c                 (   | j                   | j                   S | j                  5  	 t        | j                  j	                               }| j                  |       | j                   cddd       S # t        $ r t        d      w xY w# 1 sw Y   yxY w)a  Returns the timestamp in seconds of the first event.

        If the first event has been loaded (either by this method or by `Reload`,
        this returns immediately. Otherwise, it will load in the first event. Note
        that this means that calling `Reload` will cause this to block until
        `Reload` has finished.

        Returns:
          The timestamp in seconds of the first event that was loaded.

        Raises:
          ValueError: If no events have been loaded and there were no events found
          on disk.
        Nz!No event timestamp could be found)r^   rr   nextru   r   r   StopIteration
ValueErrorr   s     r#   FirstEventTimestampz$EventAccumulator.FirstEventTimestampx  s     &&2..."" 	FFT__1134""5)22		F 	F ! F !DEEF	F 	Fs   B?A00BBBreturnc                 j   | j                   | j                   S | j                  5  	 t        | j                  j	                               }| j                  |       | j                   cddd       S # t        $ r# t        j                  d| j                         Y nw xY w	 ddd       y# 1 sw Y   yxY w)z%Returns the name of the event writer.Nz.End of file in %s, no source writer was found.)
r{   rr   r   ru   r   r   r   loggerinfors   r   s     r#   GetSourceWriterz EventAccumulator.GetSourceWriter  s    *&&&"" 	T__1134""5)**		 	
 ! Ddii	 	 	s(   B)?A00)BB)BB))B2c                 X    || j                   vrt        d|z        | j                   |   S )a  Returns a dict mapping tags to content specific to that plugin.

        Args:
          plugin_name: The name of the plugin for which to fetch plugin-specific
            content.

        Raises:
          KeyError: if the plugin name is not found.

        Returns:
          A dict mapping tag names to bytestrings of plugin-specific content-- by
          convention, in the form of binary serialized protos.
        zPlugin %r could not be found.)ro   KeyErrorr   s     r#   PluginTagToContentz#EventAccumulator.PluginTagToContent  s4     d<<<:[HII--k::r"   c                      | j                   |   S )zGiven a summary tag name, return the associated metadata object.

        Args:
          tag: The name of a tag, as a string.

        Raises:
          KeyError: If the tag is not found.

        Returns:
          A `SummaryMetadata` protobuf.
        )re   r~   tags     r#   SummaryMetadataz EventAccumulator.SummaryMetadata  s     $$S))r"   c                 L   | j                   |j                  | _         |j                  d      rpt        j                  |j
                        }| j                  r>| j                  |k7  r/t        j                  dj                  | j                  |             || _        |j                  d      rpt        j                  |j                        }| j                  r>| j                  |k7  r/t        j                  dj                  | j                  |             || _        | j                  |       |j                  d      r:| j                  t        j                  d       |j                  | _        d| _        y|j                  d	      r| j"                  t        j                  d
       |j$                  | _        | j                  | j                   rt'        j(                         }|j+                  | j"                         |j                  rH| j                  t        j                  d       d| _        |j                  j-                         | _        yyy|j                  d      rc|j.                  j0                  }|| j2                  v rt        j                  d|z   dz          |j.                  j4                  | j2                  |<   y|j                  d      rC|j6                  j8                  D ](  }|j                  d      r|j0                  }|| j:                  vrx|j<                  | j:                  |<   |j<                  j>                  }|j@                  r'|jB                  | jD                  |j@                     |<   nt        j                  d|       tF        jI                         D ]k  \  }}	|j                  |      stK        ||      }
|j0                  }|dk(  r|s|jL                  } tK        | |	      ||j                  |jN                  |
       m + yy)z#Called whenever an event is loaded.Nsource_metadataz;Found new source writer for event.proto. Old: {0}, New: {1}rz   zqFound new file_version for event.proto. This will affect purging logic for TensorFlow restarts. Old: {0} New: {1}	graph_defzFound more than one graph event per run, or there was a metagraph containing a graph_def, as well as one or more graph events.  Overwriting the graph with the newest event.Fmeta_graph_defz]Found more than one metagraph event per run. Overwriting the metagraph with the newest event.zFound multiple metagraphs containing graph_defs,but did not find any graph events.  Overwriting the graph with the newest metagraph version.Ttagged_run_metadataz2Found more than one "run metadata" event with tag z'. Overwriting it with the newest event.summarymetadataz?This summary with tag %r is oddly not associated with a plugin.rM   )(r^   r   HasFieldr   r   r   r{   r   r   formatParseFileVersionrz   warning_MaybePurgeOrphanedDatara   r   rb   rc   r   r   MetaGraphDefParseFromStringSerializeToStringr   r   rd   run_metadatar   r   re   r   plugin_datar   contentro   SUMMARY_TYPESitemsgetattr	node_namer   )r~   r   new_source_writernew_file_version
meta_graphr   r   r   summary_typesummary_funcdatums              r#   r   zEventAccumulator._ProcessEvent  s   &&.*///D'>>+, * : :%%! ""t':':>O'O-fT002CD	 #4D>>.))::5;M;MN  T%6%6:J%J, fT..0@A !1D$$U+ >>+&{{&(  //DK).D&^^,-+K  %33D{{"d&@&@ ,88:
**4+;+;<''{{.!K 26D.","6"6"H"H"JDK ( 'A  ^^12++//Cd+++H?@
 */)B)B)O)OD!!#&^^I&,, #>>*-))C $"7"775:^^--c2&+nn&@&@&22 &1%8%8 !:: + 7 7!# #NN%. !$ 3@2E2E2G 
.L,~~l3 '| <#ii'83C #(//C3l3%**e
3# 'r"   c                    t         | j                  j                         t        | j                  j                         t
        | j                  j                         t        | j                  j                         t        | j                  j                         t        | j                  j                         t        | j                  dut        | j                   dut"        t%        | j&                  j)                               i	S )zReturn all tags found in the value stream.

        Returns:
          A `{tagType: ['list', 'of', 'tags']}` dictionary.
        N)rh   r[   Keysri   r\   rf   rY   r`   rX   rg   rZ   rj   rk   GRAPHra   
META_GRAPHrc   RUN_METADATAlistrd   keys)r~   s    r#   TagszEventAccumulator.Tags;  s     DKK$$&4;;##%,,.T\\&&(!4#=#=#B#B#DT\\&&( 4;;d*((4$t4499;<
 	
r"   c                 8    | j                   j                  |      S )a   Given a summary tag, return all associated `ScalarEvent`s.

        Args:
          tag: A string tag associated with the events.

        Raises:
          KeyError: If the tag is not found.

        Returns:
          An array of `ScalarEvent`s.
        )rX   Itemsr   s     r#   ScalarszEventAccumulator.ScalarsO       ||!!#&&r"   c                     t        j                         }| j                  |j                  | j                         |S t	        d      )aM  Return the graph definition, if there is one.

        If the graph is stored directly, return that.  If no graph is stored
        directly but a metagraph is stored containing a graph, return that.

        Raises:
          ValueError: If there is no graph for this run.

        Returns:
          The `graph_def` proto.
        z*There is no graph in this EventAccumulator)r   GraphDefra   r   r   )r~   graphs     r#   GraphzEventAccumulator.Graph]  s?     ""$;;"!!$++.LEFFr"   c                     | j                   t        d      t        j                         }|j	                  | j                          |S )zReturn the metagraph definition, if there is one.

        Raises:
          ValueError: If there is no metagraph for this run.

        Returns:
          The `meta_graph_def` proto.
        z.There is no metagraph in this EventAccumulator)rc   r   r   r   r   )r~   r   s     r#   	MetaGraphzEventAccumulator.MetaGrapho  sD     #MNN#002
""4#3#34r"   c                     || j                   vrt        d      t        j                         }|j	                  | j                   |          |S )a  Given a tag, return the associated session.run() metadata.

        Args:
          tag: A string tag associated with the event.

        Raises:
          ValueError: If the tag is not found.

        Returns:
          The metadata in form of `RunMetadata` proto.
        z+There is no run metadata with this tag name)rd   r   r   RunMetadatar   )r~   r   r   s      r#   r   zEventAccumulator.RunMetadata~  sK     d+++JKK!--/$$T%:%:3%?@r"   c                 8    | j                   j                  |      S )zGiven a summary tag, return all associated histograms.

        Args:
          tag: A string tag associated with the events.

        Raises:
          KeyError: If the tag is not found.

        Returns:
          An array of `HistogramEvent`s.
        )rY   r   r   s     r#   
HistogramszEventAccumulator.Histograms  s     $$S))r"   c                 8    | j                   j                  |      S )a  Given a summary tag, return all associated compressed histograms.

        Args:
          tag: A string tag associated with the events.

        Raises:
          KeyError: If the tag is not found.

        Returns:
          An array of `CompressedHistogramEvent`s.
        )rZ   r   r   s     r#   CompressedHistogramsz%EventAccumulator.CompressedHistograms  s     ))//44r"   c                 8    | j                   j                  |      S )zGiven a summary tag, return all associated images.

        Args:
          tag: A string tag associated with the events.

        Raises:
          KeyError: If the tag is not found.

        Returns:
          An array of `ImageEvent`s.
        )r[   r   r   s     r#   ImageszEventAccumulator.Images       {{  %%r"   c                 8    | j                   j                  |      S )zGiven a summary tag, return all associated audio.

        Args:
          tag: A string tag associated with the events.

        Raises:
          KeyError: If the tag is not found.

        Returns:
          An array of `AudioEvent`s.
        )r\   r   r   s     r#   AudiozEventAccumulator.Audio  r   r"   c                 8    | j                   j                  |      S )zGiven a summary tag, return all associated tensors.

        Args:
          tag: A string tag associated with the events.

        Raises:
          KeyError: If the tag is not found.

        Returns:
          An array of `TensorEvent`s.
        )rk   r   r   s     r#   TensorszEventAccumulator.Tensors  r   r"   c                     | j                   sy| j                  r!| j                  dk\  r| j                  |       y| j                  |       y)a  Maybe purge orphaned data due to a TensorFlow crash.

        When TensorFlow crashes at step T+O and restarts at step T, any events
        written after step T are now "orphaned" and will be at best misleading if
        they are included in TensorBoard.

        This logic attempts to determine if there is orphaned data, and purge it
        if it is found.

        Args:
          event: The event to use as a reference, to determine if a purge is needed.
        N   )rw   rz   _CheckForRestartAndMaybePurge$_CheckForOutOfOrderStepAndMaybePurger   s     r#   r   z(EventAccumulator._MaybePurgeOrphanedData  sF     ''!2!2a!7 ..u5 55e<r"   c                     |j                  d      rF|j                  j                  t        j                  j
                  k(  r| j                  |d       yyy)a  Check and discard expired events using SessionLog.START.

        Check for a SessionLog.START event and purge all previously seen events
        with larger steps, because they are out of date. Because of supervisor
        threading, it is possible that this logic will cause the first few event
        messages to be discarded since supervisor threading does not guarantee
        that the START message is deterministically written first.

        This method is preferred over _CheckForOutOfOrderStepAndMaybePurge which
        can inadvertently discard events due to supervisor threading.

        Args:
          event: The event to use as reference. If the event is a START event, all
            previously seen events with a greater event.step will be purged.
        session_logFby_tagsN)r   r   statusr   
SessionLogSTART_Purger   s     r#   r   z.EventAccumulator._CheckForRestartAndMaybePurge  sK    " NN=)!!((I,@,@,F,FFKKuK- G *r"   c                     |j                   | j                  k  r%|j                  d      r| j                  |d       y|j                   | _        |j                  | _        y)a  Check for out-of-order event.step and discard expired events for
        tags.

        Check if the event is out of order relative to the global most recent step.
        If it is, purge outdated summaries for tags that the event contains.

        Args:
          event: The event to use as reference. If the event is out-of-order, all
            events with the same tags, but with a greater event.step will be purged.
        r   Tr   N)r   rx   r   r   r   ry   r   s     r#   r   z5EventAccumulator._CheckForOutOfOrderStepAndMaybePurge  sI     ::---%..2KKKtK,$)JJD!).D&r"   c                     t        |j                  |j                  |j                  |j                  |j
                  t        |j                        t        |j                              S )z*Converts histogram proto to Python object.)r)   r*   r+   r,   r-   r.   r/   )	r(   r)   r*   r+   r,   r-   r   r.   r/   )r~   rJ   s     r#   _ConvertHistogramProtoToPopoz-EventAccumulator._ConvertHistogramProtoToPopo  sN    								))e001%
 	
r"   c                     | j                  |      }t        |||      }| j                  j                  ||       | j                  j                  ||| j
                         y)z>Processes a proto histogram by adding it to accumulated state.N)r   r1   rY   AddItemrZ   _CompressHistogram)r~   r   r   r   rJ   histo_evs         r#   rE   z"EventAccumulator._ProcessHistogram#  sU    11%8!)T59X.""**422	
r"   c                     t        |j                  |j                  t        j                  |j
                  | j                              S )zCallback for _ProcessHistogram.)r%   r   r   r   compress_histogram_protor2   rv   )r~   r   s     r#   r   z#EventAccumulator._CompressHistogram,  s>    'MM//(($*?*?
 	
r"   c                     t        |||j                  |j                  |j                        }| j                  j                  ||       y)z5Processes an image by adding it to accumulated state.)r   r   r5   r6   r7   N)r4   r5   r6   r7   r[   r   )r~   r   r   r   rK   r   s         r#   rF   zEventAccumulator._ProcessImage6  s?    !&!;!;++<<
 	C'r"   c                     t        |||j                  |j                  |j                  |j                        }| j
                  j                  ||       y)z4Processes a audio by adding it to accumulated state.)r   r   r;   r<   r=   r>   N)r:   r;   r<   r=   r>   r\   r   )r~   r   r   r   rL   r   s         r#   rG   zEventAccumulator._ProcessAudioA  sL    !&!;!;++))--
 	C'r"   c                 X    t        |||      }| j                  j                  ||       y)z;Processes a simple value by adding it to accumulated state.)r   r   r   N)r   rX   r   )r~   r   r   r   scalarsvs         r#   rD   zEventAccumulator._ProcessScalarM  s$    94vFS"%r"   c                 X    t        |||      }| j                  j                  ||       y )N)r   r   rB   )rA   rk   r   )r~   r   r   r   rM   tvs         r#   rH   zEventAccumulator._ProcessTensorR  s$    94fMS"%r"   c                    	 fd	|rN	 fd}j                   j                  D cg c]
  } ||       }}t        | D cg c]  }t        |       }}n2 j                  D cg c]  }t         |      j                  	       }}t        |      dkD  rMt         j                   j                  j                  j                  g| }t        j                  |       yyc c}w c c}w c c}w )a  Purge all events that have occurred after the given event.step.

        If by_tags is True, purge all events that occurred after the given
        event.step, but only for the tags that the event has. Non-sequential
        event.steps suggest that a TensorFlow restart occurred, and we discard
        the out-of-order events to display a consistent view in TensorBoard.

        Discarding by tags is the safer method, when we are unsure whether a restart
        has occurred, given that threading in supervisor can cause events of
        different tags to arrive with unsynchronized step values.

        If by_tags is False, then purge all events with event.step greater than the
        given event.step. This can be used when we are certain that a TensorFlow
        restart has occurred and these events can be discarded.

        Args:
          event: The event to use as reference for the purge. All events with
            the same tags, but with a greater event.step will be purged.
          by_tags: Bool to dictate whether to discard all out-of-order events or
            only those that are associated with the given reference event.
        c                 6    | j                   j                   k  S N)r   )xr   s    r#   <lambda>z)EventAccumulator._Purge.<locals>.<lambda>m  s     3 r"   c                     j                   D cg c](  }t        |      j                  | j                        * c}S c c}w r   )r|   r   FilterItemsr   )r   r   _NotExpiredr~   s     r#   _ExpiredPerTagz/EventAccumulator._Purge.<locals>._ExpiredPerTagq  sC     "33 D!$00eiiH  s   -A r   N)r   r   zipr,   r|   r   r  _GetPurgeMessagerx   ry   r   r   r   r   )
r~   r   r   r  r   expired_per_tagsr   expired_per_type	purge_msgr  s
   ``       @r#   r   zEventAccumulator._PurgeV  s    . 4 49==3F3F */u%    145E0FG1AGG //  a ,,[9   
  1$(%%**

	
 "I NN9% %   H s   C'C,'"C1)%r   r   r   r   NORMAL_HISTOGRAM_BPSr   r   r   r   r   r   r?   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rE   r   rF   rG   rD   rH   r   r!   r"   r#   rS   rS      s    )\ , N$`
D
"F4# ;$*yv
('G$&*5&&'=2.,9"



	(
(&
&3&r"   rS   c	                 4    dj                  | ||||||||	      S )z=Return the string message associated with TensorBoard purges.a"  Detected out of order event.step likely caused by a TensorFlow restart. Purging expired events from Tensorboard display between the previous step: {} (timestamp: {}) and current step: {} (timestamp: {}). Removing {} scalars, {} histograms, {} compressed histograms, {} images, and {} audio.)r   )	rx   ry   
event_stepevent_wall_timenum_expired_scalarsnum_expired_histosnum_expired_comp_histosnum_expired_imagesnum_expired_audios	            r#   r  r    s3    	 f
r"   c                     | st        d      t        j                  |       rt        j                  |       S t        j                  | t        j                  t        j                        S )zECreate an event generator for file or directory at given path string.zpath must be a valid string)r   r	   IsSummaryEventsFiler   LegacyEventFileLoaderr   DirectoryWatcher)rs   s    r#   rt   rt     sX    677%%d+ 66t<< 1133**
 	
r"   )4r   rl   dataclassesrp   typingr   r   r   $tensorboard.backend.event_processingr   r   r   r	   r
   r   r   tensorboard.compat.protor   r   r   r   r    tensorboard.plugins.distributionr   tensorboard.utilr   
get_loggerr   	dataclassr   r%   r(   r1   r4   r:   rA   r   rg   rf   rh   ri   r`   rj   r   r   r   r	  r]   STORE_EVERYTHING_SIZE_GUIDANCErS   r  rt   r!   r"   r#   <module>r     sK   H    , , B B ; ; B : : / . . 3 / 7 ' 
			  d#  $ d#? ? $? d#  $, d#$ $ $$ d#  $$ d#  $( d#) ) $)  %  "77 !!
			





!!
%%
 K  3
A	1UR  1
A	1QQ" w
& w
&t@
r"   