Problem with running StarDist in headless mode

Hi,

I try to run StarDist from a python script in headless mode inside a docker container, but got stuck (see error below). I suspect it has to do with the fact the “some” UI needs to be show etc. but I do really now, what I have to change.

C:\Users\m1srh\Documents\Apeer_Modules\stardist_2d_nucelus_detecti_0361c18d-0a29-4fbc-a68a-7bfe1a62f713>docker run -it --rm -v c:\Temp\input:/input -v c:\Temp\output:/output --env-file wfe.env test/apeer_test_stardist:latest
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
[INFO] Overriding BIOP Run Macro...; identifier: command:ch.epfl.biop.macrorunner.B_Run_Macro; jar: file:/Fiji.app/plugins/BIOP/B_Run_Macro-1.0.0-SNAPSHOT.jar
[INFO] Overriding Get Spine From Circle Rois; identifier: command:Cirlces_Based_Spine; jar: file:/Fiji.app/plugins/Max_Inscribed_Circles-1.1.0.jar
[INFO] Starting pipeline ...
[INFO] Image Filename         : /input/segment_nuclei_CNN_mito.czi
[INFO] File exists            : True
[INFO] Channel to Analyse     : 1
[INFO] ----------------------------------------------------
[INFO] Stardist Model         : Versatile (fluorescent nuclei)
[INFO] Normalize              : True
[INFO] ---------------------------------------------------
[INFO] Minimum Probability    : 0.5
[INFO] Overlap Threshold      : 0.4
[INFO] Number of Tiles (ML)   : 1
[INFO] Exclude Boundary       : 2
[INFO] ---------------------------------------------------
[INFO] Save Format used       : ome.tiff
[INFO] --------------  START IMAGE ANALYSIS --------------
[INFO] Opening Image: /input/segment_nuclei_CNN_mito.czi
ZeissCZIReader initializing /input/segment_nuclei_CNN_mito.czi
[WARN] Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
[WARN] Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
[WARN] Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
[WARN] Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
[WARN] Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
[WARN] Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
[INFO] File Extension    : .czi
[INFO] Channel Count     : 2
[INFO] Extract Channel  : 1
[INFO] C1-segment_nuclei_CNN_mito.czi = net.imagej.display.DefaultDatasetView@2b7c8937
[ERROR] Module threw exception
java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763)
        at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838)
        at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1696)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:863)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:666)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:637)
        at de.csbdresden.stardist.StarDist2D.checkForCSBDeep(StarDist2D.java:193)
        at de.csbdresden.stardist.StarDist2D.run(StarDist2D.java:211)
        at org.scijava.command.CommandModule.run(CommandModule.java:199)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
        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)
[ERROR] Traceback (most recent call last):
  File "/Fiji.app/scripts/apeer_stardist2d.py", line 236, in <module>
    objstack = run(IMAGEPATH, outputpath_orig,
  File "/Fiji.app/scripts/apeer_stardist2d.py", line 97, in run
    res = command.run(StarDist2D, show_output,
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        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:498)
java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.awt.HeadlessException

        at org.python.core.Py.JavaError(Py.java:552)
        at org.python.core.Py.JavaError(Py.java:543)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
        at org.python.core.PyObject.__call__(PyObject.java:480)
        at org.python.core.PyObject.__call__(PyObject.java:484)
        at org.python.core.PyMethod.__call__(PyMethod.java:126)
        at org.python.pycode._pyx0.run$1(/Fiji.app/scripts/apeer_stardist2d.py:108)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/apeer_stardist2d.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
        at org.python.core.PyFunction.function___call__(PyFunction.java:471)
        at org.python.core.PyFunction.__call__(PyFunction.java:466)
        at org.python.pycode._pyx0.f$0(/Fiji.app/scripts/apeer_stardist2d.py:277)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/apeer_stardist2d.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.__builtin__.eval(__builtin__.java:497)
        at org.python.core.__builtin__.eval(__builtin__.java:501)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
        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.util.concurrent.ExecutionException: java.awt.HeadlessException
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        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:498)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
        ... 30 more
