Abstract: Disclosed is a computer-implemented method for segmenting input data. In the method a plurality of tags is generated; the input data is masked with the plurality of tags; a plurality of output reconstructions is generated by inputting the plurality of masked input data to one of the following: a denoising neural network, a variational autoencoder; a plurality of values representing distances of each plurality of output reconstructions to the input data are determined; a plurality of updated versions of input data is generated by applying at least one of the determined values representing distances of each plurality of output reconstructions to the input data; and updated output reconstructions are generated by inputting the plurality of updated versions of input data to one of the networks. Also disclosed is a method for training the network and a processing unit.