Fiji Macro for U-net segmentation (Falk et al. plugin)



Hi, I’ve been trying to get the @falk U-net segmentation plugin to run in macro using a custom fine-tuned model but can’t seem to have any luck in executing it in a macro. Has anyone gotten it working? When I execute:
run(“Segment Current Image (Hyperstack)”);

call(‘de.unifreiburg.unet.SegmentationJob.processHyperStack’, ‘modelFilename=C:\Users\bolek\Desktop\UNET\caffemodels\2d_cell_net_v0-BZ-ishRGB-8JAN19.modeldef.h5,weightsFilename=2d_cell_net_v0-BZ-ishRGB-8JAN19.caffemodel.h5,Memory (MB):=4000,gpuId=all available,useRemoteHost=true,hostname=,port=22,username=bolek,processFolder=cellnet/,average=none,keepOriginal=true,outputScores=false,outputSoftmaxScores=false’);
it pops up the dialog to start the segmentation (from the first command) where as the actual call spits out an error (below) Has anyone managed to get this to run via Macro? Any tips on what I’m doing wrong? Thanks!

(Fiji Is Just) ImageJ 2.0.0-rc-43/1.52i; Java 1.8.0_25 [64-bit]; Windows 8 6.2; 5360MB of 392867MB (1%)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at ij.macro.Functions.getStringFunction(
at ij.macro.Interpreter.getStringTerm(
at ij.macro.Interpreter.getString(
at ij.macro.Interpreter.doStatement(
at ij.macro.Interpreter.doStatements(
at ij.plugin.Macro_Runner.runMacro(
at ij.IJ.runMacro(
at ij.IJ.runMacro(
at net.imagej.legacy.IJ1Helper$
at net.imagej.legacy.IJ1Helper$
at net.imagej.legacy.IJ1Helper.runMacroFriendly(
at net.imagej.legacy.IJ1Helper.runMacro(
at net.imagej.legacy.plugin.IJ1MacroEngine.eval(
at net.imagej.legacy.plugin.IJ1MacroEngine.eval(
at org.scijava.thread.DefaultThreadService$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: ncsa.hdf.hdf5lib.exceptions.HDF5FileNotFoundException: Path does not exit. (C:\Users\bolek\Documents\\UsersolekDesktopUNETcaffemodelsd_cell_net_v0-BZ-ishRGB-8JAN19.modeldef.h5)
at ch.systemsx.cisd.hdf5.HDF5BaseReader.openFile(
at ch.systemsx.cisd.hdf5.HDF5BaseReader.(
at ch.systemsx.cisd.hdf5.HDF5BaseReader.(
at ch.systemsx.cisd.hdf5.HDF5ReaderConfigurator.reader(
at de.unifreiburg.unet.ModelDefinition._load(
at de.unifreiburg.unet.ModelDefinition.load(
at de.unifreiburg.unet.SegmentationJob.processHyperStack(
… 31 more


Without testing the call myself according to the error message (a Java exception) the error seems to be caused by the file path argument:
Caused by: ncsa.hdf.hdf5lib.exceptions.HDF5FileNotFoundException: Path does not exit. (C:\Users\bolek

So at first I would control the path.

See also:


This is a known issue when recording macros on Windows (see Until I have a good solution to this, replace all occurrences of \ by \\ in all arguments to the macro and try again.


Thanks, indeed this seems to be the bug. I “resolved” this yesterday by moving both the model file and the RSA key into the same directory as Fiji and ran from the macro without a directory path - the \ seems to be the better fix that wont result in my fiji folder full of models. In case it’s useful for anyone, a working macro is pasted below.

One thing I did notice is that after quiting Fiji and starting it fresh, when I executed the Macro it would ask me for a password even though the RSA key was specified, and it wouldn’t work even when I entered the password. After running one segmentation manually the macro started working again without any changes - I’ll keep an eye on this and follow up if I can get to the bottom of it.

function processFile(input, output, file) {
open(input + file);
call(‘de.unifreiburg.unet.SegmentationJob.processHyperStack’, ‘modelFilename=2d_cell_net_v0-BZ-ishRGB-8JAN19.modeldef.h5, weightsFilename=2d_cell_net_v0-BZ-ishRGB-8JAN19.caffemodel.h5,Memory (MB):=6000,gpuId=all available,useRemoteHost=true,hostname=,port=22,username=bolek,RSAKeyfile=id_rsa,processFolder=cellnet/,average=none,keepOriginal=true,outputScores=false,outputSoftmaxScores=false’);
saveAs(“tif”, output + file);
print("Processing: " + input + file);
print("Saving to: " + output);