fiji / Trainable_Segmentation

Fiji library to perform image segmentation based on the Weka learning schemes
https://imagej.net/Trainable_Weka_Segmentation
GNU General Public License v3.0
110 stars 61 forks source link

Null pointer excpetion #67

Closed aforsythe closed 3 years ago

aforsythe commented 3 years ago

Running the following jython code produces a null pointer exception in 3.2.34. Downgrading to 3.2.33 solves the issue.

imp2 = imp.duplicate()
getProbs = True
segmentator = WekaSegmentation()
segmentator.loadClassifier(join(os.path.dirname(os.path.abspath(__file__)), 'classifiers/tumor_classifier.model'))
imp3 = segmentator.applyClassifier(imp2, 0, getProbs)
imp3 = imp3.crop()
IJ.setThreshold(imp3, 0.55, 1000000000000000000000000000000.0000)
IJ.run(imp3, "Convert to Mask", "")
Traceback (most recent call last):
  File "/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py", line 147, in <module>
    segment_tumor(imp)
  File "/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py", line 59, in segment_tumor
    segmentator.loadClassifier(join(os.path.dirname(os.path.abspath(__file__)), 'classifiers/tumor_classifier.model'))
    at trainableSegmentation.WekaSegmentation.loadClassifier(WekaSegmentation.java:807)
    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.lang.NullPointerException: java.lang.NullPointerException

    at org.python.core.Py.JavaError(Py.java:547)
    at org.python.core.Py.JavaError(Py.java:538)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)
    at org.python.core.PyObject.__call__(PyObject.java:477)
    at org.python.core.PyObject.__call__(PyObject.java:481)
    at org.python.core.PyMethod.__call__(PyMethod.java:141)
    at org.python.pycode._pyx0.segment_tumor$2(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py:104)
    at org.python.pycode._pyx0.call_function(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:173)
    at org.python.core.PyBaseCode.call(PyBaseCode.java:134)
    at org.python.core.PyFunction.__call__(PyFunction.java:416)
    at org.python.pycode._pyx0.f$0(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py:151)
    at org.python.pycode._pyx0.call_function(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:173)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1687)
    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:255)
    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:157)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
    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.NullPointerException
    at trainableSegmentation.WekaSegmentation.loadClassifier(WekaSegmentation.java:807)
    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:190)
    ... 29 more'classifiers/tumor_classifier.model'))
    at trainableSegmentation.WekaSegmentation.loadClassifier(WekaSegmentation.java:807)
    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.lang.NullPointerException: java.lang.NullPointerException

    at org.python.core.Py.JavaError(Py.java:547)
    at org.python.core.Py.JavaError(Py.java:538)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)
    at org.python.core.PyObject.__call__(PyObject.java:477)
    at org.python.core.PyObject.__call__(PyObject.java:481)
    at org.python.core.PyMethod.__call__(PyMethod.java:141)
    at org.python.pycode._pyx10.segment_tumor$2(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py:104)
    at org.python.pycode._pyx10.call_function(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:173)
    at org.python.core.PyBaseCode.call(PyBaseCode.java:134)
    at org.python.core.PyFunction.__call__(PyFunction.java:416)
    at org.python.pycode._pyx10.f$0(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py:151)
    at org.python.pycode._pyx10.call_function(/Users/alex/Source/IdeaProjects/stitch_devices/src/measure_stitched_tumors.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:173)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1687)
    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:255)
    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:157)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
    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.NullPointerException
    at trainableSegmentation.WekaSegmentation.loadClassifier(WekaSegmentation.java:807)
    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:190)
    ... 29 more
CellKai commented 3 years ago

In case it helps, I observed the same issue in version 3.2.35 and described another minimal example to reproduce the problem here: Applying Weka model in a script fails in recent version For me, the error did NOT exist in version 3.2.34 Thank you for your help!

emmenlau commented 3 years ago

In case it helps, I observed the same issue in version 3.2.35 and described another minimal example to reproduce the problem here: Applying Weka model in a script fails in recent version For me, the error did NOT exist in version 3.2.34

I second that, and other users on the forum reported the same. The issue happens in version 3.2.35, but goes away after downgrading to version 3.2.34. For me the problem was observed in beanshell scripts.

imagesc-bot commented 3 years ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/after-last-windows-update-fiji-macros-are-not-working/55568/7

imagejan commented 3 years ago

It seems like this might be fixed by https://github.com/fiji/Trainable_Segmentation/commit/c14a05d47a8d3292af4d93a68eac0154a0a2fbd5.

iarganda commented 3 years ago

This should be now fixed with the 3.3.0 release.