
    ~WhL                     J   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z
ddlZddlmc mZ ddlmZ ddlmZ ddlmZ d ZddZdd	Z ed
           G d d                      Zd ZddZd Zd Zd Zd Z	 ddZ d Z!d Z"d Z# G d de
j$                  Z%dS )z#Python utilities required by Keras.    N)io_utils)
tf_inspect)keras_exportc                    t           j        dk    rVt          j        | j                                      dd          }t          j        |d                              d          }nAt          j        | j                  }t          j        |d                              d          }| j	        }| j
        rt          d | j
        D                       }nd}|||fS )zSerializes a user defined function.

    Args:
        func: the function to serialize.

    Returns:
        A tuple `(code, defaults, closure)`.
    nt   \   /base64asciic              3   $   K   | ]}|j         V  d S N)cell_contents).0cs     _/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/keras/utils/generic_utils.py	<genexpr>zfunc_dump.<locals>.<genexpr>6   s$      BBABBBBBB    N)osnamemarshaldumps__code__replacecodecsencodedecode__defaults____closure__tuple)funcraw_codecodedefaultsclosures        r   	func_dumpr%   %   s     
w$=//77tDD}Xx0077@@=//}Xx0077@@ H BB1ABBBBB7""r   c                 
   t          | t          t          f          r*| \  } }}t          |t                    rt          |          }d |t          fd|D                       }	 t          j        |                     d          d          }n1# t          t          j        f$ r |                     d          }Y nw xY wt          j
        |          } |t                      }t          j        | || j        ||          S )a	  Deserializes a user defined function.

    Args:
        code: bytecode of the function.
        defaults: defaults of the function.
        closure: closure of the function.
        globs: dictionary of global objects.

    Returns:
        A function object.
    c                 j      fd}|j         d         }t           t          |                    s|S  S )zEnsures that a value is converted to a python cell object.

        Args:
            value: Any value that needs to be casted to the cell type

        Returns:
            A value wrapped as a cell object (see function "func_load")
        c                        d S r    )values   r   dummy_fnz9func_load.<locals>.ensure_value_to_cell.<locals>.dummy_fnW   s    EEEr   r   )r   
