
    2Vh
                     `    d dl mZ d dlmZ d dlmZ d dlmZ  ed       G d de             Zy)	    )backend)keras_export)TFDataLayer)serialization_libzkeras.layers.Rescalingc                   L     e Zd ZdZd fd	Zd Zd Z fdZedd       Z	 xZ
S )		Rescalinga  A preprocessing layer which rescales input values to a new range.

    This layer rescales every value of an input (often an image) by multiplying
    by `scale` and adding `offset`.

    For instance:

    1. To rescale an input in the `[0, 255]` range
    to be in the `[0, 1]` range, you would pass `scale=1./255`.

    2. To rescale an input in the `[0, 255]` range to be in the `[-1, 1]` range,
    you would pass `scale=1./127.5, offset=-1`.

    The rescaling is applied both during training and inference. Inputs can be
    of integer or floating point dtype, and by default the layer will output
    floats.

    **Note:** This layer is safe to use inside a `tf.data` pipeline
    (independently of which backend you're using).

    Args:
        scale: Float, the scale to apply to the inputs.
        offset: Float, the offset to apply to the inputs.
        **kwargs: Base layer keyword arguments, such as `name` and `dtype`.
    c                 N    t        |   di | || _        || _        d| _        y )NT )super__init__scaleoffsetsupports_masking)selfr   r   kwargs	__class__s       X/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/layers/preprocessing/rescaling.pyr   zRescaling.__init__#   s)    "6"
 $    c           	         | j                   }| j                  j                  | j                  |      }| j                  j                  | j                  |      }| j                  j
                  j                  |      }t        |      dkD  rOt        j                         dk(  r8| j                  j                  j                  ||ddt        |      z
  z  z         }| j                  j                  ||      |z  |z   S )Nr   channels_first)      )compute_dtyper   castr   r   coreshapelenimage_data_formatnumpyreshape)r   inputsdtyper   r   scale_shapes         r   callzRescaling.call)   s    ""!!$**e4""4;;6ll''--e4q ))+/??LL&&..{TQ[1A-A%BBE ||  /%7&@@r   c                     |S Nr
   )r   input_shapes     r   compute_output_shapezRescaling.compute_output_shape7   s    r   c                     t         |          }|j                  t        j                  | j
                        t        j                  | j                        d       |S )N)r   r   )r   
get_configupdater   serialize_keras_objectr   r   )r   configr   s     r   r*   zRescaling.get_config:   sN    #% +AA$**M+BB4;;O	
 r   c                     |j                         }t        j                  |d   |      |d<   t        j                  |d   |      |d<    | di |S )Nr   )custom_objectsr   r
   )copyr   deserialize_keras_object)clsr-   r/   s      r   from_configzRescaling.from_configE   sY    +DD7ON
w -EE8^
x }V}r   )g        r&   )__name__
__module____qualname____doc__r   r$   r(   r*   classmethodr3   __classcell__)r   s   @r   r   r      s1    4%A	  r   r   N)		keras.srcr   keras.src.api_exportr   ,keras.src.layers.preprocessing.tf_data_layerr   keras.src.savingr   r   r
   r   r   <module>r>      s5     - D . &'F F (Fr   