
    
3j/                     |    S SK r S SKrS SKrS SKrS SKrSSKJr  SSKJrJ	r	  Sr
 " S S5      r " S S	5      r\\/rg)
    N   )log)nextAvailable
tensor2pilzI
Absolute paths are kept as is, relatives are from the output directory.
c                   ~    \ rS rSrSr\S 5       rSrSrSr	Sr
        SS\R                  S	\S
\S\S\4
S jjrSrg)MTB_PostshotTrain   mtb/postshotc                     SSS04/ SQSSS.4SS	/S	S
S.4SSSSSS.4SSS[          3S.4SSS04S.SSSSSS.4SSSSS.4SSSSS.4SSSSS.4S S!S"S#S$S.4SS%SS&S.4SS'S([          3S.4S).S*.$ )+NIMAGEtooltipz'These image will get save to disk first)zNeRF LzNeRF MzNeRF SzNeRF XLzNeRF XXL	Splat ADC
Splat MCMCr   z)The radiance field model profile to train)defaultr   allbestz8How to select training images from the source image setsINT      i  z'Number of kSteps to train the model for)r   minmaxr   STRINGoutputzpath to save the project tor   5C:/Program Files/Jawset Postshot/bin/postshot-cli.exe)imagesprofileimage_selecttrain_steps_limitoutput_pathpostshot_clir      z#Specify the index of the GPU to usezOIf image-select best is used, specifies the number of training images to select)r   r   r   @  zhDownscale training images such that their longer edge is at most this value in pixels. Disabled if zero.   z9Maximum number of 2D kFeatures extracted from each image.FLOAT      ?g      ?g       @zfControls how much additional splats are generated during training.Applies only in 'Splat ADC' profile.  zmSets the maximum number of splats (in kSplats) created during training. Applies only in 'Splat MCMC' profile. z'If not empty will also save a ply file.)gpunum_train_imagesmax_image_sizemax_num_featuressplat_densitymax_num_splatsexport_splat_ply)requiredoptional)RELATIVE_NOTICEclss    E/home/wildlama/comfy/ComfyUI/custom_nodes/comfy_mtb/nodes/postshot.pyINPUT_TYPESMTB_PostshotTrain.INPUT_TYPES   sl   
  IJ
 $0#N  FO#)#]! #% ##L	& #+9_<MN  !#Z![3l #$ "#H	 #$ #t% #'  $N# #$ #^% #&$"C	" #' D	# #%E./1	%wEk{
 {	
    r   T)project_file_pathtrain_modelr   r   r   r   r   c                 X
   UR                  S5      (       d  US-  n[        U5      nUR                  R                  SS9  [        R
                  R                  SUR                  S5      -   5      n [        R                  " 5        n/ n[        U5      n[        U5       H_  u  nn [        R                  R                  USUS S35      nUR                  U5        UR!                  U5        UR)                  S5        Ma     U(       d  [+        S5      eUS/nU H  nUR-                  SU/5        M     UR-                  SUSUS['        U5      SUR/                  5       /5        Ub  UR-                  S['        U5      /5        US:  a"  US:X  a  UR-                  S['        U5      /5        US:  a  UR-                  S['        U5      /5        U	S:w  a  UR-                  S['        U	5      /5        US:X  a"  U
S:w  a  UR-                  S['        U
5      /5        US:X  a"  US:w  a  UR-                  S['        U5      /5        U(       a,  [        U5      nUR-                  SUR/                  5       /5        [0        R2                  " S U 35        [4        R6                  " U[4        R8                  [4        R8                  SS!9nSnSn UR:                  R=                  5       nUS":X  a  UR?                  5       b  OU(       a  [A        U5        S#URC                  5       ;   aW   [E        URG                  S$5      S   RG                  S%5      S   RI                  5       5      nUU:  a  UR)                  S5        UnS&URC                  5       ;   aW   [E        URG                  S$5      S   RG                  S%5      S   RI                  5       5      nUU:  a  UR)                  S5        UnGM  URL                  S:w  a!  URO                  5       u  nn[%        S'U 35      e[        R                  RQ                  U5      (       d  [%        S(5      eUR/                  5       4sS S S 5        UR)                  U5        $ ! ["         a   n[%        S	U S
['        U5       35      UeS nAff = f! [*        [J        4 a     GM  f = f! [*        [J        4 a     GM  f = f! , (       d  f       O,= f! ["         a  n[%        S)['        U5       35      eS nAff = f UR)                  U5        g ! UR)                  U5        f = f)*N.pshtTexist_ok   r   image_04dz.pngzFailed to save image z: r   zNo valid images to processtrainz-iz-pz--image-selectz-sz-oz--gpur   z--num-train-imagesz--max-image-sizer#   z--max-num-featuresr   r%   z--splat-densityr   r&   z--max-num-splats--export-splat-plyzRunning )stdoutstderruniversal_newlinesr'   zcamera tracking step%:ztraining radiance field:zPostshot training failed: zOutput file was not createdzTraining failed: ))endswithr   parentmkdircomfyutilsProgressBarsizetempfileTemporaryDirectoryr   	enumerateospathjoinsaveappend	ExceptionRuntimeErrorstrupdate
ValueErrorextendas_posixr   debug
subprocessPopenPIPErD   readlinepollprintlowerintsplitstrip
IndexError
returncodecommunicateexists)selfr   r   r   r   r   r(   r)   r*   r+   r,   r-   r.   r    pbartemp_dirimage_paths
images_piliimgimg_pathecmdprocesslast_step_clast_step_tr   current_step_rE   s                                 r4   r:   MTB_PostshotTrain.train_model   s     ##G,,7"K#K0  $ /{{&&sV[[^';<k	+,,.( '/
'
3FAs!#%77<<F1S':N#O*#**84
 KKN 4 #$%ABB#W- +HJJh/0 !, 

($-.#,,.	 ?JJS23#a'LF,BJJ 4c:J6KLM!A%JJ 2C4GHI#q(JJ 4c:J6KLMk)ms.BJJ 13}3EFGl*~/EJJ 2C4GHI#'45E'F$JJ-/?/H/H/JK 		HSE*+$**%??%??'+	  $^^446F|(Bf1V\\^C	)/2$*LL$5a$8$>$>s$CA$F$L$L$N0" $0+#=$(KKN2>K
 6G	)/2$*LL$5a$8$>$>s$CA$F$L$L$N0" $0+#=$(KKN2>K3 < %%* ' 3 3 5IAv&)CF8'LMMww~~k22&'DEE#,,.0K /.T KK)*E % !*3A3bQA !!N %/
#; ) () %/
#; ) ()w /.N  	=!23q6(;<<	=O /T KK)*DKK)*s   2S S	'AQ,.H.S	AR3S	AR1A3S		S ,
R6RRS	R.)S	-R..S	1SS	SS		
SS T S 
T $S;;T  T T) N)r   r   r"   r#   r%   r&   r'   r'   )__name__
__module____qualname____firstlineno__CATEGORYclassmethodr5   RETURN_TYPESOUTPUT_NODERETURN_NAMESFUNCTIONtorchTensorrZ   rg   r:   __static_attributes__r~   r7   r4   r   r      s    H|
 |
| LK)LH C+C+ C+ 	C+
 C+ C+ C+r7   r   c                   N    \ rS rSrSrSr\S 5       rSrSr	Sr
S\S	\S
\4S jrSrg)MTB_PostshotExporti  r
   Tc                 ,    SSSSS.4SSS04SSS04S	.0$ )
Nr/   r   r'   T)r   
forceInputr   z
output.plyr   )project_filer.   r    r~   r2   s    r4   r5   MTB_PostshotExport.INPUT_TYPES!  sH      "$7! &.	</H$I!#Z!
 	