isinstancetype)r*   r+   
cell_values   `  r   ensure_value_to_cellz'func_load.<locals>.ensure_value_to_cellM   sP    	 	 	 	 	 )!,
%j!1!122 	r   Nc              3   .   K   | ]} |          V  d S r   r)   )r   _r/   s     r   r   zfunc_load.<locals>.<genexpr>a   s/      AAA,,Q//AAAAAAr   r   r
   raw_unicode_escape)r   argdefsr$   )r,   r   listr   r   r   UnicodeEncodeErrorbinasciiErrorr   loadsglobalspython_typesFunctionTypeco_name)r"   r#   r$   globsr!   r/   s        @r   	func_loadr>   <   s    $&& '"&hh%% 	'XH  & AAAAAAAAA5=W!5!5x@@/ 5 5 5;;3445=""D}		$e$,'   s   )(B +C ?C Fc                 d    t          j        |           }|r	|j        dS ||j        v p||j        v S )a  Checks if a callable accepts a given keyword argument.

    Args:
        fn: Callable to inspect.
        name: Check if `fn` can be called with `name` as a keyword argument.
        accept_all: What to return if there is no parameter called `name` but
          the function accepts a `**kwargs` argument.

    Returns:
        bool, whether `fn` accepts a `name` keyword argument.
    NT)r   getfullargspecvarkwargs
kwonlyargs)fnr   
accept_allarg_specs       r   has_argrG   n   sB     (,,H hn0t8= ?DH,?$??r   zkeras.utils.Progbarc                   F    e Zd ZdZ	 	 	 	 	 ddZddZdd	Zd
 Zd Zd Z	dS )Progbara[  Displays a progress bar.

    Args:
        target: Total number of steps expected, None if unknown.
        width: Progress bar width on screen.
        verbose: Verbosity mode, 0 (silent), 1 (verbose), 2 (semi-verbose)
        stateful_metrics: Iterable of string names of metrics that should *not*
          be averaged over time. Metrics in this list will be displayed as-is.
          All others will be averaged by the progbar before display.
        interval: Minimum visual progress update interval (in seconds).
        unit_name: Display name for step counts (usually "step" or "sample").
          皙?Nstepc                    || _         || _        || _        || _        || _        |rt          |          | _        nt                      | _        t          t          j	        d          rt          j	        
                                p)dt          j        v pdt          j        v pdt          j        v | _        d| _        d| _        i | _        g | _        t'          j                    | _        d| _        | j        | _        d | _        d | _        d S )Nisatty	ipykernelposixPYCHARM_HOSTEDr   )targetwidthverboseinterval	unit_namesetstateful_metricshasattrsysstdoutrO   modulesr   environ_dynamic_display_total_width_seen_so_far_values_values_ordertime_start_last_update_time_at_epoch_start_time_at_epoch_end_time_after_first_step)selfrS   rT   rU   rV   rY   rW   s          r   __init__zProgbar.__init__   s    
 " 	*$'(8$9$9D!!$'EED! SZ**Bsz/@/@/B/B .ck).#+%.  2:-	 	  ikk$(K!"&&*###r   c           	      6
   || j         d}n|| j         k    }|pg }|D ]\  }}|| j        vr| j                            |           || j        vrkt	          || j        z
  d          }|| j        vr||z  |g| j        |<   b| j        |         dxx         ||z  z  cc<   | j        |         dxx         |z  cc<   |dg| j        |<   || _        d}t          j                    }d|| j        z
  dd}	|| j         k    r|| _	        | j
        dk    r|| j        z
  | j        k     r|sdS | j        }
| j        r|d	|
z  z  }|d
z  }n|dz  }| j         t          t!          j        | j                             dz   }dt%          |          z   dz   || j         fz  }t'          |          | j         z  }t          | j        |z            }|dk    r!|d|dz
  z  z  }|| j         k     r|dz  }n|dz  }|d| j        |z
  z  z  }|dz  }nd|z  }t+          |          | _        ||z  }|                     ||          }| j         |r|	|                     || j                  z  }	nF|| j         |z
  z  }|dk    rd|dz  |dz  dz  |dz  fz  }n|dk    rd|dz  |dz  fz  }nd|z  }d| }	| j        D ]}|	d| dz  }	t3          | j        |         t4                    rnt!          j        | j        |         d         t	          d| j        |         d                   z            }t9          |          dk    r
|	d|dz  }	|	d|dz  }	|	d| j        |          z  }	| xj        t+          |	          z  c_        |
| j        k    r|	d|
| j        z
  z  z  }	|r|	dz  }	||	z  }t;          j        |d           d}n\| j
        dk    rP|rMt          t!          j        | j                             dz   }dt%          |          z   d z   || j         fz  }||	z   }	| j        D ]k}|	d| dz  }	t!          j        | j        |         d         t	          d| j        |         d                   z            }|dk    r
|	d|dz  }	b|	d|dz  }	l| j	        ri| j	        | j        z
  }|| j         z  }|| _        d| _	        |	d!|                     |d"          z   z  }	|	d!|                     || j                  z   z  }	|	dz  }	||	z  }t;          j        |d           d}|| _        dS )#a  Updates the progress bar.

        Args:
            current: Index of current step.
            values: List of tuples: `(name, value_for_last_step)`. If `name` is
              in `stateful_metrics`, `value_for_last_step` will be displayed
              as-is. Else, an average of the metric over time will be
              displayed.
            finalize: Whether this is the last update for the progress bar. If
              `None`, defaults to `current >= self.target`.
        NFrK   r    z - .0fs
%zd/%d [=>.]z%7d/Unknowni  z%d:%02d:%02d<   z%d:%02dz%dsz - ETA: :MbP? z.4fz.4e)
line_break   zd/%dz -epoch) rS   rc   appendrY   maxra   rb   rd   re   rh   rU   rf   rV   r`   r_   intnplog10strfloatrT   len_estimate_step_duration_format_timerW   r,   r4   meanabsr   	print_msgrg   )rj   currentvaluesfinalizekv
value_basemessagenowinfoprev_total_width	numdigitsbarprog
prog_widthtime_per_uniteta
eta_formatavgcounttime_per_epochavg_time_per_steps                         r   updatezProgbar.update   sT    {" "dk12 	) 	)DAq***"))!,,,--- !4+<!<a@@
DL(('(:~z&BDLOOLOA&&&!j.8&&&LOA&&&*4&&&&
 $%a&Q#ikk-S4;&----dk!!&)D#<1T&&66x6#0$  4"22244{& 5 566:	S^^+h67DK:PPW~~3 d!233
>>3*q.11C,,s
s
sdj:566s
#g- #CDsNG 88#FFM{"h"))-HHH#t{W'<=::!/tt*b3 "JJ
 2XX!*cRir-B!BJJ!&J.*..' 2 2
a


"dl1ot44 	2'Q*SDLOA4F-G-GG C 3xx$C-C-1Q111DDT*$"333/$2CCDD tOGw59999GG\Q  5 566:	s9~~-67DK:PPt|+ . .AJ!JJJ&D'Q*SDLOA4F-G-GG C TzzC-C-* !/$2KK # )7(D%03D-.2D+D4#4#4^W#M#MMMDD4#4#4)4>$ $  D DLD4"7u====r   c                 B    |                      | j        |z   |           d S r   )r   ra   )rj   nr   s      r   addzProgbar.addK  s$    D%)622222r   c                     d}|dk    s|dk    r|d|dd| z  }n%|dk    r|d|dz  dd	| z  }n|d|d
z  dd| z  }|S )a  format a given duration to display to the user.

        Given the duration, this function formats it in either milliseconds
        or seconds and displays the unit (i.e. ms/step or s/epoch)
        Args:
          time_per_unit: the duration to display
          unit_name: the name of the unit to display
        Returns:
          a string with the correctly formatted duration and units
        rm   rK   r   r{   rn   zs/rz   g     @@zms/g    .Azus/r)   )rj   r   rW   	formatteds       r   r   zProgbar._format_timeN  s     	A!!3!3=]===)===IId""G]V3GGGIGGGIIJ]Y6JJJyJJJIr   c                 ~    |r:| j         |dk    r|| j         z
  |dz
  z  }n|| j        z
  |z  }|dk    r|| _         |S dS )a  Estimate the duration of a single step.

        Given the step number `current` and the corresponding time `now` this
        function returns an estimate for how long a single step takes. If this
        is called before one step has been completed (i.e. `current == 0`) then
        zero is given as an estimate. The duration estimate ignores the duration
        of the (assumed to be non-representative) first step for estimates when
        more steps are available (i.e. `current>1`).

        Args:
          current: Index of current step.
          now: The current time.

        Returns: Estimate of the duration of a single step.
        NrK   r   )ri   re   )rj   r   r   r   s       r   r   zProgbar._estimate_step_durationb  si       	 *67Q;;!$t'B!BaK! "%t{!2g =!||.1+  1r   c                 D    | j                             |          | _         d S r   )rY   union)rj   rY   s     r   _update_stateful_metricsz Progbar._update_stateful_metrics  s"     $ 5 ; ;<L M Mr   )rJ   rK   rL   NrM   NNr   )