Caused by: java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763)
        at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838)
        at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1696)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:863)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:666)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:637)
        at de.csbdresden.stardist.StarDist2D.checkForCSBDeep(StarDist2D.java:193)
        at de.csbdresden.stardist.StarDist2D.run(StarDist2D.java:211)
        at org.scijava.command.CommandModule.run(CommandModule.java:199)
        ... 8 more

The relevant code snippet is:

# @LogService log
# @CommandService command

...

res = command.run(StarDist2D, False,
                  "input", imp,
                  "modelChoice", model,
                  "normalizeInput", normalize_inputs,
                  "probThresh", min_probability,
                  "nTiles", numtiles,
                  "excludeBoundary", exclude_boundary,
                  "outputType", output,
                  ).get()

Hi @sebi06, I’ve never tested headless mode, but seeing that your error originates from

I’m guessing StarDist is trying to show you an error message that CSBDeep could not be found. Did you activate the CSBDeep update site and does it work when you don’t run in headless mode?

Best,
Uwe

1 Like

Hi @uschmidt83 ,

i think this was exactly was I did during the docker build inside the dockefile, but I will double check and post my finding.

Cheers, Sebi

1 Like

Hu @uschmidt83,

I checked my dockerfile and the StarDist update site is activated. And the import statement from de.csbdresden.stardist import StarDist2D at the beginning of the script also seems to work, so I think StarDist plugin itself is available and the issue might be something else. What else could I check?

Dockerfile:

# Prerequisites
# - download latest fiji_linux64 from web
# - copy Fiji.app folder it to the folder where your dockerfile is placed
# place your additional fiji scripts inside the root folder
# run docker file to built the image and enjoy
#
# docker build -t username/fiji_linux64_baseimage:tag .
#
# docker push username/fiji_linux64_baseimage:tag
#
# Pull base JDK-8 image only if using Fiji that doe not already contain a JDK.
#FROM java:8-jre

FROM ubuntu:latest

COPY ./Fiji.app /Fiji.app

# add Fiji-Update sites only works when connected to the internet
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site 3DImageJSuite http://sites.imagej.net/Tboudier/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BAR http://sites.imagej.net/Tiago/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site EMBL-CBA http://sites.imagej.net/EMBL-CBA/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BASIC http://sites.imagej.net/BaSiC/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BIG-EPFL http://sites.imagej.net/BIG-EPFL/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BioVoxxel http://sites.imagej.net/BioVoxxel/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site CMP-BIAtools http://sites.imagej.net/CMP-BIA/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site IBMP-CNRS http://sites.imagej.net/Mutterer/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site IJPB-plugins http://sites.imagej.net/IJPB-plugins/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site ImageScience http://sites.imagej.net/ImageScience/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site IMCFUniBasel http://sites.imagej.net/UniBas-IMCF/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site PTBIOP http://biop.epfl.ch/Fiji-Update
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site CLIJ http://sites.imagej.net/clij
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site CLIJ2 https://sites.imagej.net/clij2/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site StarDist https://sites.imagej.net/StarDist/ 
RUN ./Fiji.app/ImageJ-linux64 --ij2 --headless --update update
RUN ./Fiji.app/ImageJ-linux64 --ij2 --headless

I forgot to mention that i cannot test if it runs in non-headless mode inside my docker container … (I know that there are tricks to “pretend” a display that can show graphical output, even if there is none, to make some Fiji plugins run, but first I want to make sure, I do not “do” any silly mistakes.)

Hi @uschmidt83,

I also tried to create a virtual display for the docker container, but I still get this headless error. Any ideas what else could try or whom to consult?

Thx, Sebi

