todo support for ragged used to instantiate a keras tensor a keras tensor is a symbolic tensorlike object which we augment with certain attributes that allow us to build a keras model just by knowing the inputs and outputs of the model for instance if a b and c are keras tensors it becomes possible to do model modelinputa b outputc args shape a shape tuple tuple of integers or none objects not including the batch size for instance shape32 indicates that the expected input will be batches of 32dimensional vectors elements of this tuple can be none none elements represent dimensions where the shape is not known and may vary e g sequence length batchsize optional static batch size integer dtype the data type expected by the input as a string e g float32 int32 sparse a boolean specifying whether the expected input will be sparse tensors note that if sparse is false sparse tensors can still be passed into the input they will be densified with a default value of 0 this feature is only supported with the tensorflow backend defaults to false name optional name string for the layer should be unique in a model do not reuse the same name twice it will be autogenerated if it isn t provided tensor optional existing tensor to wrap into the input layer if set the layer will use this tensor rather than creating a new placeholder tensor returns a keras tensor example python this is a logistic regression in keras x inputshape32 y dense16 activation softmax x model modelx y todo support for ragged used to instantiate a keras tensor a keras tensor is a symbolic tensor like object which we augment with certain attributes that allow us to build a keras model just by knowing the inputs and outputs of the model for instance if a b and c are keras tensors it becomes possible to do model model input a b output c args shape a shape tuple tuple of integers or none objects not including the batch size for instance shape 32 indicates that the expected input will be batches of 32 dimensional vectors elements of this tuple can be none none elements represent dimensions where the shape is not known and may vary e g sequence length batch_size optional static batch size integer dtype the data type expected by the input as a string e g float32 int32 sparse a boolean specifying whether the expected input will be sparse tensors note that if sparse is false sparse tensors can still be passed into the input they will be densified with a default value of 0 this feature is only supported with the tensorflow backend defaults to false name optional name string for the layer should be unique in a model do not reuse the same name twice it will be autogenerated if it isn t provided tensor optional existing tensor to wrap into the input layer if set the layer will use this tensor rather than creating a new placeholder tensor returns a keras tensor example python this is a logistic regression in keras x input shape 32 y dense 16 activation softmax x model model x y
import warnings

from keras import backend
from keras.api_export import keras_export
from keras.layers.layer import Layer
from keras.ops.node import Node


@keras_export("keras.layers.InputLayer")
class InputLayer(Layer):
    def __init__(
        self,
        shape=None,
        batch_size=None,
        dtype=None,
        sparse=None,
        batch_shape=None,
        input_tensor=None,
        name=None,
        **kwargs,
    ):
        
        super().__init__(name=name)
        if "input_shape" in kwargs:
            warnings.warn(
                "Argument `input_shape` is deprecated. Use `shape` instead."
            )
            shape = kwargs.pop("input_shape")

        if shape is not None and batch_shape is not None:
            raise ValueError(
                "You cannot pass both `shape` and `batch_shape` at the "
                "same time."
            )
        if batch_size is not None and batch_shape is not None:
            raise ValueError(
                "You cannot pass both `batch_size` and `batch_shape` at the "
                "same time."
            )
        if shape is None and batch_shape is None:
            raise ValueError("You must pass a `shape` argument.")

        if shape is not None:
            shape = backend.standardize_shape(shape)
            batch_shape = (batch_size,) + shape
        self.batch_shape = tuple(batch_shape)
        self._dtype = backend.standardize_dtype(dtype)

        self.sparse = bool(sparse)
        if self.sparse and not backend.SUPPORTS_SPARSE_TENSORS:
            raise ValueError(
                "`sparse=True` is not supported with backend: "
                f"{backend.backend()}"
            )

        if input_tensor is not None:
            if not isinstance(input_tensor, backend.KerasTensor):
                raise ValueError(
                    "Argument `input_tensor` must be a KerasTensor. "
                    f"Received invalid type: input_tensor={input_tensor} "
                    f"(of type {type(input_tensor)})"
                )
        else:
            input_tensor = backend.KerasTensor(
                shape=batch_shape, dtype=dtype, sparse=sparse, name=name
            )
        self._input_tensor = input_tensor
        Node(operation=self, call_args=(), call_kwargs={}, outputs=input_tensor)
        self.built = True

    def call(self):
        return

    @property
    def dtype(self):
        return self._dtype

    def get_config(self):
        return {
            "batch_shape": self.batch_shape,
            "dtype": self.dtype,
            "sparse": self.sparse,
            "name": self.name,
        }


@keras_export(["keras.layers.Input", "keras.Input"])
def Input(
    shape=None,
    batch_size=None,
    dtype=None,
    sparse=None,
    batch_shape=None,
    name=None,
    tensor=None,
):
    
    layer = InputLayer(
        shape=shape,
        batch_size=batch_size,
        dtype=dtype,
        sparse=sparse,
        batch_shape=batch_shape,
        name=name,
        input_tensor=tensor,
    )
    return layer.output