-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Frequently asked questions and answers
Wenqi Li edited this page May 25, 2020
·
16 revisions
A list of frequently asked questions and answers maintained by the core developer team, based on the users' feedback and discussions.
Q2. How do I sample 2D slices from 3D volumes?
Q1. The randomised data transformations generate insufficiently shuffled outputs. How can I resolve this issue?
This is likely because the random number generator in MONAI is duplicated when multiple workers are initialised by torch.utils.data.Dataloader
(see also Pytorch FAQ, #398).
A possible solution is to set up random seeds in workers via the worker_init_fn
option:
def worker_init_fn(worker_id):
worker_info = torch.utils.data.get_worker_info()
try:
worker_info.dataset.transform.set_random_state(worker_info.seed % (2 ** 32))
except AttributeError:
pass
dataloader = torch.utils.data.DataLoader(..., worker_init_fn=worker_init_fn)
This could be achieved by setting a 3D window size, followed by "squeezing" the length one spatial dimension (see also: #299). For example,
train_transforms = Compose([
...
RandSpatialCropd(keys=['img', 'seg'], roi_size=[96, 96, 1], random_size=False),
SqueezeDimd(keys=['img', 'seg'], dim=-1), # remove the last spatial dimension
...
])