a
    Sic                     @   sN   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dZ	dd	d
Z
dS )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)encoder   c              	   C   s8  ddl m  m} |du r| }tj||d}||  |||d|||j	|
|g |d| }|j|jj||jdd}	|j|d}
|j|j|
d d	d
|j|
d dd
gdd
}|j||	gdd}|jjd|||dW  d   W  d   S 1 s
0    Y  W d   n1 s*0    Y  dS )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   Z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    r1   ]/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorboard/plugins/image/summary.pyop$   sB    !
r3   c                 C   s   ddl m  m} t|tj}|jdkr>td|j	f |d| }dd |D }|j	d |j	d  }}	t
|t
|	g| }
|j|
|jd	}|du r| }tj||d
}|j| }| }|jjd|  ||d |S )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 %r must have rank 4c                 S   s   g | ]}t |qS r1   )r   r#   ).0r"   r1   r1   r2   
<listcomp>       zpb.<locals>.<listcomp>r   r   )r
   r   z%s/image_summary)tagr   r   )r   r   r   nparrayastyper   ndim
ValueErrorr%   strmake_tensor_protor$   r   r   SummaryMetadata
FromStringSerializeToStringSummaryvalueadd)r   r+   r,   r   r   r-   r.   r/   r   r   contentr   r   tf_summary_metadatar)   r1   r1   r2   pbk   s0    
rG   )r   NNN)r   NN)__doc__numpyr8   tensorboard.plugins.imager   r   tensorboard.utilr   r"   r3   rG   r1   r1   r1   r2   <module>   s   
    
G