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

fiji
batch-processing
macro
segmentation

#1

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=10.0.1.198,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%)

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at ij.macro.Functions.call(Functions.java:4379)
at ij.macro.Functions.getStringFunction(Functions.java:274)
at ij.macro.Interpreter.getStringTerm(Interpreter.java:1366)
at ij.macro.Interpreter.getString(Interpreter.java:1344)
at ij.macro.Interpreter.doStatement(Interpreter.java:304)
at ij.macro.Interpreter.doStatements(Interpreter.java:236)
at ij.macro.Interpreter.run(Interpreter.java:119)
at ij.macro.Interpreter.run(Interpreter.java:90)
at ij.macro.Interpreter.run(Interpreter.java:101)
at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
at ij.IJ.runMacro(IJ.java:147)
at ij.IJ.runMacro(IJ.java:136)
at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:936)
at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:933)
at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:899)
at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:933)
at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:116)
at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:163)
at org.scijava.script.ScriptModule.run(ScriptModule.java:174)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: ncsa.hdf.hdf5lib.exceptions.HDF5FileNotFoundException: Path does not exit. (C:\Users\bolek\Documents\Fiji.app\UsersolekDesktopUNETcaffemodelsd_cell_net_v0-BZ-ishRGB-8JAN19.modeldef.h5)
at ch.systemsx.cisd.hdf5.HDF5BaseReader.openFile(HDF5BaseReader.java:183)
at ch.systemsx.cisd.hdf5.HDF5BaseReader.(HDF5BaseReader.java:141)
at ch.systemsx.cisd.hdf5.HDF5BaseReader.(HDF5BaseReader.java:120)
at ch.systemsx.cisd.hdf5.HDF5ReaderConfigurator.reader(HDF5ReaderConfigurator.java:86)
at de.unifreiburg.unet.ModelDefinition._load(ModelDefinition.java:304)
at de.unifreiburg.unet.ModelDefinition.load(ModelDefinition.java:809)
at de.unifreiburg.unet.SegmentationJob.processHyperStack(SegmentationJob.java:604)
… 31 more


#2

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:


#3

This is a known issue when recording macros on Windows (see https://github.com/lmb-freiburg/Unet-Segmentation/issues/2). Until I have a good solution to this, replace all occurrences of \ by \\ in all arguments to the macro and try again.


#4

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=10.0.1.198,port=22,username=bolek,RSAKeyfile=id_rsa,processFolder=cellnet/,average=none,keepOriginal=true,outputScores=false,outputSoftmaxScores=false’);
saveAs(“tif”, output + file);
close();
close();
close();
print("Processing: " + input + file);
print("Saving to: " + output);
}