fepegar / torchio
Showing 1 of 1 files from the diff.

@@ -1,7 +1,7 @@
Loading
1 1
import random
2 2
import warnings
3 3
from itertools import islice
4 -
from typing import List, Iterator, Optional, Sequence
4 +
from typing import List, Iterator, Optional, Sequence, Union
5 5
6 6
import humanize
7 7
from torch.utils.data import Dataset, DataLoader, RandomSampler
@@ -133,7 +133,7 @@
Loading
133 133
            self,
134 134
            subjects_dataset: SubjectsDataset,
135 135
            max_length: int,
136 -
            samples_per_volume: int,
136 +
            samples_per_volume: Union[int, Sequence[int]],
137 137
            sampler: PatchSampler,
138 138
            num_workers: int = 0,
139 139
            shuffle_subjects: bool = True,
@@ -145,17 +145,8 @@
Loading
145 145
        self.max_length = max_length
146 146
        self.shuffle_subjects = shuffle_subjects
147 147
        self.shuffle_patches = shuffle_patches
148 -
        self.samples_per_volume = samples_per_volume
149 -
        if isinstance(samples_per_volume, int):
150 -
            self.samples_per_volume = self.num_subjects * [samples_per_volume]
151 -
152 -
        if not isinstance(self.samples_per_volume, Sequence):
153 -
            raise TypeError('`samples_per_volume` should be an int or a list')
154 -
155 -
        if len(self.samples_per_volume) != self.num_subjects:
156 -
            raise ValueError('`samples_per_volume` (list) length must be equal'
157 -
                             'to the number of subjects')
158 -
148 +
        self.samples_per_volume = self._parse_samples_per_volume(
149 +
            samples_per_volume)
159 150
        self.sampler = sampler
160 151
        self.num_workers = num_workers
161 152
        self.verbose = verbose
@@ -198,6 +189,26 @@
Loading
198 189
        attributes_string = ', '.join(attributes)
199 190
        return f'Queue({attributes_string})'
200 191
192 +
    def _parse_samples_per_volume(self, samples_per_volume):
193 +
        if isinstance(samples_per_volume, int):
194 +
            samples_per_volume = self.num_subjects * [samples_per_volume]
195 +
        message = (
196 +
            'The value of samples_per_volume must be an integer'
197 +
            ' or a sequence of integers'
198 +
        )
199 +
        if isinstance(samples_per_volume, Sequence):
200 +
            if not all(isinstance(n, int) for n in samples_per_volume):
201 +
                raise TypeError(message)
202 +
        else:
203 +
            raise TypeError(message)
204 +
        if len(samples_per_volume) != self.num_subjects:
205 +
            message = (
206 +
                'The length of samples_per_volume must be equal to the number'
207 +
                ' of subjects in the subjects dataset'
208 +
            )
209 +
            raise ValueError(message)
210 +
        return samples_per_volume
211 +
201 212
    def _print(self, *args):
202 213
        if self.verbose:
203 214
            print(*args)  # noqa: T001
@@ -313,7 +324,7 @@
Loading
313 324
            num_workers=self.num_workers,
314 325
            batch_size=1,
315 326
            collate_fn=self._get_first_item,
316 -
            shuffle=False,  # Shuffling is done is Queue's constructor
327 +
            shuffle=False,  # shuffling is done in _get_subjects_iterable
317 328
        )
318 329
        return iter(subjects_loader)
319 330
Files Coverage
tests 99.78%
torchio 95.25%
print_system.py 0.00%
Project Totals (124 files) 96.62%
1962.3
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
1962.2
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
1962.1
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading