
    JTh                        S SK r S SKrS SKrS SKrS SKJrJr  S SKrS SKr	S SK
Jr  S SKJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S
SKJr  S
SKJrJr  / SQr\R@                  " \!5      r"S\#S\$4S jr%S\$S\#4S jr&S\RN                  S\(\$   4S jr)S\RN                  S\(\#   4S jr*S\RN                  S\(\   4S jr+0 \RX                  SS\)4_\RZ                  SS\)4_\R\                  SS\)4_\R^                  SS\+4_\RF                  SS\+4_\R`                  SS\+4_\Rb                  SS\+4_\Rd                  SS\+4_\Rf                  S S\+4_\Rh                  S S\+4_\Rj                  S!S\+4_\Rl                  S!S\+4_\RH                  S"S\+4_\Rn                  S"S\+4_\Rp                  S"S\+4_\Rr                  S#S$\+4_\Rt                  S%S&\*4_\Rv                  S%S&\*4\Rx                  S'S&\*4\Rz                  S'S&\*4\R|                  S(S)\+4\R~                  S*S+\*4\R                  S*S+\*4\Rf                  S S,\+4\R                  S S,\+4\R                  S S,\+40	ErCS- rD   SDS. jrESES/ jrFSFS0 jrGS1 rHS2 rISGS3 jrJSGS4 jrKSHS5 jrL SIS6 jrMSGS7 jrNSJS8 jrOSKS9 jrPS: rQSLS; jrRS< rSS= rT SMS> jrUSMS? jrVSNS@ jrWSA rXSB rY SNSC jrZg)O    N)AnyOptional)
struct_pb2)HistogramProtoSummarySummaryMetadata)TensorProto)TensorShapeProto)
layout_pb2)PrCurvePluginData)TextPluginData   )make_np)_prepare_videoconvert_to_HWC)half_to_intint_to_halfhparamsscalarhistogram_raw	histogrammake_histogramimageimage_boxes
draw_boxes
make_imagevideo
make_videoaudiocustom_scalarstexttensor_protopr_curve_rawpr_curvecompute_curvemeshfreturnc                 d    [         R                  " SU 5      n[         R                  " SU5      S   $ )a-  Casts a half-precision float value into an integer.

Converts a half precision floating point value, such as `torch.half` or
`torch.bfloat16`, into an integer value which can be written into the
half_val field of a TensorProto for storage.

To undo the effects of this conversion, use int_to_half().

r'   ir   structpackunpack)r'   bufs     W/var/www/auris/envauris/lib/python3.13/site-packages/torch/utils/tensorboard/summary.pyr   r   6   s*     ++c1
C==c"1%%    r*   c                 d    [         R                  " SU 5      n[         R                  " SU5      S   $ )zCasts an integer value to a half-precision float.

Converts an integer value obtained from half_to_int back into a floating
point value.

r*   r'   r   r+   )r*   r/   s     r0   r   r   C   s*     ++c1
C==c"1%%r1   tc                 |    U R                  5       R                  5        Vs/ s H  n[        U5      PM     sn$ s  snf N)flattentolistr   )r3   xs     r0   _tensor_to_half_valr9   M   s/    $%IIK$6$6$89$8qKN$8999s   9c                 f    [         R                  " U 5      R                  5       R                  5       $ r5   )torchview_as_realr6   r7   r3   s    r0   _tensor_to_complex_valr>   P   s%    a ((*1133r1   c                 >    U R                  5       R                  5       $ r5   )r6   r7   r=   s    r0   _tensor_to_listr@   S   s    99;r1   DT_HALFhalf_valDT_BFLOAT16DT_FLOAT	float_val	DT_DOUBLE
double_valDT_INT8int_valDT_UINT8DT_INT16DT_INT32DT_INT64	int64_valDT_COMPLEX32scomplex_valDT_COMPLEX64DT_BOOLbool_valDT_COMPLEX128dcomplex_val
uint32_valc                     [        U [        R                  5      (       d  U R                  5       OU nUR                  [        R
                  :X  a  S$ S$ )Nr      )
isinstancenpndarraynumpydtypeuint8)tensor	converteds     r0   _calc_scale_factorra   u   s9    &0&D&D&I288+144r1   c	                    SSK Jn	Jn
  U
R                  5       nU	R	                  U 5      nXX$4u  pnnUR                  X4UU4UU4X4X4/UUS9  U(       az  UnUR                  U5      u  nnnnUU-
  UU-
  nn[        R                  " SU-  5      nUR                  UUU-
  SU-  -
  4UU-   U4/US9  UR                  UU-   UU-
  U-
  4UUUS9  U $ )Nr   )	ImageDraw	ImageFont)widthfillg?   )rf   )rf   font)PILrc   rd   load_defaultDrawlinegetbboxrZ   ceil	rectangler!   )r   xminyminxmaxymaxdisplay_strcolor
