
    1Vh                     d    d Z ddlZddlmZ ddlmZ ddlmZ ej                  Z	 	 	 	 ddZ	d	dZ
y)
aH  Image summaries and TensorFlow operations to create them.

An image summary stores the width, height, and PNG-encoded data for zero
or more images in a rank-1 string array: `[w, h, png0, png1, ...]`.

NOTE: This module is in beta, and its API is subject to change, but the
data that it stores to disk will be supported forever.
    N)metadata)
summary_v2)encoderc           	         ddl mc m} || }t        j                  ||      }|j                  |       5  |j                  |j                  |d      |j                  ||j                        |j                  |      g      5  |d| }|j                  |j                  j                  ||j                  d      }	|j                  |      }
|j!                  |j#                  |
d   d	
      |j#                  |
d   d
      gd
      }|j%                  ||	gd      }|j&                  j)                  d|||      cddd       cddd       S # 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)a  Create a legacy image summary op for use in a TensorFlow graph.

    Arguments:
      name: A unique name for the generated summary node.
      images: A `Tensor` representing pixel data with shape `[k, h, w, c]`,
        where `k` is the number of images, `h` and `w` are the height and
        width of the images, and `c` is the number of channels, which
        should be 1, 3, or 4. Any of the dimensions may be statically
        unknown (i.e., `None`).
      max_outputs: Optional `int` or rank-0 integer `Tensor`. At most this
        many images will be emitted at each step. When more than
        `max_outputs` many images are provided, the first `max_outputs` many
        images will be used and the rest silently discarded.
      display_name: Optional name for this summary in TensorBoard, as a
        constant `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.
      collections: Optional list of graph collections keys. The new
        summary op is added to these collections. Defaults to
        `[Graph Keys.SUMMARIES]`.

    Returns:
      A TensorFlow summary op.
    r   Ndisplay_namedescription   encode_each_image)dtypename)input   width)r      height
dimensions)axisimage_summary)r   tensorcollectionssummary_metadata)tensorflow.compat.v1compatv1r   create_summary_metadata
name_scopecontrol_dependenciesassert_rankassert_typeuint8assert_non_negativemap_fnimage
encode_pngstringshapestack	as_stringconcatsummarytensor_summary)r   imagesmax_outputsr   r	   r   tfr   limited_imagesencoded_imagesimage_shaper   r   s                Q/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/plugins/image/summary.pyopr4   $   sw   B &%77!{ 
t	 
b55NN61%NN6288,"";/	
 
  -HH))$	 # 
 hhVh,XX[^':[^(;   

 J7a@zz(( #-	 ) 
/
 
 
 
 
 
 
s%   AE'B;E?	E'E	E''E0c                    ddl mc m} t        j                  |      j                  t        j                        }|j                  dk7  rt        d|j                  d      |d| }|D cg c]  }t        j                  |       }}|j                  d   |j                  d   }
}	t        |	      t        |
      g|z   }|j                  ||j                        }|| }t        j                   ||	      }|j"                  j%                  |j'                               }|j)                         }|j*                  j-                  d
| z  ||       |S c c}w )a\  Create a legacy image summary protobuf.

    This behaves as if you were to create an `op` with the same arguments
    (wrapped with constant tensors where appropriate) and then execute
    that summary op in a TensorFlow session.

    Arguments:
      name: A unique name for the generated summary, including any desired
        name scopes.
      images: An `np.array` representing pixel data with shape
        `[k, h, w, c]`, where `k` is the number of images, `w` and `h` are
        the width and height of the images, and `c` is the number of
        channels, which should be 1, 3, or 4.
      max_outputs: Optional `int`. At most this many images will be
        emitted. If more than this many images are provided, the first
        `max_outputs` many images will be used and the rest silently
        discarded.
      display_name: Optional name for this summary in TensorBoard, as a
        `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        `str`. Markdown is supported. Defaults to empty.

    Returns:
      A `tf.Summary` protobuf object.
    r   Nr
   zShape z must have rank 4r   r   )r   r   z%s/image_summary)tagr   r   )r   r   r   nparrayastyper!   ndim
ValueErrorr'   r   r%   strmake_tensor_protor&   r   r   SummaryMetadata
FromStringSerializeToStringSummaryvalueadd)r   r-   r.   r   r	   r/   r0   r$   r1   r   r   contentr   r   tf_summary_metadatar+   s                   r3   pbrF   k   s=   6 &%XXf$$RXX.F{{aFGGL[)N=KLEg((/LNL||AQFU5z3v;'.8G!!'!;F77!{ ,,77**, jjlGMM%$  
 N) Ms   -E)   NNN)rG   NN)__doc__numpyr7   tensorboard.plugins.imager   r   tensorboard.utilr   r$   r4   rF        r3   <module>rN      s?     . 0 $ 	 D
N6rM   