N2V for 3D stacks

, ,


I’m trying to use the N2V Fiji plugin. 2D training and prediction works very well, but I encountered an error when training for 3D stacks. When starting the training (train or train+predict) for a 3D stack (I tried a recently acquired one and this one too https://zenodo.org/record/3713326#.XnEJjy2cZQI since the first one didn’t work) and with a 3D kernel, the training starts and crashes when entering the “Preparation-Preparing validation batches” with the attached error message:

[INFO] Prepare validation batches..
65 blind-spots will be generated per training patch of size [16, 16, 16].
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: bound must be positive
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at de.csbdresden.n2v.train.N2VTraining.train(N2VTraining.java:194)
	at de.csbdresden.n2v.command.N2VTrainPredictCommand.mainThread(N2VTrainPredictCommand.java:182)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: bound must be positive
	at java.util.Random.nextInt(Random.java:388)
	at de.csbdresden.n2v.train.N2VDataWrapper.subpatch_sampling(N2VDataWrapper.java:290)
	at de.csbdresden.n2v.train.N2VDataWrapper.getItem(N2VDataWrapper.java:132)
	at de.csbdresden.n2v.train.N2VTraining.makeValidationData(N2VTraining.java:411)
	at de.csbdresden.n2v.train.N2VTraining.mainThread(N2VTraining.java:277)
	... 5 more

full_console_error_N2V3D.txt (1.8 KB)
I thought it could be because there are not enough slices but I got the same error with an artificially thicker dataset.
I also tried to change the axes order to XYZ or ZYX without any visible change in the error.
I tested this on a Windows and a Linux Mint machine with the same result.
I’m using TF 1.15.0 GPU (CUDA 10.0, CuDNN>=7.4.1) and CSBDeep should be up-to-date (version csbdeep-0.6.0.jar).
I also tried the zeroCostDL4Mic implementation and it worked on this dataset, but there you can specify the patch height along Z so it may be this?

I hope I didn’t miss something obvious, could someone help me understand this error? (Adding a tag for visibility @frauzufall)


Hi Sebastian!

I managed to reproduce the error, I will try to have a look under the hood!


1 Like

Hi again,

So the problem arise from the fact that the smallest dimension of the stack (13 in the example from the Zenodo repository) is smaller than the patch size (minimum being 16 in the implementation). Which is basically what you were hinting at. It for instance “works” (as in run through without errors) with 3 empty slices added at the end and a patch size of 16.

I opened a Github issue, but right now I am not familiar with the code so it will take a bit of time before I can push a fix.


1 Like

Hi! Thanks for the help!

I really thought I had tested for this, but I tested again and it works as expected indeed!

Thanks for spending time on this and opening the GitHub issue!