color_text	thicknessrc   rd   rh   drawleftrighttopbottomtext_bottom_left_top_right_bottom
text_widthtext_heightmargins                            r0   _draw_single_boxr   z   s#    )!!#D>>% D"&d!9T#vII
tVnufo|d[Q  
 '+||K'@$tVW"(5.'D.K
+,{[01v:=>
"K0  	 	
 			F]K+5>?	 	 	
 Lr1   c           
      	  ^ ^ SSK nSSKJnJnJnJnJnJn	  SSKJ	n
J
nJnJnJn  SSKJnJnJn  [%        T [&        5      (       d   [(        R+                  S5        [-        S5      e[%        U[&        5      (       d   [(        R+                  S5        [-        S5      eU=(       d    0 n[%        U[&        5      (       d  [-        S5      eUR/                  5        HN  u  mnTT ;  d2  [%        U[0        5      (       a  [3        U U4S	 jU 5       5      (       a  M>  [-        S
T ST S35      e   / nU" 5       nT R/                  5        GH=  u  mnUc  M  [%        U[4        [6        45      (       a  UUR8                  T   l        TU;   a;  [<        R>                  " UT    Vs/ s H  n[<        R@                  " US9PM     snS9nOSnURC                  U" TURA                  S5      US95        M  [%        U[D        5      (       a  UUR8                  T   l#        TU;   a;  [<        R>                  " UT    Vs/ s H  n[<        R@                  " US9PM     snS9nOSnURC                  U" TURA                  S5      US95        GM;  [%        U[H        5      (       a  UUR8                  T   l%        TU;   a;  [<        R>                  " UT    Vs/ s H  n[<        R@                  " US9PM     snS9nOSnURC                  U" TURA                  S5      US95        GM  [%        UURL                  5      (       aJ  [O        U5      S   nUUR8                  T   l        URC                  U" TURA                  S5      S95        GM5  [Q        S5      e   U" UUS9n[S        [R        RT                  " UURW                  5       S9S9n[Y        [X        R@                  " UUS9/S9nUR[                  5        Vs/ s H  nU" U" US9S9PM     nnU" UUS9nU" UUS9n[S        [R        RT                  " UURW                  5       S9S9n[Y        [X        R@                  " U
US9/S9nU" U	RA                  S 5      S!9nU" UUS"9n[S        [R        RT                  " UURW                  5       S9S9n[Y        [X        R@                  " UUS9/S9nUUU4$ s  snf s  snf s  snf s  snf )#a  Output three `Summary` protocol buffers needed by hparams plugin.

`Experiment` keeps the metadata of an experiment, such as the name of the
  hyperparameters and the name of the metrics.
`SessionStartInfo` keeps key-value pairs of the hyperparameters
`SessionEndInfo` describes status of the experiment e.g. STATUS_SUCCESS

Args:
  hparam_dict: A dictionary that contains names of the hyperparameters
    and their values.
  metric_dict: A dictionary that contains names of the metrics
    and their values.
  hparam_domain_discrete: (Optional[Dict[str, List[Any]]]) A dictionary that
    contains names of the hyperparameters and all discrete values they can hold

Returns:
  The `Summary` protobufs for Experiment, SessionStartInfo and
    SessionEndInfo
r   N)DataType
Experiment
HParamInfo
MetricInfo
MetricNameStatus)EXPERIMENT_TAGPLUGIN_DATA_VERSIONPLUGIN_NAMESESSION_END_INFO_TAGSESSION_START_INFO_TAG)HParamsPluginDataSessionEndInfoSessionStartInfoz>parameter: hparam_dict should be a dictionary, nothing logged.z>parameter: metric_dict should be a dictionary, nothing logged.zIparameter: hparam_domain_discrete should be a dictionary, nothing logged.c              3   T   >#    U  H  n[        U[        TT   5      5      v   M     g 7fr5   )rY   type).0dhparam_dictks     r0   	<genexpr>hparams.<locals>.<genexpr>   s$     FAqz!T+a.%9::As   %(z"parameter: hparam_domain_discrete[z/] should be a list of same type as hparam_dict[z].)number_value)valuesDATA_TYPE_FLOAT64)namer   domain_discrete)string_valueDATA_TYPE_STRING)
bool_valueDATA_TYPE_BOOL)r   r   z=value should be one of int, float, str, bool, or torch.Tensor)session_start_infoversionplugin_namecontentplugin_data)tagmetadatavaluer   )r   )hparam_infosmetric_infos)
experimentr   STATUS_SUCCESS)status)session_end_infor   ).r;   #tensorboard.plugins.hparams.api_pb2r   r   r   r   r   r   $tensorboard.plugins.hparams.metadatar   r   r   r   r   +tensorboard.plugins.hparams.plugin_data_pb2r   r   r   rY   dictloggerwarning	TypeErroritemslistallintfloatr   r   r   	ListValueValueappendstrr   boolr   Tensorr   
ValueErrorr   
PluginDataSerializeToStringr   keys)r   metric_dicthparam_domain_discreter;   r   r   r   r   r   r   r   r   r   r   r   r   r   r   vhpsssir   r   r   smdr   mtsexpseis   `                        `   r0   r   r      s   (     k4((WXL
 	
 k4((WXL
 	
 49r,d33W
 	
 ',,.1[ a&&FAFFF4QC7fghfiikl  / C

C!!#19a#u&&*+CKKN'**BLBVBV "8!:!:A #((a8!:C #'JJ!(;<$3 a*+CKKN'**","6"6 "8!:!:A #((a8!:# #'JJ!(:;$3 a()CKKN%**","6"6 "8!:!:A #((A6!:# #'JJ!(89$3 a&&
1A*+CKKN'JJzqx~~>Q/RSTK
 	
U $\  3@STG
#..#W-F-F-H
C
 +ACPQ
RC7B7G7G7I
J7I!::!,-7IC
J
#C
8C38KLG
#..#W-F-F-H
C
 >CHI
JC
-= >
?C>QRG
#..#W-F-F-H
C
 +?#NO
PCS=G,,D Ks   R4
+R9
 R>
!Sc                    [        U5      R                  5       nUR                  S:X  d"   SUR                   SUR                   S35       e[	        U5      nU(       aX  [        U/SS9nU(       a  [        U/SS9n[        R                  " S	S
9n[        US9n[        [        R                  " U UUS9/S9$ [        [        R                  " XS9/S9$ )a  Output a `Summary` protocol buffer containing a single scalar value.

The generated Summary has a Tensor.proto containing the input Tensor.
Args:
  name: A name for the generated node. Will also serve as the series name in
    TensorBoard.
  tensor: A real numeric Tensor containing a single value.
  collections: Optional list of graph collections keys. The new summary op is
    added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
  new_style: Whether to use new style (tensor field) or old style (simple_value
    field). New style could lead to faster data loading.
Returns:
  A scalar `Tensor` of type `string`. Which contains a `Summary` protobuf.
Raises:
  ValueError: If tensor has the wrong shape or type.
r   zBTensor should contain one element (0 dimensions). Was given size: z and z dimensions.rD   )rE   r]   rF   )rG   r]   scalarsr   r   r   r_   r   r   )r   simple_value)
r   squeezendimsizer   r	   r   r   r   r   )	r   r_   collections	new_styledouble_precisionr   r"   r   r   s	            r0   r   r   b  s    " V_$$&Fqx	KFKK=X]^d^i^i]jjvwx 6]F"fXZH&6(+NL%00YG+6' 
 	
 gmmJKLLr1   c                    UR                  5       UR                  -  S:  a  [        S5      eUR                  [        ;   aa  [        UR                     u  p#n[        S0 SUS[        UR                   Vs/ s H  n[        R                  " US9PM     snS9X4" U5      0D6nO[        U  SUR                   35      e[        R                  " SS	9n[        US
9n[        [        R                  " XUS9/S9$ s  snf )a  Outputs a `Summary` protocol buffer containing the full tensor.
The generated Summary has a Tensor.proto containing the input Tensor.
Args:
  tag: A name for the generated node. Will also serve as the series name in
    TensorBoard.
  tensor: Tensor to be converted to protobuf
Returns:
  A tensor protobuf in a `Summary` protobuf.
Raises:
  ValueError: If tensor is too big to be converted to protobuf, or
                 tensor data type is not supported
l        zAtensor is bigger than protocol buffer's hard limit of 2GB in sizer]   tensor_shaper   dimz has unsupported tensor dtype r_   r   r   r   r   r_   r    )numelitemsizer   r]   _TENSOR_TYPE_MAPr	   r
   shapeDimr   r   r   r   )	r   r_   r]   
field_nameconversion_fnr8   r"   r   r   s	            r0   r"   r"     s     ||~'G4O
 	
 ||''+;FLL+I(=" 
 0?E||L|!)--15|L! M&1
 C5 >v||nMNN!,,BK
k
2C'--ClSTUU Ms   4C6c           
      X    [        UUUUUUUS9n[        [        R                  " XS9/S9$ )a  Output a `Summary` protocol buffer with a histogram.

The generated
[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
has one summary value containing a histogram for `values`.
Args:
  name: A name for the generated node. Will also serve as a series name in
    TensorBoard.
  min: A float or int min value
  max: A float or int max value
  num: Int number of values
  sum: Float or int sum of all values
  sum_squares: Float or int sum of squares for all values
  bucket_limits: A numeric `Tensor` with upper value per bucket
  bucket_counts: A numeric `Tensor` with number of values per bucket
Returns:
  A scalar `Tensor` of type `string`. The serialized `Summary` protocol
  buffer.
minmaxnumsumsum_squaresbucket_limitbucketr   histor   )r   r   r   )	r   r   r   r   r   r   bucket_limitsbucket_countshists	            r0   r   r     s<    * "D '--D=>??r1   c                     [        U5      n[        UR                  [        5      X#5      n[	        [        R
                  " XS9/S9$ )a0  Output a `Summary` protocol buffer with a histogram.

The generated
[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
has one summary value containing a histogram for `values`.
This op reports an `InvalidArgument` error if any value is not finite.
Args:
  name: A name for the generated node. Will also serve as a series name in
    TensorBoard.
  values: A real numeric `Tensor`. Any shape. Values to use to
    build the histogram.
Returns:
  A scalar `Tensor` of type `string`. The serialized `Summary` protocol
  buffer.
r   r   )r   r   astyper   r   r   )r   r   binsmax_binsr   s        r0   r   r     s9    " V_F&--.?D'--D=>??r1   c           
      $   U R                   S:X  a  [        S5      eU R                  S5      n [        R                  " XS9u  p4[        U5      nUb  XR:  a  XR-  nXV-  nUS:w  a  [        R                  " USXg-
  //SSS9nUR                  SU5      R                  SS9n[        R                  " UR                   S	-   4UR                  5      nUSSU2   USS& US   US'   Un[        R                  " [        R                  " US5      5      n	[        R                  " U	SU	S   S	-
  /S
S9u  p[        U
5      n
[        U5      S	-   nA	U
S:  a  X:S	-
  U O[        R                  " S/USU /5      nXJUS	-    nUR                   S:X  d  UR                   S:X  a  [        S5      eU R                  U 5      n[!        U R#                  5       U R%                  5       [        U 5      U R                  5       UUR'                  5       UR'                  5       S9$ )zDConvert values into a histogram proto using logic from histogram.cc.r   zThe input has no element.)r   Nconstant)	pad_widthmodeconstant_values)axisr   rz   )sidez1The histogram is empty, please file a bug report.r   )r   r   reshaperZ   r   lenpadr   emptyr]   cumsumgreatersearchsortedr   concatenatedotr   r   r   r7   )r   r   r  countslimitsnum_binssubsamplingsubsampling_remainder
new_limits
cum_countsstartendsum_sqs                r0   r   r     s   {{a455^^BF\\&4NF6{H 3* ( 6 A%VV{BCD !	F K044"4=XXv{{Q0&,,?
 "[1
3B
2 2::fa01JaB!1C-D7SJEJE
c(Q,C $)19qy3"..1#vds|AT2U  C!G$F{{a6;;!+LMMZZFJJLJJLKJJL]]_}} r1   c                 .   [        U5      n[        X5      n[        U5      nUR                  [        R
                  5      nX-  R                  SS5      R                  [        R                  5      n[        XS9n[        [        R                  " XS9/S9$ )a  Output a `Summary` protocol buffer with images.

The summary has up to `max_images` summary values containing images. The
images are built from `tensor` which must be 3-D with shape `[height, width,
channels]` and where `channels` can be:
*  1: `tensor` is interpreted as Grayscale.
*  3: `tensor` is interpreted as RGB.
*  4: `tensor` is interpreted as RGBA.
The `name` in the outputted Summary.Value protobufs is generated based on the
name, with a suffix depending on the max_outputs setting:
*  If `max_outputs` is 1, the summary value tag is '*name*/image'.
*  If `max_outputs` is greater than 1, the summary value tags are
   generated sequentially as '*name*/image/0', '*name*/image/1', etc.
Args:
  tag: A name for the generated node. Will also serve as a series name in
    TensorBoard.
  tensor: A 3-D `uint8` or `float32` `Tensor` of shape `[height, width,
    channels]` where `channels` is 1, 3, or 4.
    'tensor' can either have values in [0, 1] (float32) or [0, 255] (uint8).
    The image() function will scale the image values to [0, 255] by applying
    a scale factor of either 1 (uint8) or 255 (float32). Out-of-range values
    will be clipped.
Returns:
  A scalar `Tensor` of type `string`. The serialized `Summary` protocol
  buffer.
r   rX   )rescaler   r   r   )r   r   ra   r   rZ   float32clipr^   r   r   r   )r   r_   r  dataformatsscale_factorr   s         r0   r   r      sx    6 V_FF0F%f-L]]2::&F#))!S188BFv/E'--C=>??r1   c                 D   [        U5      n[        X5      n[        U5      nUR                  [        R                  5      [        U5      -  n[        UR                  SS5      R                  [        R                  5      UUUS9n[        [        R                  " XS9/S9$ )z/Output a `Summary` protocol buffer with images.r   rX   )r  roislabelsr  r   )r   r   r   rZ   r   ra   r   r!  r^   r   r   )r   tensor_imagetensor_boxesr  r"  r&  r   s          r0   r   r   E  s     <(L!,<L<(L&&rzz25G5UUL!S!((2	E '--C=>??r1   c                     UR                   S   n[        U5      nU H)  n[        U XS4   XS4   XS4   XS4   Uc  S OX%   SS9n M+     U $ )Nr   r   rg      Red)rt   ru   )r   ranger   )
disp_imageboxesr&  	num_boxeslist_gtr*   s         r0   r   r   V  sj    AIIG%Q$KQ$KQ$KQ$K &FI

  r1   c                    SSK Jn  U R                  u  pVn[        XQ-  5      n[        Xa-  5      n	UR	                  U 5      n
Ub
  [        XUS9n
UR                  R                  nU
R                  X4U5      n
SSK	nUR                  5       nU
R                  USS9  UR                  5       nUR                  5         [        R                  " UUUUS9$ )z=Convert a numpy representation of an image to Image protobuf.r   )ImageN)r&  PNG)formatheightre   
colorspaceencoded_image_string)ri   r2  r   r   	fromarrayr   
ResamplingLANCZOSresizeioBytesIOsavegetvaluecloser   )r_   r  r%  r&  r2  r6  re   channelscaled_heightscaled_widthr   	ANTIALIASr=  outputimage_strings                  r0   r   r   g  s    #\\F7()Mu'LOOF#E5v6  ((ILL,6	BEZZ\F	JJveJ$??$L
LLN==)	 r1   c                 2   [        U5      n[        U5      n[        U5      nUR                  [        R
                  5      nX-  R                  SS5      R                  [        R                  5      n[        X5      n[        [        R                  " XS9/S9$ )Nr   rX   r  r   )r   r   ra   r   rZ   r   r!  r^   r   r   r   )r   r_   fpsr#  r   s        r0   r   r     sv    V_FF#F%f-L]]2::&F#))!S188BFv#E'--C=>??r1   c                     SS K n SSK Jn  SS KnU R
                  u  pVpxUR                  [        U 5      US9n	UR                  SSS	9R                  n
 U	R                  U
SS S
9  [        U
S5       nUR                  5       nS S S 5         [        R                  " U
5        [&        R(                  " XgUWS9$ ! [         a    [        S5         g f = f! [         a    [        SS5         g f = f! [         a6     U	R                  U
SSS9   N! [         a    U	R                  U
SS9    Nf = ff = f! , (       d  f       N= f! [          a    ["        R%                  S5         Nf = f)Nr   zadd_video needs package moviepy)editorz6moviepy is installed, but can't import moviepy.editor.z2Some packages could be missing [imageio, requests])rI  z.gifF)suffixdelete)verboser   )rN  progress_bar)rN  rbz5The temporary file used by moviepy cannot be deleted.r5  )moviepyImportErrorprintrK  tempfiler   ImageSequenceClipr   NamedTemporaryFiler   	write_gifr   openreadosremoveOSErrorr   r   r   r2  )r_   rI  rQ  mpyrT  _thwcr!  filenamer'   tensor_strings                r0   r   r     sj   ) ,,KB1   f3 7D**&*GLLH4xt< 
h	 
P
		( ==am G  /0
  D@	
 	   4	4NN8UNG 	4NN8UN3	44 
	
  PNOPsj   B7 C C. 1D1E 7CCC+*C+.
D.9DD*&D.)D**D.1
D?E$#E$c                 @   [        U5      nUR                  5       n[        U5      R                  5       S:  a  [	        S5        UR                  SS5      nUR                  S:X  d   S5       eU[        R                  " [        R                  5      R                  -  R                  S5      nSS KnSS KnUR                  5       nUR                  US5       nUR                  S5        UR!                  S5        UR#                  U5        UR%                  UR&                  5        S S S 5        UR)                  5       nUR+                  5         [,        R.                  " USUR0                  S   US	S
9n	[-        [,        R2                  " X	S9/S9$ ! , (       d  f       No= f)Nr   z4warning: audio amplitude out of range, auto clipped.r  z%input tensor should be 1 dimensional.z<i2r   wbrg   z	audio/wav)sample_ratenum_channelslength_framesencoded_audio_stringcontent_type)r   r   r   )r   r   absr   rS  r!  r   rZ   iinfoint16r   r=  waver>  rX  setnchannelssetsampwidthsetframeratewriteframesdatar@  rA  r   Audior   r   )
r   r_   rf  arrayr=  rn  fio
wave_writeaudio_stringr   s
             r0   r   r     s?   FOEMMOE
5z~~!DE

2q!::?CCC?RXXbhh'+++33E:E
**,C	3	"",uzz*	 

 <<>LIIKMMkk"o) E '--C=>?? 
	s   AF
Fc           
         / nU R                  5        H  u  p#/ nUR                  5        H  u  pVUS   nUS   S:X  aa  [        U5      S:X  d   e[        R                  " [        R                  R	                  US   US   US   S9/S9n[        R
                  " XXS9n	O([        R                  " US	9n
[        R
                  " XZS
9n	UR                  U	5        M     UR                  [        R                  " X$S95        M     [        R                  " US9n [        R                  " SS9n[        US9n[        SU R                  5       /[        5       S9n[        [        R                   " SXS9/S9$ )Nr   r   Marginr*  rg   )r   lowerupper)series)titler   r   )r~  	multiline)r~  chart)categoryr    r   r   	DT_STRINGr]   
string_valr   custom_scalars__config__r   r   )r   r  r   MarginChartContentSeriesChartMultilineChartContentr   CategoryLayoutr   r   r	   r   r
   r   r   )layout
categoriesr   r   charts
chart_namechart_metadatatagsmgccr  mlccr   r   r_   s                 r0   r    r      sd   J*+'')&J!!$Da H,4yA~%~!44"55<<"&q'aQ =  #((zG!77DA"((zJMM%  +4  	*--ADE% ( 
3F!,,9IJK
k
2C,,./%'F
 MM8V
 r1   c           
         [         R                  " S[        SS9R                  5       S9n[        US9n[	        SUR                  SS9/[        [        R                  " S	S
9/S9S9n[        [        R                  " U S-   X4S9/S9$ )Nr!   r   )r   r   r   r  utf_8)encodingr   r   r   r  z/text_summaryr   r   )
r   r   r   r   r	   encoder
   r   r   r   )r   r!   r   r   r_   s        r0   r!   r!     s    !,,N1$=$O$O$QK k
2CKKK12%+;+?+?Q+G*HIF
 }}!6TU r1   c	                    US:  a  Sn[         R                  " XX4XV45      n	[        SUS9R                  5       n
[        R
                  " SU
S9n[	        US9n[        SU	R                  S5      R                  5       [        [        R                  " U	R                  S   S	9[        R                  " U	R                  S
   S	9/S9S9n[        [        R                  " XUS9/S9$ )N   r   r   num_thresholds	pr_curvesr   r   rD   r  r   r   r   r]   rE   r   r   r   )rZ   stackr   r   r   r   r	   r
  r7   r
   r   r   r   r   )r   tpfptnfn	precisionrecallr  weightsrs  pr_curve_plugin_datar   r   r_   s                 r0   r#   r#   	  s     88RRY78D,.  ",,)=K k
2C,,r"))+% $$$**Q-8 $$$**Q-8
	F '--CfMNOOr1   c                    [        US5      n[        XX4S9n[        SUS9R                  5       n[        R
                  " SUS9n[	        US9n[        SUR                  S	5      R                  5       [        [        R                  " UR                  S   S
9[        R                  " UR                  S   S
9/S9S9n	[        [        R                  " XU	S9/S9$ )Nr  )r  r  r   r  r  r   r   rD   r  r   r   r   r  r   r   )r   r%   r   r   r   r   r	   r
  r7   r
   r   r   r   r   )
r   r&  predictionsr  r  rs  r  r   r   r_   s
             r0   r$   r$   #  s    -NND -.  ",,)=K k
2C,,r"))+% $$$**Q-8 $$$**Q-8
	F '--CfMNOOr1   c                 z   SnUc  Sn[         R                  " [         R                  " XS-
  -  5      5      nU R                  [         R                  5      nSUS-
  4n[         R
                  " UUUXc-  S9u  p[         R
                  " UUUSU-
  U-  S9u  p[         R                  " US S S2   5      S S S2   n[         R                  " U
S S S2   5      S S S2   nUS   U-
  nUS   U-
  nU[         R                  " XKU-   5      -  nU[         R                  " XKU-   5      -  n[         R                  " XXUU45      $ )NgHz>g      ?r   r   )r   r,  r  r  )	rZ   int32floorr   float64r   r  maximumr  )r&  r  r  r  _MINIMUM_COUNTbucket_indicesfloat_labelshistogram_range
tp_buckets_
fp_bucketsr  r  r  r  r  r  s                    r0   r%   r%   >  s<   N XXbhh{q6H'IJKN==,L.1,-OLL&	MJ LL|#w.	MJ 
:dd#	$TrT	*B	:dd#	$TrT	*B	AB	ABRZZR88I"**^"W55F88RRY788r1   c                    SSK nSSKJn  UR                  " U5      nUR	                  U UUUUR
                  UUS9n	[        SUR                  S5      R                  5       [        [        R                  " UR
                  S   S9[        R                  " UR
                  S   S9[        R                  " UR
                  S	   S9/S
9S9n[        R                  " UR                  X5      UU	S9n
U
$ )a  Create a tensor summary with summary metadata.

Args:
  name: Uniquely identifiable name of the summary op. Could be replaced by
    combination of name and type to make it unique even outside of this
    summary.
  display_name: Will be used as the display name in TensorBoard.
    Defaults to `name`.
  description: A longform readable description of the summary data. Markdown
    is supported.
  tensor: Tensor to display in summary.
  content_type: Type of content inside the Tensor.
  components: Bitmask representing present parts (vertices, colors, etc.) that
    belong to the summary.
  json_config: A string, JSON-serialized dictionary of ThreeJS classes
    configuration.

Returns:
  Tensor summary with metadata.
r   Nr   )json_configrD   r  r   r   rg   r   r  r   )r;   tensorboard.plugins.meshr   	as_tensorcreate_summary_metadatar   r	   r
  r7   r
   r   r   r   get_instance_name)r   display_namedescriptionr_   rj  
componentsr  r;   r   tensor_metadatatensor_summarys              r0   _get_tensor_summaryr  _  s    . 1__V$F66 7 O ..$++-% $$&,,q/: $$&,,q/: $$&,,q/:

F ]]&&t: N r1   c                 :    SnU b  [         R                  " U SS9nU$ )z5Parse and returns JSON string from python dictionary.z{}T)	sort_keys)jsondumps)config_dictr  s     r0   _get_json_configr    s#    Kjj=r1   c                 |   SSK Jn  SSKJn  [	        U5      n	/ n
XR
                  4X8R                  4X(R                  4/nU Vs/ s H  oS   c  M
  UPM     nnUR                  U VVs/ s H  u  pUPM	     snn5      nU H%  u  pU
R                  [        U UUUUUU	5      5        M'     [        U
S9$ s  snf s  snnf )a  Output a merged `Summary` protocol buffer with a mesh/point cloud.

Args:
  tag: A name for this summary operation.
  vertices: Tensor of shape `[dim_1, ..., dim_n, 3]` representing the 3D
    coordinates of vertices.
  faces: Tensor of shape `[dim_1, ..., dim_n, 3]` containing indices of
    vertices within each triangle.
  colors: Tensor of shape `[dim_1, ..., dim_n, 3]` containing colors for each
    vertex.
  display_name: If set, will be used as the display name in TensorBoard.
    Defaults to `name`.
  description: A longform readable description of the summary data. Markdown
    is supported.
  config_dict: Dictionary with ThreeJS classes names and configuration.

Returns:
  Merged summary for mesh/point cloud representation.
r   r  )MeshPluginDatar   )r  r   (tensorboard.plugins.mesh.plugin_data_pb2r  r  VERTEXFACECOLORget_components_bitmaskr   r  r   )r   verticescolorsfacesr  r  r  r   r  r  	summariestensorsr_   rj  r  s                  r0   r&   r&     s    , 2G";/KI	(()	##$	%%&G
 %,EG&ayvGGE004;<G06G<J !(
	
 !( ##% F<s   	B3B3)B8
)blackr  rg   )NNN)NFFr5   )r   NCHW)r   CHWN)r   NN)   )iD  )r  N)NN)[r  loggingrZ  r,   typingr   r   r;   r\   rZ   google.protobufr   $tensorboard.compat.proto.summary_pb2r   r   r   #tensorboard.compat.proto.tensor_pb2r	   )tensorboard.compat.proto.tensor_shape_pb2r
   !tensorboard.plugins.custom_scalarr   ,tensorboard.plugins.pr_curve.plugin_data_pb2r   (tensorboard.plugins.text.plugin_data_pb2r   _convert_npr   _utilsr   r   __all__	getLogger__name__r   r   r   r   r   r   r   r9   r>   r@   halffloat16bfloat16r   r  doubleint8r^   qint8rm  shortr  qint32int64	complex32chalf	complex64cfloatr   
complex128cdoublequint8quint4x2r   ra   r   r   r   r"   r   r   r   r   r   r   r   r   r   r   r    r!   r#   r$   r%   r  r  r&   r   r1   r0   <module>r     s     	      & 
 < F 8 J C   20 
		8	$&5 &S &&3 &5 &:5<< :DI :4ell 4tE{ 4 u||  S	  	JJJ(;<	MMIz+>? 
NN]J0CD 
MMJ_=	
 
KK*k?; 
MMK? 
LL;o> 
JJI7 
KK*i9 
KK*i9 
KK*i9 
KK*i9 
II
I7 
KK*i9 
LL:y/:  
KK*k?;!" 
OOnn6LM#$ 
KK..2HI	OOnn6LM	LL>>3IJ	JJJ8	8NO	MMO^5KL	KK*lO<	LL:|_=	NNZ?5 <5 (Vzz(MV"VJ@B@,4n"@L KO@""4@(V@<"J  IMP4P69B8v OS3$r1   