Skip to content

Commit a120ade

Browse files
NepeliusLukas Nepeliuspre-commit-ci[bot]lukasbehammer
authored
fix: add check for image dimensions during loading (#15)
* fix: add check for image dimensions during loading closes #14 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor: refactor to comply with ruff * docs(load_data): add Exception to function docstring --------- Co-authored-by: Lukas Nepelius <p42940@fhooe.at> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: lukasbehammer <lukas.behammer@fh-wels.at>
1 parent c423f57 commit a120ade

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/viqa/utils/loading.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ def load_data(
655655
------
656656
ValueError
657657
If input type is not supported \n
658-
If ``data_range=None`` and ``normalize=True``
658+
If ``data_range=None`` and ``normalize=True`` \n
659+
If number of dimensions not 2 or 3
659660
660661
Warns
661662
-----
@@ -738,6 +739,21 @@ def load_data(
738739
"Input type not supported"
739740
) # Raise exception if input type is not supported
740741

742+
if batch:
743+
# TODO: Deprecate in version 4.0.0
744+
for img_num, img in enumerate(img_arr):
745+
if len(img.shape) > 3 or len(img.shape) < 2:
746+
raise ValueError(
747+
f"Number of dimensions of input image should be 2 or 3, got "
748+
f"{len(img.shape)} for image number {img_num} in img_arr."
749+
)
750+
elif not isinstance(img_arr, list):
751+
if len(img_arr.shape) > 3 or len(img_arr.shape) < 2:
752+
raise ValueError(
753+
f"Number of dimensions of input image should be 2 or 3, got "
754+
f"{len(img_arr.shape)}."
755+
)
756+
741757
# Normalize data
742758
if normalize and data_range:
743759
# TODO: Deprecate in version 4.0.0

0 commit comments

Comments
 (0)