o
    2h                     @   s  d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ ee
eee	eeeeeeeeeeeehZ dd e D Z!e!"dd e D  e!"eeee	eeed eddd Z#edd%d d!Z$ed"d#d$ Z%dS )&    N)backend)ops)keras_export)STFT)Constant)Identity)Ones)Zeros)Initializer)GlorotNormal)GlorotUniform)HeNormal)	HeUniform)LecunNormal)LecunUniform)
Orthogonal)RandomNormal)RandomUniform)TruncatedNormal)VarianceScaling)serialization_lib)to_snake_casec                 C   s   i | ]}|j |qS  )__name__.0clsr   r   Z/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/initializers/__init__.py
<dictcomp>0   s    r   c                 C   s   i | ]}t |j|qS r   )r   r   r   r   r   r   r   2   s    )IdentityInitializernormaloneSTFTInitializerOrthogonalInitializeruniformzerozkeras.initializers.serializec                 C   s
   t | S )z7Returns the initializer configuration as a Python dict.)r   serialize_keras_object)initializerr   r   r   	serializeB   s   
r(   zkeras.initializers.deserializec                 C   s   t j| t|dS )z9Returns a Keras initializer object via its configuration.)module_objectscustom_objects)r   deserialize_keras_objectALL_OBJECTS_DICT)configr*   r   r   r   deserializeH   s
   r.   zkeras.initializers.getc                    s    du rdS t  trt }n+t  tr!t i d}t|}nt s/t  tjtjfr9d fdd	}|}n }t	|rIt
|rG| }|S td  )a  Retrieves a Keras initializer object via an identifier.

    The `identifier` may be the string name of a initializers function or class
    (case-sensitively).

    >>> identifier = 'Ones'
    >>> keras.initializers.get(identifier)
    <...keras.initializers.initializers.Ones...>

    You can also specify `config` of the initializer to this function by passing
    dict containing `class_name` and `config` as an identifier. Also note that
    the `class_name` must map to a `Initializer` class.

    >>> cfg = {'class_name': 'Ones', 'config': {}}
    >>> keras.initializers.get(cfg)
    <...keras.initializers.initializers.Ones...>

    In the case that the `identifier` is a class, this method will return a new
    instance of the class by its constructor.

    You may also pass a callable function with a signature that includes `shape`
    and `dtype=None` as an identifier.

    >>> fn = lambda shape, dtype=None: ops.ones(shape, dtype)
    >>> keras.initializers.get(fn)
    <function <lambda> at ...>

    Alternatively, you can pass a backend tensor or numpy array as the
    `identifier` to define the initializer values directly. Note that when
    calling the initializer, the specified `shape` argument must be the same as
    the shape of the tensor.

    >>> tensor = ops.ones(shape=(5, 5))
    >>> keras.initializers.get(tensor)
    <function get.<locals>.initialize_fn at ...>

    Args:
        identifier: A string, dict, callable function, or tensor specifying
            the initializer. If a string, it should be the name of an
            initializer. If a dict, it should contain the configuration of an
            initializer. Callable functions or predefined tensors are also
            accepted.

    Returns:
        Initializer instance base on the input identifier.
    N)
class_namer-   c                    sB   t |}t | t  jkrtd j d|  t |S )NzExpected `shape` to be z2 for direct tensor as initializer. Received shape=)r   standardize_dtypestandardize_shapeshape
ValueErrorr   cast)r2   dtype
identifierr   r   initialize_fn   s   

zget.<locals>.initialize_fnz,Could not interpret initializer identifier: N)
isinstancedictr.   strr   	is_tensornpgenericndarraycallableinspectisclassr3   )r7   objr-   r8   r   r6   r   getR   s(   0




rE   r9   )&rB   numpyr>   	keras.srcr   r   keras.src.api_exportr   ,keras.src.initializers.constant_initializersr   r   r   r   r	   "keras.src.initializers.initializerr
   *keras.src.initializers.random_initializersr   r   r   r   r   r   r   r   r   r   r   keras.src.savingr   keras.src.utils.namingr   ALL_OBJECTSr,   updater(   r.   rE   r   r   r   r   <module>   s|    
	