Skip to content

ConstantImageSize

Bases: ModelImageSize

A container for constant image size in neural networks.

Parameters:

Name Type Description Default
width int

the width of the image

required
height int

the height of the image

required
channel int

the channel of the image

required

Raises:

Type Description
OutOfBoundsError:

if width or height are below 1

ValueError

if an invalid channel is given

Methods:

Name Description
from_image

Create a ModelImageSize of a given image.

from_image_size

Create a ModelImageSize of a given image size.

Attributes:

Name Type Description
channel int

Get the channel of this ImageSize in pixels.

height int

Get the height of this ImageSize in pixels.

width int

Get the width of this ImageSize in pixels.

Source code in src/safeds/ml/nn/typing/_model_image_size.py
class ConstantImageSize(ModelImageSize):
    """
    A container for constant image size in neural networks.

    Parameters
    ----------
    width:
        the width of the image
    height:
        the height of the image
    channel:
        the channel of the image

    Raises
    ------
    OutOfBoundsError:
        if width or height are below 1
    ValueError
        if an invalid channel is given
    """

    def __eq__(self, other: object) -> bool:
        if isinstance(other, VariableImageSize):
            return other.__eq__(self)
        else:
            return super().__eq__(other)

    def __hash__(self) -> int:
        return super().__hash__()

    def __str__(self) -> str:
        return f"ConstantImageSize | {super().__str__()}"

channel

Get the channel of this ImageSize in pixels.

Returns:

Name Type Description
channel int

The channel of this ImageSize.

height

Get the height of this ImageSize in pixels.

Returns:

Name Type Description
height int

The height of this ImageSize.

width

Get the width of this ImageSize in pixels.

Returns:

Name Type Description
width int

The width of this ImageSize.

from_image

Create a ModelImageSize of a given image.

Parameters:

Name Type Description Default
image Image

the given image for the ModelImageSize

required

Returns:

Name Type Description
image_size Self

the calculated ModelImageSize

Source code in src/safeds/ml/nn/typing/_model_image_size.py
@classmethod
def from_image(cls: type[Self], image: Image) -> Self:
    """
    Create a `ModelImageSize` of a given image.

    Parameters
    ----------
    image:
        the given image for the `ModelImageSize`

    Returns
    -------
    image_size:
        the calculated `ModelImageSize`
    """
    return cls(image.width, image.height, image.channel)

from_image_size

Create a ModelImageSize of a given image size.

Parameters:

Name Type Description Default
image_size ModelImageSize

the given image size for the ModelImageSize

required

Returns:

Name Type Description
image_size Self

the new ModelImageSize

Source code in src/safeds/ml/nn/typing/_model_image_size.py
@classmethod
def from_image_size(cls: type[Self], image_size: ModelImageSize) -> Self:
    """
    Create a `ModelImageSize` of a given image size.

    Parameters
    ----------
    image_size:
        the given image size for the `ModelImageSize`

    Returns
    -------
    image_size:
        the new `ModelImageSize`
    """
    return cls(image_size.width, image_size.height, image_size.channel)