o
    2h                     @   sL   d Z ddlZddlmZ G dd dejZe ZG dd dejZe Z	dS )zCTensorBoard encoder helper module.

Encoder depends on TensorFlow.
    N)op_evaluatorc                       0   e Zd ZdZ fddZdd Zdd Z  ZS )_TensorFlowPngEncoderab  Encode an image to PNG.

    This function is thread-safe, and has high performance when run in
    parallel. See `encode_png_benchmark.py` for details.

    Arguments:
      image: A numpy array of shape `[height, width, channels]`, where
        `channels` is 1, 3, or 4, and of dtype uint8.

    Returns:
      A bytestring with PNG-encoded data.
    c                    s   t    d | _d | _d S N)super__init___image_placeholder
_encode_opself	__class__ S/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/util/encoder.pyr   (   s   

z_TensorFlowPngEncoder.__init__c                 C   s8   dd l m  m} |j|jdd| _|j| j| _d S )Nr   image_to_encodedtypename)	tensorflow.compat.v1compatv1placeholderuint8r   image
encode_pngr	   r   tfr   r   r   initialize_graph-   s
   z&_TensorFlowPngEncoder.initialize_graphc                 C   sF   t |tjstd| |jtjkrtd|j | jj| j|idS )Nz!'image' must be a numpy array: %rz&'image' dtype must be uint8, but is %r	feed_dict)	
isinstancenpndarray
ValueErrorr   r   r	   evalr   )r   r   r   r   r   run6   s   z_TensorFlowPngEncoder.run__name__
__module____qualname____doc__r   r   r%   __classcell__r   r   r   r   r      s
    	r   c                       r   )_TensorFlowWavEncodera!  Encode an audio clip to WAV.

    This function is thread-safe and exhibits good parallel performance.

    Arguments:
      audio: A numpy array of shape `[samples, channels]`.
      samples_per_second: A positive `int`, in Hz.

    Returns:
      A bytestring with WAV-encoded data.
    c                    s    t    d | _d | _d | _d S r   )r   r   _audio_placeholder_samples_per_second_placeholderr	   r
   r   r   r   r   P   s   

z_TensorFlowWavEncoder.__init__c                 C   sP   dd l m  m} |j|jdd| _|j|jdd| _|jj	| j| jd| _
d S )Nr   r   r   samples_per_second)sample_rate)r   r   r   r   float32r-   int32r.   audio
encode_wavr	   r   r   r   r   r   V   s   z&_TensorFlowWavEncoder.initialize_graphc                 C   sL   t |tjstd| t |tstd| | j|| j|i}| jj|dS )Nz!'audio' must be a numpy array: %rz''samples_per_second' must be an int: %rr   )	r    r!   r"   r#   intr-   r.   r	   r$   )r   r3   r/   r   r   r   r   r%   e   s   
z_TensorFlowWavEncoder.runr&   r   r   r   r   r,   C   s
    r,   )
r*   numpyr!   tensorboard.utilr   PersistentOpEvaluatorr   r   r,   r4   r   r   r   r   <module>   s   &
2