__name__
__module____qualname____doc__rk   r   r   r   r   r   r)   r   r   rI   rI      s           #+ #+ #+ #+JU  U  U  U n3 3 3 3  (" " "HN N N N Nr   rI   c                      t          t          j         t                    z                      } fdt	          d|          D             S )zReturns a list of batch indices (tuples of indices).

    Args:
        size: Integer, total size of the data to slice into batches.
        batch_size: Integer, batch size.

    Returns:
        A list of tuples of array indices.
    c                 F    g | ]}|z  t          |d z   z            fS )rK   )min)r   i
batch_sizesizes     r   
<listcomp>z make_batches.<locals>.<listcomp>  sE        
ZTAEZ#7889  r   r   )r   r   ceilr   range)r   r   num_batchess   `` r   make_batchesr     sd     bgdU:%6%667788K    q+&&   r   c                    | dgS t          t                    rt          d d           t          | t                    rQt          d          r2t          d          r                                fd| D             S fd| D             S t          d          r,t          d          r                                |          S t          d          r
|          S dgS )	a  Slice an array or list of arrays.

    This takes an array-like, or a list of
    array-likes, and outputs:
        - arrays[start:stop] if `arrays` is an array-like
        - [x[start:stop] for x in arrays] if `arrays` is a list

    Can also work on list/array of indices: `slice_arrays(x, indices)`

    Args:
        arrays: Single array or list of arrays.
        start: can be an integer index (start index) or a list/array of indices
        stop: integer (stop index); should be None if `start` was a list.

    Returns:
        A slice of the array(s).

    Raises:
        ValueError: If the value of start is a list and stop is not None.
    NzQThe stop argument has to be None if the value of start is a list. Received start=z, stop=__len__shapec                 (    g | ]}|d n|         S r   r)   )r   xstarts     r   r   z slice_arrays.<locals>.<listcomp>  s%    DDDAIDD1U8DDDr   c                 P    g | ]"}|d nt          |d          sd n	|         #S )N__getitem__)rZ   )r   r   r   stops     r   r   z slice_arrays.<locals>.<listcomp>  sW     
 
 
 	 y D 1m,,5:
 
 
