
    hG                     :    S SK r S SKrSrS rSS jrS rS rS rg)	    Ni    c                    U R                  S5      (       a  U R                  S5      S   nU [        S5      S nUR                  S5      nUS   nUS[        U5      -   S nUS-   U-   n US	:X  aD  SSKnUR	                  S	[
        R                  R                  S
5      S9nUR                  XU5        gUS:X  aJ  SSK	J
n  UR                  5       n	UR                  X5      n
UR                  XZ5      nUR                  U 5        ggg)zMUpload a file to remote cloud storage
if the path starts with gs:// or s3://
)s3://zgs://:r   r   N/   z:/s3S3_ENDPOINT)endpoint_urlgs)storage)
startswithsplitlenboto3clientosenvirongetupload_filegoogle.cloudr   ClientBucketBlobupload_from_filename)
local_pathprefixremote_bucket_pathbpbucketpathr   r   r   r   Hbucketblobs               P/var/www/fran/franai/venv/lib/python3.13/site-packages/tensorboardX/embedding.pymaybe_upload_filer$   	   s     /00!!#&q)'G6%%c*A!!c&k/"23 d]%77
T>d1NOBNN:t4t^,^^%FnnV4G<<.D%%j1  1    c                    U(       d  U  Vs/ s H  n[        U5      PM     n nON[        U5      [        U S   5      :X  d   S5       eU/U -    Vs/ s H  nSR                  S U 5       5      PM     n n[        R                  R                  US5      n[        USSS9 nU  H  nUR                  US	-   5        M     S S S 5        [        U5        g s  snf s  snf ! , (       d  f       N$= f)
Nr   z@len of header must be equal to the number of columns in metadata	c              3   8   #    U  H  n[        U5      v   M     g 7fN)str).0es     r#   	<genexpr>make_tsv.<locals>.<genexpr>*   s     0ac!ffas   metadata.tsvwutf8)encoding
)r*   r   joinr   r    openwriter$   )metadata	save_pathmetadata_headerxl
named_pathfs          r#   make_tsvr>   $   s    $,-HqCFH-?#s8A;'77 	ON	O7 ..9;9 II0a009 	 ; i8J	j#	/1AGGAH  
0 j! .;
 
0	/s   C"CC
C'c                    SS K nSS KnSSKJn  SSKJn  SSKJn  U R                  S   U R                  S   :X  d   S5       eU R                  S   U R                  S   -  U R                  S   -  nUS	-  n[        UR                  XR                  S   -  5      5      n	U" U" U 5      U	S
9n
U
R                  SSS5      nU
R                  S   nU[        ::  d   S5       eUR                  XS45      nXS UR                  S   2S S 2S S 24'   UR                  UR                  US-  R!                  SS5      5      5      n["        R$                  R'                  US5      nUR)                  U5        [+        U5        g )Nr   )Imager   )	make_grid)make_np      z6Image should be square, see tensorflow/tensorboard#670g      ?)ncolsz,Sprite too large, see label_img shape limits   
sprite.png)mathnumpyPILr@   utilsrA   x2numrB   shapeintceil	transposeTB_MAX_SPRITE_SIZEndarray	fromarrayuint8clipr   r    r4   saver$   )	label_imgr8   rH   npr@   rA   rB   total_pixelspixels_one_sidenumber_of_images_per_rowarranged_img_CHWarranged_img_HWCsprite_sizearranged_augment_square_HWCimr<   s                   r#   make_spritera   6   sa     ??1!33m5mm3??1%	(::Y__Q=OOL"c)O"499_q?Q-Q#RS !3;ST'11!Q:"((+K,,\.\\,"$**k-J"KDT :!1!7!7!: :Aq @A	#>#D"J"J1c"RS	TBi6JGGJj!r%   c           	         SSK Jn  [        R                  R                  US5      n[	        US5       nUR                  S5        UR                  SU S[        U5      R                  S5       S	35        UR                  S
R                  U" US5      5      5        U b'  UR                  SR                  U" US5      5      5        Ub  UR                  S5        UR                  SR                  U" US5      5      5        UR                  SUR                  S    S35        UR                  SUR                  S    S35        UR                  S5        UR                  S5        S S S 5        [        U5        g ! , (       d  f       N= f)Nr   )r4   zprojector_config.pbtxtazembeddings {
ztensor_name: "r      z"
ztensor_path: "{}"
tensors.tsvzmetadata_path: "{}"
r/   z	sprite {
zimage_path: "{}"
rG   zsingle_image_dim: rD   r3   rC   z}
)	posixpathr4   r   r    r5   r6   r*   zfillformatrM   r$   )	r7   rW   r8   subdirglobal_steptagr4   r<   r=   s	            r#   append_pbtxtrl   Y   sG   i)ABJ	j#	!	 !	.Qs;'7'='=a'@&AEF	%,,T&--HIJGG+22V^,. / GGL!GG(//V\0JKLGG();(<B?@GG();(<B?@GGEN	 
 j! 
	s   D4E;;
F	c           	      Z   [         R                  R                  US5      n[        US5       nU  HO  nU Vs/ s H  n[	        UR                  5       5      PM     nnUR                  SR                  U5      S-   5        MQ     S S S 5        [        U5        g s  snf ! , (       d  f       N= f)Nre   r0   r'   r3   )r   r    r4   r5   r*   itemr6   r$   )matlistr8   r<   r=   r:   is         r#   make_matrq   n   s    i7J	j#	!A()*1QVVXA*GGDIIaL4'(  
 j! + 
	s   
B#B)BB
B*r)   )r   sysrQ   r$   r>   ra   rl   rq    r%   r#   <module>rt      s-    	 
  26"$ "F"*"r%   