コード例 #1
0
ファイル: generic.py プロジェクト: Kimerth/volume-raycasting
    def _generate_cache(self):
        os.makedirs(self.cfg["cache_path"])

        data_map = self._create_data_map()

        for path, label_paths in tqdm(
            data_map.items(),
            total=len(data_map),
            position=0,
            leave=False,
            desc="Caching pooled data",
        ):
            subject_id = self._get_subject_id(path)

            image = ScalarImage(path, check_nans=True)
            label_map = LabelMap(label_paths, check_nans=True)
            if not isinstance(label_map, list):
                one_hot = OneHot(self.cfg["num_classes"] + 1)
                label_map = one_hot(label_map)
                label_map = LabelMap(tensor=label_map.tensor[1:])  # type: ignore

            image.load()
            label_map.load()

            image, label_map = self._resize(image, label_map)

            torch.save(
                {"subject_id": subject_id, "image": image.data, "seg": label_map.data},
                os.path.join(self.cfg["cache_path"], f"{subject_id}.pt"),
            )
コード例 #2
0
 def test_with_a_list_of_images_with_different_affines(self):
     path1 = self.get_image_path('path1', spacing=(1, 1, 1))
     path2 = self.get_image_path('path2', spacing=(1, 2, 1))
     image = ScalarImage(path=[path1, path2])
     with self.assertWarns(RuntimeWarning):
         image.load()
コード例 #3
0
 def test_with_a_list_of_images_with_different_shapes(self):
     path1 = self.get_image_path('path1', shape=(5, 5, 5))
     path2 = self.get_image_path('path2', shape=(7, 5, 5))
     image = ScalarImage(path=[path1, path2])
     with self.assertRaises(RuntimeError):
         image.load()
コード例 #4
0
 def test_nans_file(self):
     image = ScalarImage(self.get_image_path('repr_test', add_nans=True))
     with self.assertWarns(UserWarning):
         image.load()