r   r   )r,   r4   
ValueErrorrZ   tolist)arraysr   r   s    ``r   slice_arraysr     sQ   * ~v% 4#3>).> >7;> >
 
 	
 
FD	!	! 5)$$ 	Eug&& 'DDDDVDDDD
 
 
 
 
 
 
 
 	
 5)$$ 	!ug&& '%= 5-(( 	&%*%%vr   c                 6    t          | t                    r| S | gS )zNormalizes a list/tensor into a list.

    If a tensor is passed, we return
    a list of size 1 containing the tensor.

    Args:
        x: target object to be normalized.

    Returns:
        A list.
    )r,   r4   )r   s    r   to_listr     s"     !T 3Jr   c                     t          j        dd|           }t          j        dd|                                          }|d         dk    r|S d|z   S )Nz(.)([A-Z][a-z]+)z\1_\2z([a-z])([A-Z])r   r1   private)resublower)r   intermediateinsecures      r   to_snake_caser     sW    6,h==Lv&,??EEGGH {cxr   c                 X    t           j                            |           }|D ]}| dS dS )NFT)tfnestflatten)	structureiterableelements      r   is_all_noner     s;    wy))H  55 4r   c                     t          |                                                              |          }|r%t          d|  dt	          |           d|           d S )NzUnknown entries in z dictionary: z . Only expected following keys: )rX   keys
differencer   r4   )r   
input_dictexpected_valuesunknowns       r   check_for_unexpected_keysr     s{    *//##$$//@@G 
?$ ? ?T']] ? ?-<? ?
 
 	

 
r    Keyword argument not understood:c                 8    | D ]}||vrt          ||          dS )zAChecks that all keyword arguments are in the set of allowed keys.N)	TypeError)kwargsallowed_kwargserror_messagekwargs       r   validate_kwargsr     s=      2 2&&M5111 '2 2r   c                     d| _         | S )z5Decorates a method to detect overrides in subclasses.T)_is_defaultmethods    r   defaultr     s    FMr   c                 $    t          | dd          S )z:Check if a method is decorated with the `default` wrapper.r   F)getattrr   s    r   
is_defaultr     s    6=%000r   c                 t    |D ]4}t          |          D ]"}t          ||          } ||          r|| |<   #5d S r   )dirr   )target_dictr]   
obj_filtermoduler   objs         r   !populate_dict_with_module_objectsr     s_     ( (KK 	( 	(D&$''Cz# ($'D!	(( (r   c                   .     e Zd ZdZ fdZd Zd Z xZS )
LazyLoaderzFLazily import a module, mainly to avoid pulling in large dependencies.c                 f    || _         || _        t                                          |           d S r   )_local_name_parent_module_globalssuperrk   )rj   
local_nameparent_module_globalsr   	__class__s       r   rk   zLazyLoader.__init__  s1    %&;#r   c                     t          j        | j                  }|| j        | j        <   | j                            |j                   |S )z8Load the module and insert it into the parent's globals.)	importlibimport_moduler   r   r   __dict__r   )rj   r   s     r   _loadzLazyLoader._load   sE     (778>#D$45 	V_---r   c                 J    |                                  }t          ||          S r   )r  r   )rj   itemr   s      r   __getattr__zLazyLoader.__getattr__+  s    vt$$$r   )r   r   r   r   rk   r  r  __classcell__)r   s   @r   r   r     s\        PP    
	 	 	% % % % % % %r   r   )NNN)Fr   )r   )&r   r6   r   r  r   r   r   r[   rd   typesr:   numpyr   tensorflow.compat.v2compatv2r   keras.utilsr   r    tensorflow.python.util.tf_exportr   r%   r>   rG   rI   r   r   r   r   r   r   r   r   r   r   
ModuleTyper   r)   r   r   <module>r     s.   * )        				 				 



          ! ! ! ! ! ! ! ! !             " " " " " " : 9 9 9 9 9# # #./ / / /d@ @ @ @$ #$$FN FN FN FN FN FN FN %$FNR  "1 1 1 1h  "       
 
 
 +M2 2 2 2  1 1 1
( ( (% % % % %( % % % % %r   