
    6bix                     
   S r SSKrSSKrSSKJs  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  SS
KJr  SSKJr   SSKJr  SSSSSSSSSSSSSS\R:                  SSS4S jrS rS r S r!S r"SS jr#SS jr$S r%S r&\RN                  " \\R:                  S9r(\RN                  " \\RR                  SS9r*\RN                  " \\RV                  SS9r, " S S\RZ                  5      r.g! \ a    Sr Nf = f)zAPart of the TF-Keras training engine related to plain array data.    N)backend)	callbacks)distributed_training_utils_v1)training_utils_v1)io_utils)make_batches)slice_arrays)ModeKeys)
tf_logging)issparse   TFstepsc                 P   SU;   a  UR                  S5      nU(       a  [        SU 35      eSnSn[        U[        R                  R
                  R                  R                  [        R                  R                  45      nU(       a2  Uc  Sn[        R                  " U UUUUS9n[        XR                  5      nU R                  (       aE  [        R                  " U R                  U[        R                  :X  a  SOSS	9nUR!                  5         U=(       d    USLnUSLnU=(       d    UnU(       a
  U(       a  UnO[#        XX#U5      nU(       d  [%        UXM5      nOUn['        U UU5        [)        U U5      nSn[        U[        R                  R
                  R                  R                  [        R                  R                  45      (       aO  Uc  [        R                  " U UUUS
S9n[        XR                  5      n[#        U UX[        R*                  5      nUnOAU=(       a/    [        R,                  R/                  U5      S   R0                  S   =(       d    SnU[        R                  :X  a  U(       a  [3        UUU5        U(       a  SOSn [4        R6                  " UU UUUUUU UUS9
n[8        bw  U(       dp  / n![;        U U5      n"[=        [?        UU"5      5       HI  u  n#u  n$n%[9        U$5      (       d  M  [@        RB                  " U%5      (       a  M8  U!RE                  U#5        MK     U[        RF                  :X  a   [        RH                  " UU(       a  SOUUS9n&O[        RJ                  " UU(       a  SOUUS9n&U RL                  (       a  [        RN                  " U U5        SURP                  l)        URU                  U5        U RW                  UU5      n[Y        X5       GH  n'URP                  RR                  (       a    GO0 n(U[        RF                  :w  a  U R[                  5         U[        R                  :X  a  UR]                  U'U(5        U(       GaP  Uc  [^        R`                  n)OUn)Sn*U*U):  Ga/  U*SS.n+URc                  USU*U+5         [e        U5      (       a,  U R                  (       a  [        Rf                  " U 5      (       d  Un,OU" 5       n,U" U,5      n-[        U-[r        5      (       d  U-/n-U R                  (       a#  [        Rt                  " U R                  U-U U5      n-U*S:X  a  U&Rw                  U-5        U&Ry                  U-5        UR{                  U U+U-U5      n+URc                  USU*U+5        U*S-  n*URP                  RR                  (       a  GOU*U):  a  GM/  GO[^        R|                  " U5      n.US:X  a  [        R~                  " U.U5      n.O&U(       a  [^        R                  R                  U.5        [        UU5      n/[=        U/5       GH<  u  n0u  n1n2U.U1U2 n3[        U/5      S:X  a  Un4OD U(       a/  [        US   [        5      (       a  [        USS U35      US   /-   n4O[        UU35      n4 [8        b  W! H  n#U4U#   R                  5       U4U#'   M     U0[        U35      S.n+URc                  USU0U+5        U" U45      n-[        U-[r        5      (       d  U-/n-U0S:X  a  U&Rw                  U-5        U&Ry                  U-U1U25        UR{                  U U+U-U5      n+URc                  USU0U+5        URP                  RR                  (       d  GM=    O   U&R                  5         U&R                  n5UR{                  U U(U5U5      n([        U55      S:X  a  U5S   n5U(       a  [        R                  " UU'5      (       a  URP                  RR                  (       d  U RL                  (       a%  [        R                  " U [        R                  5        [        U UU	U
UUUS[        R*                  SUSLS
S9n6[        U6[r        5      (       d  U6/n6UR{                  U U(U6USS9n(U(       a  U'US-
  :  a  [        UU R                  5        U[        R                  :X  a  UR                  U'U(5        U(       d  GM  U'US-
  :  d  GM  [        UU R                  5        GM     SU lN        UR                  U5        U R                  (       a;  U RL                  (       a  [        R                  " U U5        WR                  SSS5        U[        R                  :X  a  U R                  $ W5$ ! [        Rh                  Rj                   a    U(       aF  U(       a/  SURP                  l)        [l        Rn                  " SUX-  4-  5        O>U*S:  a	  U*nUU&l8        O.SURP                  l)        [l        Rn                  " SUX-  4-  5         GM  f = f! [         a    [        S5      ef = f)a_  Loop function for arrays of data with modes TRAIN/TEST/PREDICT.

Args:
    model: TF-Keras Model instance.
    inputs: Either a list or dictionary of arrays, or a dataset instance.
    targets: List/dictionary of input arrays.
    sample_weights: Optional list of sample weight arrays.
    batch_size: Integer batch size or None if unknown.
    epochs: Number of times to iterate over the data
    verbose: 0, 1, or 2. Verbosity mode.
      0 = silent, 1 = progress bar, 2 = one line per epoch.
      Note that the progress bar is not particularly useful when
      logged to a file, so verbose=2 is recommended when not running
      interactively (eg, in a production environment).
    callbacks: List of callbacks to be called during training
    val_inputs: Either a list or dictionary of arrays, or a dataset
      instance.
    val_targets: List/dictionary of target arrays.
    val_sample_weights: Optional list of sample weight arrays.
    shuffle: Whether to shuffle the data at the beginning of each epoch
      concatenation of list the display names of the outputs of `f` and the
      list of display names of the outputs of `f_val`.
    initial_epoch: Epoch at which to start training (useful for resuming a
      previous training run)
    steps_per_epoch: Total number of steps (batches of samples) before
      declaring one epoch finished and starting the next epoch. Ignored with
      the default value of `None`.
    validation_steps: Number of steps to run validation for (only if doing
      validation from data tensors). Ignored with the default value of
      `None`.
    validation_freq: Only relevant if validation data is provided. Integer
      or `collections.abc.Container` instance (e.g. list, tuple, etc.). If
      an integer, specifies how many training epochs to run before a new
      validation run is performed, e.g. `validation_freq=2` runs validation
      every 2 epochs. If a Container, specifies the epochs on which to run
      validation, e.g. `validation_freq=[1, 2, 10]` runs validation at the
      end of the 1st, 2nd, and 10th epochs.
    mode: One of ModeKeys.TRAIN/ModeKeys.TEST/ModeKeys.PREDICT.
    validation_in_fit: if true, then this method is invoked from within
      training iteration (for validation). In the case where `val_inputs` is
      a dataset, this flag indicates that its iterator and feed values are
      already created so should properly reuse resources.
    prepared_feed_values_from_dataset: if True, `inputs` is a list of feed
      tensors returned from `_prepare_feed_values` call on the validation
      dataset, so do not call it again on `inputs`. Should only be used for
      inline validation (i.e., only if `validation_in_fit` is also True).
    steps_name: The string name of the steps argument, either `steps`,
      `validation_steps`, or `steps_per_epoch`. Only used for error message
      formatting.
    **kwargs: Additional arguments for backwards compatibility.

Returns:
    - In TRAIN mode: `History` object.
    - In TEST mode: Evaluation metrics.
    - In PREDICT mode: Outputs of the Model called on inputs.

Raises:
    ValueError: in case of invalid arguments.
r   zUnknown arguments: FNT)epochs
steps_namer   r   )strategylearning_phasevalidation_stepssamples)do_validation
batch_sizer   steps_per_epochr   
count_modeverbosemode)num_samplesr   )batchsizebeginzYour dataset ran out of data; interrupting training. Make sure that your dataset can generate at least `%s * epochs` batches (in this case, %d batches). You may need to use the repeat() function when building your dataset.zYour dataset iterator ran out of data; interrupting training. Make sure that your iterator can generate at least `%s * epochs` batches (in this case, %d batches). You may need to use the repeat() function when building your dataset.endr   zPTypeError while preparing batch. If using HDF5 input data, pass shuffle="batch".)
targetssample_weightsr   r   r   r   r   validation_in_fit!prepared_feed_values_from_datasetr   val_)prefix)Rpop	TypeError
isinstancetfcompatv1dataDatasetr   infer_steps_for_dataset_get_iterator_distribution_strategyr   distributed_scoper
   TRAIN	__enter___prepare_feed_values_get_num_samples_or_steps_update_sample_weight_mode_make_execution_functionTESTnestflattenshape_print_train_infocbksconfigure_callbacksr   _get_model_feed	enumeratezipr   	is_sparseappendPREDICTOutputsAggregatorMetricsAggregator_compile_distribution"_copy_weights_to_distributed_modelmodelstop_training_call_begin_hook#_maybe_load_initial_epoch_from_ckptrangereset_metricson_epoch_beginnpinf_call_batch_hookcallableis_distributing_by_cloningerrorsOutOfRangeErrorloggingwarningr   list_per_replica_aggregate_batchcreate	aggregate	make_logsarangebatch_shufflerandomshuffler   lenintr	   toarrayfinalizeresultsshould_run_validation_copy_weights_to_original_modelmodel_iteration_reinitialize_iteratoron_epoch_end_successful_loop_finish_call_end_hook__exit__history)7rK   inputsr"   r#   r   r   r   r   
val_inputsval_targetsval_sample_weightsrc   initial_epochr   r   validation_freqr   r$   r%   r   kwargsreset_dataset_after_each_epochinput_iterator
is_datasetscope	use_stepsr   insnum_samples_or_stepsfval_iteratorval_samples_or_stepsr   indices_for_conversion_to_densefeedi
input_datafeed_tensor
aggregatorepoch
epoch_logstarget_stepsstep
batch_logsactual_inputs
batch_outsindex_arraybatchesbatch_indexbatch_start	batch_end	batch_ids	ins_batchrh   val_resultss7                                                          `/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/engine/training_arrays_v1.pyrk   rk   )   sn	   f & **W--fX677 &+"N""**BGGOO<J "-1*/GG%O 'v/K/KL ##-??11!%!7AQ
 	9oT9Id*M %vF>
 "5'4P 8 
  / udC0
 	!-A L*ryy||0088"''//JKK#
  1HH -  %Z1M1MN)<(--

  0 B277??:6q9??BJd 	 x~~' "6
	

 &9J((#'$I I*,'ud+,5c#tn,E(A(
K
##G,=,=k,J,J/66q9 -F
 x&88 /5I!

 '88 /5I!

 ""%HH4	
 %*IOO!t$==tM }-??(( 
8### !8>>!$$UJ7&!vv  /D%'+Q7
**4$
K. $C==44 = X X!! ! ),(+!"=!1JH "*d33",J//!>![![44j%"J
 19%%j1$$Z0 '00:z4
 **4jI	??00U %Z ))$89K'!/== 		!!+."#7DG9B79K55k9'I>	w<1$
 !$I:c"gs#;#;(4S"Xy(I #BM )I )5S)(DI '<'0|';';'=	! = (3C	NK
**';

 y\
!*d33",J !#%%j1$$ZiH '00:z4
 **4ZP??000k :Ln 	$$((
GTJ
w<1ajG !77OOOO11** .MM8>> *#1% 0#]]"&3?t3K-K k400*m",,z;V - J 
 2& %">"> 8>>!""5*5 *)efqj.@">53O3OPk .n %)E!T"##&& *IIt 	tT4(x~~}}Ny yy00 !! +<@IOO9#OO!+ $./G"H!I "AX.2O/>J, 9=	5'
 +5o6N)OP C!j % '4 s&   Ae.5h;h.Bhhh%c                     U[         R                  :X  a  U R                  nU$ U R                  U R                  -   U R                  -   nU$ N)r
   rF   _feed_inputs_feed_targets_feed_sample_weights)rK   r   r   s      r   rA   rA     sU    x!! K	 !!"(() 	
 K    c                 z    U(       a  SOSnSU  SU 3nU(       a  USU SU 3-  n[         R                  " U5        g )Nr   r   z	Train on  z, validate on )r   	print_msg)r   r   r{   	incrementmsgs        r   r>   r>     sI    %9I*+1YK
8C 45QykBBsr   c                 D    U(       a  U$ [         R                  " XUS5      $ )zEReturns total number of samples when training in batch mode or steps.r   )r   check_num_samples)r~   r   r   s      r   r7   r7     s&    ..*; r   c                   ^ ^^^^ T R                   (       a  [        T[        R                  R                  R
                  R                  [        R
                  R                  45      (       a!  [        R                  " TT R                   5      mUUU UU4S jn[        R                  " 5       (       a  U$ U" 5       $ [        T[        R                  R                  R
                  R                  [        R
                  R                  [        R                  R                  R
                  R                  45      (       a  T R                  TSS9u  mmm[        R                  " T5      R                  5       m[        T=(       d    / 5      m[        T=(       d    / 5      mTT-   T-   nT[         R"                  :X  a.  [        [$        R&                  " 5       [(        5      (       d  US/-  nU$ )aj  Prepare feed values to the model execution function.

Args:
  model: Model to prepare feed values for.
  inputs: List or dict of model inputs.
  targets: Optional list of model targets.
  sample_weights: Optional list of sample weight arrays.
  mode: One of ModeKeys.TRAIN/ModeKeys.TEST/ModeKeys.PREDICT.

Returns:
  Feed values for the model in the given mode.
c                  8   > [         R                  " TT TTT5      $ r   )r   r6   )rr   r   rK   r#   r"   s   r   get_distributed_inputs4_prepare_feed_values.<locals>.get_distributed_inputs,  s!    0EEvw r   T)extract_tensors_from_dataset)r2   r*   r+   r,   r-   r.   r/   r   get_iteratorexecuting_eagerlyIterator_standardize_user_datar   ModelInputsas_listr[   r
   r4   r   symbolic_learning_phasere   )rK   rr   r"   r#   r   r   r~   s   `````  r   r6   r6     sr    ##fryy||0088"''//JKK2??44F	 	 !!)))++IILL%%GGOOIILL&&	
  +0*F*F +G +
' **62::<F7=b!G..B/N
7
^
+Cx~~j'')3' ' 	vJr   c                 h    U(       a  [         R                  " X5      $ [        R                  " U 5      $ r   )r   r   r   )rr   distribution_strategys     r   r1   r1   T  s.    ,99
 	
 ))&11r   c                 l    U(       a  [         R                  " X5        g [        R                  " U 5        g r   )r   initialize_iteratorr   )iteratorr   s     r   rl   rl   \  s&    %99	
 	--h7r   c                 r    U R                   (       a  [        R                  " X5      $ U R                  U5      $ )z2Makes function to run one step of model execution.)r2   r   r9   )rK   r   s     r   r9   r9   e  s4    ##,EE
 	
 ))$//r   c                    U[         R                  :X  a  gSn[        U5      (       d  U[        U R                  5      [        U R
                  5      -   S nU[         R                  :H  =(       a(    [        [        R                  " 5       [        5      (       + nU(       a  USS nU R                  US9  U R                  (       a  [        R                  " XU5        gg)z0Updates the sample_weight_mode of a given model.Nr!   )r#   )r
   rF   rU   rd   r   r   r4   r*   r   r   re   _update_sample_weight_modesr2   r   )rK   r   rr   r#   has_learning_phase_pls        r   r8   r8   n  s    
 xN
 F""#c%*=*=&>>@
 !% 6 !
z++-s@
 <
 !+CR0N)))H ##%AA	
 $r   )r   )r   rc   c                   j    \ rS rSrSr               SS jr       S	S jr    S
S jrSrg)ArrayLikeTrainingLoopi  a)  TrainingLoop that handle inputs like array.

This is the default handler for most of the input data types, includes
symbolic tensors or Numpy array-like, Datasets and iterators in graph mode
(since they generate symbolic tensors). This Function is used to handle
model with `run_eagerly` = False.
Nc                    UR                  XNU5      nUR                  UUUUUSSUUU
S9
u  p#nU	(       a  UR                  XU5      u  nnnOOU(       a0  SUs=:  a  S:  a#  O  O [        R                  " X#UU5      u  nnnnnnOU(       a  [        S5      eSu  nnn[        U40 SU_S	U_S
U_SU_SU_SU_SU_SU_SU_SU_SU
_SU_SU_SU_SU_SS_6$ )NTr   )sample_weightclass_weightr   check_stepsr   r   validation_splitrc           g      ?zH`validation_steps` should not be specified if `validation_data` is None.)NNNrr   r"   r#   r   r   r   r   rs   rt   ru   rc   rv   r   rw   r   )_validate_or_infer_batch_sizer   _prepare_validation_datar   "split_training_and_validation_data
ValueErrorfit_loop)selfrK   xyr   r   r   r   r   validation_datarc   r   r   rv   r   r   rw   rx   r#   val_xval_yru   s                         r   fitArrayLikeTrainingLoop.fit  s   ( 88

  %;;'%!(!-  <  
n /4/M/M-=0,E5, #(8">3"> "DDn&6"
   1  0@,E5,

 
 *	

 "
 
 
  
 
 
  2
 
 (
 ,
 .
  ,!
" )#
 	
r   c	                 v    UR                  XGU5      nUR                  UUUUSSUS9u  p#n
[        UUUU
UUUUS9$ )NTr   )r   r   r   r   r   )rr   r"   r#   r   r   r   r   )r   r   	test_loop)r   rK   r   r   r   r   r   r   r   rx   r#   s              r   evaluateArrayLikeTrainingLoop.evaluate  sl     88AN
$;;'!  <  
n )!	
 		
r   c           	      n    UR                  X5U5      nUR                  USSUS9u  n  n[        UUUUUUS9$ )NTr   )r   r   r   )r   r   r   r   )r   r   predict_loop)	r   rK   r   r   r   r   r   rx   _s	            r   predictArrayLikeTrainingLoop.predict  s[     88AN
..4G5 / 
1a !
 	
r    )NNNr   r   Nr   NTNNr   NNr   )NNNr   NNN)Nr   NN)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__r   r   r   r   r     sm     
#N
f 

J 
r   r   r   )/r   	functoolsnumpyrR   tensorflow.compat.v2r,   v2r+   tf_keras.srcr   r   r?   tf_keras.src.distributer   tf_keras.src.enginer   tf_keras.src.utilsr    tf_keras.src.utils.generic_utilsr   r	   tf_keras.src.utils.mode_keysr
   tensorflow.python.platformr   rY   scipy.sparser   ImportErrorr4   rk   rA   r>   r7   r6   r1   rl   r9   r8   partialr   r:   r   rF   r   TrainingLoopr   r   r   r   <module>r      s'   H   ! !   * A 1 ' 9 9 1 =% 	&+)Pf	8v280
B _8>>B(--	   (**E
O
-:: O
g  Hs   C7 7DD