diff --git a/src/safeds/data/image/containers/_image_list.py b/src/safeds/data/image/containers/_image_list.py index a69dfefa4..178151afc 100644 --- a/src/safeds/data/image/containers/_image_list.py +++ b/src/safeds/data/image/containers/_image_list.py @@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Literal, overload from safeds._config import _init_default_device +from safeds._utils import _get_random_seed from safeds.data.image.containers._image import Image from safeds.exceptions import OutOfBoundsError, ClosedBound @@ -176,6 +177,8 @@ def from_files( _init_default_device() + random.seed(_get_random_seed()) + from safeds.data.image.containers._empty_image_list import _EmptyImageList from safeds.data.image.containers._multi_size_image_list import _MultiSizeImageList from safeds.data.image.containers._single_size_image_list import _SingleSizeImageList diff --git a/src/safeds/data/labeled/containers/_image_dataset.py b/src/safeds/data/labeled/containers/_image_dataset.py index fdffcbf7b..93c8fd646 100644 --- a/src/safeds/data/labeled/containers/_image_dataset.py +++ b/src/safeds/data/labeled/containers/_image_dataset.py @@ -5,7 +5,7 @@ import warnings from typing import TYPE_CHECKING, Generic, TypeVar -from safeds._config import _init_default_device +from safeds._config import _get_device, _init_default_device from safeds._utils import _structural_hash from safeds.data.image.containers import ImageList from safeds.data.image.containers._empty_image_list import _EmptyImageList @@ -294,7 +294,7 @@ def __init__(self, table: Table) -> None: _init_default_device() self._column_names = table.column_names - self._tensor = torch.Tensor(table._data_frame.to_numpy()).to(torch.get_default_device()) + self._tensor = torch.Tensor(table._data_frame.to_torch()).to(_get_device()) if not torch.all(self._tensor.sum(dim=1) == torch.ones(self._tensor.size(dim=0))): raise ValueError( @@ -355,8 +355,8 @@ def __init__(self, column: Column) -> None: category=UserWarning, ) self._one_hot_encoder = OneHotEncoder().fit(column_as_table, [self._column_name]) - self._tensor = torch.Tensor(self._one_hot_encoder.transform(column_as_table)._data_frame.to_numpy()).to( - torch.get_default_device(), + self._tensor = torch.Tensor(self._one_hot_encoder.transform(column_as_table)._data_frame.to_torch()).to( + _get_device(), ) def __eq__(self, other: object) -> bool: diff --git a/src/safeds/data/labeled/containers/_time_series_dataset.py b/src/safeds/data/labeled/containers/_time_series_dataset.py index b7b013c9a..811996d6a 100644 --- a/src/safeds/data/labeled/containers/_time_series_dataset.py +++ b/src/safeds/data/labeled/containers/_time_series_dataset.py @@ -3,7 +3,7 @@ import sys from typing import TYPE_CHECKING, Any -from safeds._config import _init_default_device +from safeds._config import _get_device, _init_default_device from safeds._utils import _structural_hash from safeds.exceptions import ClosedBound, OutOfBoundsError @@ -235,7 +235,7 @@ def _into_dataloader_with_window(self, window_size: int, forecast_horizon: int, label = target_tensor[i + window_size + forecast_horizon] for col in feature_cols: data = torch.tensor(col._series.to_numpy(), dtype=torch.float32) - window = torch.cat((window, data[i: i + window_size]), dim=0) + window = torch.cat((window, data[i : i + window_size]), dim=0) x_s.append(window) y_s.append(label) x_s_tensor = torch.stack(x_s) @@ -279,7 +279,7 @@ def _into_dataloader_with_window_predict( _init_default_device() - target_tensor = self.target._series.to_torch() + target_tensor = self.target._series.to_torch().to(_get_device()) x_s = [] size = target_tensor.size(0) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 33b1106d5..8fb39eb32 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1994,7 +1994,7 @@ def _into_dataloader(self, batch_size: int) -> DataLoader: _init_default_device() return DataLoader( - dataset=_create_dataset(self._data_frame.to_torch(dtype=pl.Float32)), + dataset=_create_dataset(self._data_frame.to_torch(dtype=pl.Float32).to(_get_device())), batch_size=batch_size, generator=torch.Generator(device=_get_device()), ) diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cpu].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cpu].png index f6e27f2e7..9c2694ebb 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cpu].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cpu].png differ diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cuda].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cuda].png index f6e27f2e7..9c2694ebb 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cuda].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-cuda].png differ diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cpu].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cpu].png index f6e27f2e7..9c2694ebb 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cpu].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cpu].png differ diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cuda].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cuda].png index f6e27f2e7..9c2694ebb 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cuda].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[all-images-path-cuda].png differ diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cpu].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cpu].png index 40477ac64..a21a7b2d6 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cpu].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cpu].png differ diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cuda].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cuda].png index 40477ac64..a21a7b2d6 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cuda].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-cuda].png differ diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cpu].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cpu].png index 40477ac64..a21a7b2d6 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cpu].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cpu].png differ diff --git a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cuda].png b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cuda].png index 40477ac64..a21a7b2d6 100644 Binary files a/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cuda].png and b/tests/safeds/data/image/containers/__snapshots__/test_image_list/TestFromFiles.test_from_files_creation_load_percentage[images_folder-path-cuda].png differ diff --git a/tests/safeds/ml/nn/test_cnn_workflow.py b/tests/safeds/ml/nn/test_cnn_workflow.py index 0a5751ee6..78c221cad 100644 --- a/tests/safeds/ml/nn/test_cnn_workflow.py +++ b/tests/safeds/ml/nn/test_cnn_workflow.py @@ -38,22 +38,22 @@ class TestImageToTableClassifier: ( 1234, device_cuda, - ["grayscale"] * 7, + ["white_square"] * 7, ), ( 4711, device_cuda, - ["white_square"] * 7, + ["rgba"] * 7, ), ( 1234, device_cpu, - ["grayscale"] * 7, + ["white_square"] * 7, ), ( 4711, device_cpu, - ["white_square"] * 7, + ["rgba"] * 7, ), ], ids=["seed-1234-cuda", "seed-4711-cuda", "seed-1234-cpu", "seed-4711-cpu"], @@ -106,22 +106,22 @@ class TestImageToColumnClassifier: ( 1234, device_cuda, - ["grayscale"] * 7, + ["white_square"] * 7, ), ( 4711, device_cuda, - ["white_square"] * 7, + ["rgba"] * 7, ), ( 1234, device_cpu, - ["grayscale"] * 7, + ["white_square"] * 7, ), ( 4711, device_cpu, - ["white_square"] * 7, + ["rgba"] * 7, ), ], ids=["seed-1234-cuda", "seed-4711-cuda", "seed-1234-cpu", "seed-4711-cpu"],