elektronn3.training.noise2void module

Trainer code for 2D and 3D Noise2Void (https://arxiv.org/abs/1811.10980) Adapted from https://github.com/juglab/pn2v/blob/master/pn2v/training.py, ported from NumPy to PyTorch and generalized to support 3D.

class elektronn3.training.noise2void.Noise2VoidTrainer(model, criterion=torch.nn.Module, *args, n2v_ratio=0.001, agn_max_std=0, gblur_sigma=0, **kwargs)[source]

Bases: elektronn3.training.trainer.Trainer

Trainer subclass with custom training and validation code for Noise2Void training.

Noise2Void is applied by default, but it can also be replaced or accompanied by additive gaussian noise and gaussian blurring (see args below).

Parameters
  • model (Module) – PyTorch model (nn.Module) that shall be trained.

  • criterion (Module) – Training criterion. If n2v_ratio > 0, it should expect 3 arguments, the third being the Noise2Void mask. Per default, a masked MSE loss is used.

  • *argsOther positional args. See signature of :py:class:`elektronn3.training.Trainer`

  • n2v_ratio (float) – Ratio of pixels to be manipulated and masked in each image according to the Noise2Void algorithm. If it is set to a value <= 0, Noise2Void is disabled.

  • agn_max_std (float) – Maximum std (sigma parameter) for additive gaussian noise that is optionally applied to the input image. Standard deviations are sampled from a uniform distribution that ranges between 0 and agn_max_std. If it is set to a value <= 0, additive gaussian noise is disabled.

  • gblur_sigma (float) – Sigma parameter for gaussian blurring that is optionally applied to the input image. If it is set to a value <= 0, gaussian blurring is disabled.

  • **kwargs – Other keyword args. See signature of elektronn3.training.Trainer

epoch: int
exp_name: str
out_channels: Optional[int]
save_path: str
step: int
tb: tensorboardX.SummaryWriter
terminate: bool
train_loader: torch.utils.data.DataLoader
valid_loader: torch.utils.data.DataLoader
elektronn3.training.noise2void.get_stratified_coords(ratio, shape)

Produce a list of approx. num_pix random coordinates, sampled from shape using startified sampling. Supports n-dimensional shapes.

elektronn3.training.noise2void.prepare_sample(img, ratio=0.001, channels=None)

Prepare binary mask and target image for Noise2Void from a given image