o
    bi
                     @   sL   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 deZdS )	    )backend)keras_export)	DataLayer)serialization_libzkeras.layers.Rescalingc                       sL   e Zd ZdZd fdd	Zdd Zdd Z fd	d
ZedddZ	  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` or `grain` 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                    s(   t  jdi | || _|| _d| _d S )NT )super__init__scaleoffsetsupports_masking)selfr   r   kwargs	__class__r   \/home/ubuntu/.local/lib/python3.10/site-packages/keras/src/layers/preprocessing/rescaling.pyr
   #   s   
zRescaling.__init__c                 C   s   | j }| j| j|}| j| j|}| jj|}t|dkr6t dkr6| jj	
||ddt|   }| j||| | S )Nr   channels_first)      )compute_dtyper   castr   r   coreshapelenimage_data_formatnumpyreshape)r   inputsdtyper   r   scale_shaper   r   r   call)   s   zRescaling.callc                 C   s   |S Nr   )r   input_shaper   r   r   compute_output_shape7   s   zRescaling.compute_output_shapec                    s.   t   }|t| jt| jd |S )N)r   r   )r	   
get_configupdater   serialize_keras_objectr   r   )r   configr   r   r   r%   :   s   


zRescaling.get_configNc                 C   sB   |  }tj|d |d|d< tj|d |d|d< | di |S )Nr   )custom_objectsr   r   )copyr   deserialize_keras_object)clsr(   r)   r   r   r   from_configE   s   

zRescaling.from_config)r   r"   )__name__
__module____qualname____doc__r
   r!   r$   r%   classmethodr-   __classcell__r   r   r   r   r      s    r   N)		keras.srcr   keras.src.api_exportr   )keras.src.layers.preprocessing.data_layerr   keras.src.savingr   r   r   r   r   r   <module>   s    