r7   r8   )exported_ply_pathexport_modelr   r.   r    c                    UR                  S5      (       d  [        S5      e[        R                  R	                  U5      (       d  [        SU 35      eUR                  S5      (       d  US-  n[        U5      nUR                  R                  SS9  USSUS	UR                  5       /n [        R                  " USSSS
9nUR	                  5       (       d  [        R                  " S5        UR                  5       4$ ! [        R                   a  n[        SUR                    35      eS nAf["         a  n[        S[%        U5       35      eS nAff = f)Nr<   z&Project file must have .psht extensionzProject file not found: z.plyTr=   exportz-frC   )checkcapture_outputtextzExport file was not createdzExport failed: )rI   r\   rS   rT   rm   FileNotFoundErrorr   rJ   rK   r^   r`   runr   errorCalledProcessErrorrY   rE   rX   rZ   )rn   r   r.   r    _export_splat_plyrw   _resultrv   s           r4   r   MTB_PostshotExport.export_model7  sA    $$W--EFFww~~l++#&>|n$MNN((00&)*:;  &&&5  &&(
	; nn44G %++--		78%..022,, 	=
;<< 	;Q9::	;s%   *AC= =ED))E6EEr~   N)r   r   r   r   r   r   r   r5   r   r   r   rZ   r   r   r~   r7   r4   r   r     sL    HK
 
" L)LH%;%;36%;FI%;r7   r   )rS   r`   rP   comfy.utilsrL   r   r   rM   r   r   r1   r   r   	__nodes__r~   r7   r4   <module>r      sF    	      -
J+ J+Z?; ?;D  !23	r7   