|
1 | | -# import pytest |
2 | | -# import torch |
3 | | - |
4 | | -# from cellseg_models_pytorch.datasets import SegmentationHDF5Dataset |
5 | | - |
6 | | -# img_transforms = ["rigid", "blur"] |
7 | | -# inst_transforms = ["smooth_dist"] |
8 | | - |
9 | | - |
10 | | -# @pytest.mark.optional |
11 | | -# @pytest.mark.parametrize("return_inst", [True, False]) |
12 | | -# @pytest.mark.parametrize("return_type", [True, False]) |
13 | | -# @pytest.mark.parametrize("return_sem", [True, False]) |
14 | | -# @pytest.mark.parametrize("normalization", [None, "minmax"]) |
15 | | -# def test_hdf5_dataset(hdf5db, return_inst, return_type, return_sem, normalization): |
16 | | -# ds = SegmentationHDF5Dataset( |
17 | | -# path=hdf5db, |
18 | | -# img_transforms=img_transforms, |
19 | | -# inst_transforms=inst_transforms, |
20 | | -# normalization=normalization, |
21 | | -# return_inst=return_inst, |
22 | | -# return_type=return_type, |
23 | | -# return_sem=return_sem, |
24 | | -# ) |
25 | | - |
26 | | -# out = next(iter(ds)) |
27 | | - |
28 | | -# if return_inst: |
29 | | -# assert "inst" in out.keys() |
30 | | -# assert out["inst"].dtype == torch.int64 |
31 | | -# else: |
32 | | -# assert "binary" not in out.keys() |
33 | | - |
34 | | -# if return_type: |
35 | | -# assert "type" in out.keys() |
36 | | -# assert out["type"].dtype == torch.int64 |
37 | | -# else: |
38 | | -# assert "type" not in out.keys() |
39 | | - |
40 | | -# if return_sem: |
41 | | -# assert "sem" in out.keys() |
42 | | -# assert out["sem"].dtype == torch.int64 |
43 | | -# else: |
44 | | -# assert "sem" not in out.keys() |
45 | | - |
46 | | -# assert "smoothdist" in out.keys() |
47 | | -# assert out["image"].dtype == torch.float32 |
| 1 | +import pytest |
| 2 | +import torch |
| 3 | + |
| 4 | +from cellseg_models_pytorch.datasets.hdf5_dataset import SegmentationHDF5Dataset |
| 5 | + |
| 6 | +img_transforms = ["rigid", "blur"] |
| 7 | +inst_transforms = ["smooth_dist"] |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.optional |
| 11 | +@pytest.mark.parametrize("return_inst", [True, False]) |
| 12 | +@pytest.mark.parametrize("return_type", [True, False]) |
| 13 | +@pytest.mark.parametrize("return_sem", [True, False]) |
| 14 | +@pytest.mark.parametrize("normalization", [None, "minmax"]) |
| 15 | +def test_hdf5_dataset(hdf5db, return_inst, return_type, return_sem, normalization): |
| 16 | + ds = SegmentationHDF5Dataset( |
| 17 | + path=hdf5db, |
| 18 | + img_transforms=img_transforms, |
| 19 | + inst_transforms=inst_transforms, |
| 20 | + normalization=normalization, |
| 21 | + return_inst=return_inst, |
| 22 | + return_type=return_type, |
| 23 | + return_sem=return_sem, |
| 24 | + ) |
| 25 | + |
| 26 | + out = next(iter(ds)) |
| 27 | + |
| 28 | + if return_inst: |
| 29 | + assert "inst" in out.keys() |
| 30 | + assert out["inst"].dtype == torch.int64 |
| 31 | + else: |
| 32 | + assert "binary" not in out.keys() |
| 33 | + |
| 34 | + if return_type: |
| 35 | + assert "type" in out.keys() |
| 36 | + assert out["type"].dtype == torch.int64 |
| 37 | + else: |
| 38 | + assert "type" not in out.keys() |
| 39 | + |
| 40 | + if return_sem: |
| 41 | + assert "sem" in out.keys() |
| 42 | + assert out["sem"].dtype == torch.int64 |
| 43 | + else: |
| 44 | + assert "sem" not in out.keys() |
| 45 | + |
| 46 | + assert "smoothdist" in out.keys() |
| 47 | + assert out["image"].dtype == torch.float32 |
0 commit comments