CARE 2D Probabilistic denoising

After trying [3D denoising] CARE model I decided to try 2D Probabilistic denoising to see if this denoising can give better results than 3D denoising for organoid segmentation. However, after generating my training data and perform my training (successfully, I think), when I try to apply the model I keep getting the same error “ValueError: axes (SZYXC) must be of length 3.” when I apply model.predict() function.

I already tried to change the values of the axes theRawData.from_folder() function inputs parameters and use SZYXC as axes values, but the same error are still appearing. I do not know if I am trying to do something that requires more than just changing this parameter or if I am just trying to do something that is not as easy as I thing. Reading the documentation help me to understand best how to use CARE but I have not found anything related to this issue. Thank you for your time

the output of the function load_training_data gives() me

number of training images:	 2765
number of validation images:	 307
image size (3D):		 (16, 64, 64)
axes:				 SZYXC
channels in / out:		 1 / 1

the output of the model configuration is

{'n_dim': 3,
 'axes': 'ZYXC',
 'n_channel_in': 1,
 'n_channel_out': 1,
 'train_checkpoint': 'weights_best.h5',
 'train_checkpoint_last': 'weights_last.h5',
 'train_checkpoint_epoch': 'weights_now.h5',
 'probabilistic': True,
 'unet_residual': True,
 'unet_n_depth': 2,
 'unet_kern_size': 3,
 'unet_n_first': 32,
 'unet_last_activation': 'linear',
 'unet_input_shape': (None, None, None, 1),
 'train_loss': 'laplace',
 'train_epochs': 100,
 'train_steps_per_epoch': 50,
 'train_learning_rate': 0.0004,
 'train_batch_size': 16,
 'train_tensorboard': True,
 'train_reduce_lr': {'factor': 0.5, 'patience': 10, 'min_delta': 0}}

It seems that you want to do 3D denoising, hence I don’t understand why you want to try 2D probabilistic denoising. You can try probabilistic denoising in 3D, but it’ll (likely) not give you better results, just an intensity distribution per pixel instead of just a single value.

You can only apply a 2D (probabilistic) denoising model plane by plane to a 3D image, but that typically leads to bad results.

Sorry for the late reply.

thank you for your reply, I was trying to find the difference between the 3D Denoising and 3D probabilistic denoising but I was trying to understand 2D probabilistic denoising CARE example for to be able to apply the different components of the code to a 3D probabilistic denoising. Now, I already finish understanding why I was having that error and I was able to perform some small changes that do not affect the results, However, since the beginning, my results have not been close to the ones given by the example, I understand that it can be because the data is not similar to the ones used to train CARE. Are you can have some ideas about why this is happening, I would be glad to read you. Here some examples of my data and my results.

w1soSPIM-405-1-02-07.tif (1.6 MB)

The example input image that you show is quite low-SNR, and it seems that you are using a 2D probabilistic denoising model. Doing image denoising on such a noisy 2D input is very challenging.

I suspect that this 2D image is once slice/plane of a 3D image stack. I am suggesting to train a 3D denoising model (probabilistic or not), which should work much better.


I am trying to obtain the 3D probabilistic denoising restoration of a 3D stack, the normal restoration works perfectly but the probabilistic restoration did not allow me to plot the results, and I do not know why this restoration it is not correctly performed. Trying to understand what was happening I print the shape and restored_prob values and I got these outputs

print (restored_prob.shape)
(61, 918, 902)

<csbdeep.internals.probability.ProbabilisticPrediction object at 0x000001B61DF91E48>

The configuration, the definition of the model, the training and the restoration are the next ones:

config = Config(axes, n_channel_in, n_channel_out, probabilistic=True, train_steps_per_epoch=40)
model = CARE(config, ‘my_model’, basedir=‘models’)
history = model.train(X,Y, validation_data=(X_val,Y_val))
restored_prob = model.predict_probabilistic(x, axes=‘ZYX’, normalizer=None)

I hope you can help me, thanks

The probabilistic prediction yields an entire distribution per pixel, which cannot easily be plotted for all pixels at once. You can obtain the expected value (i.e. mean) as restored_mean = restored_prob.mean(), which you can then show as an image. You may also want to draw samples via restored_prob.sampling_generator(). These features and more are all shown in the probabilistic 2D denoising example.

Thank you for your answer, I was able to plot some of the samples form the probabilistic restoration thanks to your advice. However, I am still facing the same problems that I was facing before with the 2D probabilistic, when applying the different methods (.mean(), scale(), .var(), entropy() ) to restored_prob. The results of these methods are in bot cases are either nan or 0. I am confused because I do not understand why the results can be similar in both cases, even when doing 2d denoising I use the examples available. Why this can be happening?

Thank you for your time

Here Ieave you the code and the results I got

restored_mean = restored_prob.mean()
restored_scale = restored_prob.scale()

plot_some(np.stack([restored_mean,restored_scale]), title_list=[[‘mean’,‘scale’]]);

plot_some(np.stack([restored_prob.var(),restored_prob.entropy()]), title_list=[[‘variance’,‘entropy’]]);