C:\Users\m1srh\Documents\Apeer_Modules\stardist_2d_nucelus_detecti_0361c18d-0a29-4fbc-a68a-7bfe1a62f713>docker run -it --rm -v c:\Temp\input:/input -v c:\Temp\output:/output --env-file wfe.env test/apeer_test_stardist:latest
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
[INFO] Overriding BIOP Run Macro...; identifier: command:ch.epfl.biop.macrorunner.B_Run_Macro; jar: file:/Fiji.app/plugins/BIOP/B_Run_Macro-1.0.0-SNAPSHOT.jar
[INFO] Overriding Get Spine From Circle Rois; identifier: command:Cirlces_Based_Spine; jar: file:/Fiji.app/plugins/Max_Inscribed_Circles-1.1.0.jar
[INFO] Starting pipeline ...
[INFO] Image Filename         : /input/segment_nuclei_CNN_mito.czi
[INFO] File exists            : True
[INFO] Channel to Analyse     : 1
[INFO] ----------------------------------------------------
[INFO] Stardist Model         : Versatile (fluorescent nuclei)
[INFO] Normalize              : True
[INFO] ---------------------------------------------------
[INFO] Minimum Probability    : 0.5
[INFO] Overlap Threshold      : 0.4
[INFO] Number of Tiles (ML)   : 1
[INFO] Exclude Boundary       : 2
[INFO] ---------------------------------------------------
[INFO] Save Format used       : ome.tiff
[INFO] --------------  START IMAGE ANALYSIS --------------
[INFO] Opening Image: /input/segment_nuclei_CNN_mito.czi
[INFO] File Extension    : .czi
[INFO] Channel Count     : 2
[INFO] Extract Channel  : 1
[INFO] C1-segment_nuclei_CNN_mito.czi = net.imagej.display.DefaultDatasetView@7b11363c
[ERROR] Module threw exception
java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763)
        at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838)
        at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1696)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:863)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:666)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:637)
        at de.csbdresden.stardist.StarDist2D.checkForCSBDeep(StarDist2D.java:193)
        at de.csbdresden.stardist.StarDist2D.run(StarDist2D.java:211)
        at org.scijava.command.CommandModule.run(CommandModule.java:199)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
        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)
[ERROR] Traceback (most recent call last):
  File "/Fiji.app/scripts/apeer_stardist2d.py", line 257, in <module>
    objstack = run(IMAGEPATH, outputpath_orig,
  File "/Fiji.app/scripts/apeer_stardist2d.py", line 97, in run
    res = command.run(StarDist2D, show_output,
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        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:498)
java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.awt.HeadlessException

        at org.python.core.Py.JavaError(Py.java:552)
        at org.python.core.Py.JavaError(Py.java:543)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
        at org.python.core.PyObject.__call__(PyObject.java:480)
        at org.python.core.PyObject.__call__(PyObject.java:484)
        at org.python.core.PyMethod.__call__(PyMethod.java:126)
        at org.python.pycode._pyx0.run$1(/Fiji.app/scripts/apeer_stardist2d.py:108)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/apeer_stardist2d.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
        at org.python.core.PyFunction.function___call__(PyFunction.java:471)
        at org.python.core.PyFunction.__call__(PyFunction.java:466)
        at org.python.pycode._pyx0.f$0(/Fiji.app/scripts/apeer_stardist2d.py:298)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/apeer_stardist2d.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.__builtin__.eval(__builtin__.java:497)
        at org.python.core.__builtin__.eval(__builtin__.java:501)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
        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.util.concurrent.ExecutionException: java.awt.HeadlessException
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        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:498)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
        ... 30 more
Caused by: java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763)
        at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838)
        at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1696)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:863)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:666)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:637)
        at de.csbdresden.stardist.StarDist2D.checkForCSBDeep(StarDist2D.java:193)
        at de.csbdresden.stardist.StarDist2D.run(StarDist2D.java:211)
        at org.scijava.command.CommandModule.run(CommandModule.java:199)
        ... 8 more

As I was saying earlier, this is due to the missing CSBDeep update site, i.e. you need to add:

RUN ./Fiji.app/ImageJ-linux64 --update add-update-site CSBDeep https://sites.imagej.net/CSBDeep

Uwe

Hi @uschmidt83,

sorry for not reading your message correctly … I thought you meant I forgot the StarDist site … I will try it out and let you know if it works.

Hi @uschmidt83,

now this problem is gone. Thanks again. I still have to sort out how to convert

net.imagej.DefaultDataset (the label output) into an ImgPlus …

Sebi

I think ImageJFunctions can help you out:

https://javadoc.scijava.org/ImgLib2/net/imglib2/img/display/imagej/ImageJFunctions.html