Re: Weka 3D Trainable Segmentation in Java code

Posted by Ignacio Arganda-Carreras-2 on
URL: http://imagej.273.s1.nabble.com/Weka-3D-Trainable-Segmentation-in-Java-code-tp5019213p5019321.html

OK, I found the error and fixed it. It should work now. Please update the
plugin to the latest version (3.2.15) and try again.

Thanks again for reporting!

ignacio

On Mon, Sep 4, 2017 at 1:51 AM, Maurice Argive <[hidden email]>
wrote:

> Hi Ignacio,
>
> No, I ssh in to a server and run the code from the command line. This
> worked fine when I was using "Weka Trainable Segmentation" by calling
> WekaSegmentation() but throws the exception when I use "Weka Trainable
> Segmentation 3D" and call WekaSegmentation(true) in the code. Maybe I'm not
> describing this well. Let me know. Thanks for responding!
>
> On Sat, Sep 2, 2017 at 5:10 AM, Ignacio Arganda-Carreras <
> [hidden email]> wrote:
>
> > Hello again, Maurice,
> >
> > That exception seems related to the use of the GUI from an environment
> that
> > does not support keyboard, mouse or display. Are you calling the plugin
> > remotely? Maybe using a remote desktop?
> >
> > ignacio
> >
> > On Tue, Aug 29, 2017 at 4:08 AM, Maurice Argive <
> [hidden email]>
> > wrote:
> >
> > > Hi Ignacio,
> > >
> > > Thanks for fixing that. I'm no longer getting that error, but I am
> still
> > > getting the HeadlessException after calling applyClassifier. I've
> > included
> > > the top few lines from the Exception. Any ideas on why this is
> happening?
> > > I'm sure the classifier was created in 3D. And ClusterClassify is my
> > class.
> > > Thanks!
> > >
> > > img["2017_08_15_PBMC_AfterExpansionWell1_Box4_
> > 4nucleiA_Good_63x_c0_crop1.
> > > tif"
> > > (-2), 8-bit, 363x403x1x182x1]
> > > WARNING: core mtj jar files are not available as resources to this
> > > classloader (sun.misc.Launcher$AppClassLoader@7d9d1a19)
> > > Field of view: max sigma = 8.0, min sigma = 1.0
> > > Read class name: class 1
> > > Read class name: class 2
> > > Unrecognized command: "32-bit"
> > > Unrecognized command: "32-bit"
> > > Unrecognized command: "32-bit"
> > > Unrecognized command: "32-bit"
> > > Error when updating feature stack.
> > > java.util.concurrent.ExecutionException: java.awt.HeadlessException:
> > > No X11 DISPLAY variable was set, but this program performed an
> operation
> > > which requires it.
> > > java.util.concurrent.FutureTask.report(FutureTask.java:122)
> > > java.util.concurrent.FutureTask.get(FutureTask.java:192)
> > > trainableSegmentation.FeatureStack3D.updateFeaturesMT(
> > > FeatureStack3D.java:999)
> > > trainableSegmentation.WekaSegmentation.applyClassifier(
> > > WekaSegmentation.java:4842)
> > > ClusterClassify.main(ClusterClassify.java:60)
> > >
> > > at java.util.concurrent.FutureTask.report(FutureTask.java:122)
> > > at java.util.concurrent.FutureTask.get(FutureTask.java:192)
> > > at
> > > trainableSegmentation.FeatureStack3D.updateFeaturesMT(
> > > FeatureStack3D.java:999)
> > > at
> > > trainableSegmentation.WekaSegmentation.applyClassifier(
> > > WekaSegmentation.java:4842)
> > > at ClusterClassify.main(ClusterClassify.java:60)
> > > Caused by: java.awt.HeadlessException:
> > > No X11 DISPLAY variable was set, but this program performed an
> operation
> > > which requires it.
> > > Unrecognized command: "32-bit"
> > > at java.awt.GraphicsEnvironment.checkHeadless(
> > > GraphicsEnvironment.java:204)
> > > at java.awt.MenuComponent.<init>(MenuComponent.java:163)
> > > at java.awt.MenuItem.<init>(MenuItem.java:214)
> > > at java.awt.MenuItem.<init>(MenuItem.java:198)
> > > at java.awt.Menu.<init>(Menu.java:157)
> > > at java.awt.Menu.<init>(Menu.java:137)
> > > at ij.Menus.getMenu(Menus.java:783)
> > > at ij.Menus.getMenu(Menus.java:773)
> > > at ij.Menus.addMenuBar(Menus.java:105)
> > > at ij.IJ.init(IJ.java:362)
> > > at ij.IJ.run(IJ.java:349)
> > > at trainableSegmentation.FeatureStack3D$11.call(
> FeatureStack3D.java:678)
> > > at trainableSegmentation.FeatureStack3D$11.call(FeatureStack3D.java:1)
> > > 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)
> > > Feature stack array is now updated (182 slice(s) with 2 feature(s),
> took
> > > 7065ms).
> > > Could not apply Classifier!
> > >
> > >
> > > On Tue, Aug 22, 2017 at 4:35 AM, Ignacio Arganda-Carreras <
> > > [hidden email]> wrote:
> > >
> > > > Dear Maurice,
> > > >
> > > > I have found the problem and fix it. Please go ahead and update the
> > > plugin
> > > > to its latest release (3.2.14).
> > > >
> > > > Let me know if you have any more problems.
> > > >
> > > > Thanks again for reporting!
> > > >
> > > > ignacio
> > > >
> > > > On Tue, Aug 22, 2017 at 4:26 AM, Maurice Argive <
> > > [hidden email]>
> > > > wrote:
> > > >
> > > > > Hi Ignacio,
> > > > >
> > > > > Yes, I used "Trainable Weka Segmentation3D" in Fiji to create the
> > > > > classifier. Then I used the following code to load that classifier
> > and
> > > > > segment additional datasets programmatically:
> > > > >
> > > > > ImagePlus image = IJ.openImage("image-file-to-be-classified.tif");
> > > > > WekaSegmentation ws = new WekaSegmentation(true);
> > > > > ws.loadClassifier("saved-3D-model-file.model");
> > > > > ImagePlus output = ws.applyClassifier(image, 0, false);
> > > > > IJ.save(output, "output.tif");
> > > > > output.close();
> > > > > image.close();
> > > > >
> > > > > On Fri, Aug 18, 2017 at 4:50 AM, Ignacio Arganda-Carreras <
> > > > > [hidden email]> wrote:
> > > > >
> > > > > > Hello Maurice,
> > > > > >
> > > > > > Can you tell me the exact steps you took and the code you are
> > > running?
> > > > > Did
> > > > > > you use "Trainable Weka Segmentation 3D" to create the
> classifier?
> > > > > >
> > > > > > ignacio
> > > > > >
> > > > > > On Thu, Aug 17, 2017 at 3:04 AM, Maurice Argive <
> > > > > [hidden email]>
> > > > > > wrote:
> > > > > >
> > > > > > > Hi Ignacio,
> > > > > > >
> > > > > > > Thanks for the info. I created a new 3D model just to be sure
> and
> > > ran
> > > > > it
> > > > > > in
> > > > > > > the code. Now I'm getting this exception:
> > > > > > >
> > > > > > > Read class name: class 1
> > > > > > >
> > > > > > > Read class name: class 2
> > > > > > >
> > > > > > > Error while adjusting data!
> > > > > > >
> > > > > > > java.lang.NullPointerException
> > > > > > >
> > > > > > >
> > > > > > > trainableSegmentation.WekaSegmentation.setEnabledFeatures(
> > > > > > > WekaSegmentation.java:6420)
> > > > > > >
> > > > > > >
> > > > > > > trainableSegmentation.WekaSegmentation.
> > > > adjustSegmentationStateToData(
> > > > > > > WekaSegmentation.java:4169)
> > > > > > >
> > > > > > >
> > > > > > > trainableSegmentation.WekaSegmentation.loadClassifier(
> > > > > > > WekaSegmentation.java:717)
> > > > > > >
> > > > > > >          ClusterClassify.main(ClusterClassify.java:54)
> > > > > > >
> > > > > > >
> > > > > > >          at
> > > > > > > trainableSegmentation.WekaSegmentation.setEnabledFeatures(
> > > > > > > WekaSegmentation.java:6420)
> > > > > > >
> > > > > > >          at
> > > > > > > trainableSegmentation.WekaSegmentation.
> > > > adjustSegmentationStateToData(
> > > > > > > WekaSegmentation.java:4169)
> > > > > > >
> > > > > > >          at
> > > > > > > trainableSegmentation.WekaSegmentation.loadClassifier(
> > > > > > > WekaSegmentation.java:717)
> > > > > > >
> > > > > > >          at ClusterClassify.main(ClusterClassify.java:54)
> > > > > > >
> > > > > > > Apply Classifier
> > > > > > >
> > > > > > > Exception in thread "main" java.lang.NullPointerException
> > > > > > >
> > > > > > >
> > > > > > > trainableSegmentation.WekaSegmentation.applyClassifier(
> > > > > > > WekaSegmentation.java:4709)
> > > > > > >
> > > > > > >          ClusterClassify.main(ClusterClassify.java:60)
> > > > > > >
> > > > > > >
> > > > > > >          at
> > > > > > > trainableSegmentation.WekaSegmentation.applyClassifier(
> > > > > > > WekaSegmentation.java:4709)
> > > > > > >
> > > > > > >          at ClusterClassify.main(ClusterClassify.java:60)
> > > > > > >
> > > > > > > Any ideas on what could be causing this? Is there something
> else
> > I
> > > > need
> > > > > > to
> > > > > > > do? The sample data I'm running classifies correctly when using
> > the
> > > > > Fiji
> > > > > > > plugin.
> > > > > > >
> > > > > > > Thanks!
> > > > > > >
> > > > > > > Maurice
> > > > > > >
> > > > > > > On Wed, Aug 16, 2017 at 7:08 AM, Ignacio Arganda-Carreras <
> > > > > > > [hidden email]> wrote:
> > > > > > >
> > > > > > > > Hello Maurice,
> > > > > > > >
> > > > > > > > I tried to replicate your error but I couldn't. Are you sure
> > > you're
> > > > > not
> > > > > > > > trying to load a classifier trained on 2D features instead of
> > one
> > > > > > trained
> > > > > > > > using 3D features? Your code worked for me.
> > > > > > > >
> > > > > > > > And by the way, you don't need to set the training image
> > anymore
> > > if
> > > > > you
> > > > > > > are
> > > > > > > > just loading a classifier and applying it to a new image.
> Have
> > a
> > > > look
> > > > > > at
> > > > > > > > this example in the wiki
> > > > > > > > <http://imagej.net/Scripting_the_Trainable_Weka_
> > > > > > > > Segmentation#Example:_apply_classifier_to_all_images_in_
> > folder>
> > > > > > > > .
> > > > > > > >
> > > > > > > > Cheers!
> > > > > > > >
> > > > > > > > On Wed, Aug 16, 2017 at 4:43 AM, Maurice Argive <
> > > > > > > [hidden email]>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > > > I'm using the following code to classify images from the
> > > command
> > > > > > line:
> > > > > > > > >
> > > > > > > > > ImagePlus image = IJ.openImage("image-file-to-
> > > > be-classified.tif");
> > > > > > > > > WekaSegmentation ws = new WekaSegmentation(image);
> > > > > > > > > ws.loadClassifier("saved-model-file.model");
> > > > > > > > > ImagePlus output = ws.applyClassifier(image, 0, false);
> > > > > > > > > IJ.save(output, "output.tif");
> > > > > > > > > output.close();
> > > > > > > > > image.close();
> > > > > > > > >
> > > > > > > > > and this has been working well for me for a few years. I
> > > noticed
> > > > > in a
> > > > > > > > > recent Fiji upgrade that there is now a 3D menu option. I'm
> > > > trying
> > > > > to
> > > > > > > use
> > > > > > > > > that feature in code so I use:
> > > > > > > > >
> > > > > > > > > ImagePlus image = IJ.openImage("image-file-to-
> > > > be-classified.tif");
> > > > > > > > > WekaSegmentation ws = new WekaSegmentation(true);
> > > > > > > > > ws.setTrainingImage(image);
> > > > > > > > > ws.loadClassifier("saved-model-file.model");
> > > > > > > > > ImagePlus output = ws.applyClassifier(image, 0, false);
> > > > > > > > > IJ.save(output, "output.tif");
> > > > > > > > > output.close();
> > > > > > > > > image.close();
> > > > > > > > >
> > > > > > > > > and it seems to be working until the applyClassifier method
> > > > runs. I
> > > > > > > then
> > > > > > > > > get a number of HeadlessExceptions that I never got before.
> > Is
> > > > > there
> > > > > > a
> > > > > > > > way
> > > > > > > > > to run the 3D segmentation in code without the GUI?
> > > > > > > > >
> > > > > > > > > Thanks!
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Ignacio Arganda-Carreras, Ph.D.
> > > > > > > > Ikerbasque Research Fellow
> > > > > > > > Departamento de Ciencia de la Computacion e Inteligencia
> > > Artificial
> > > > > > > > Facultad de Informatica, Universidad del Pais Vasco
> > > > > > > > Paseo de Manuel Lardizabal, 1
> > > > > > > > 20018 Donostia-San Sebastian
> > > > > > > > Guipuzcoa, Spain
> > > > > > > >
> > > > > > > > Phone : +34 943 01 73 25
> > > > > > > > Website: http://sites.google.com/site/iargandacarreras/
> > > > > > > >
> > > > > > > > --
> > > > > > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Ignacio Arganda-Carreras, Ph.D.
> > > > > > Ikerbasque Research Fellow
> > > > > > Departamento de Ciencia de la Computacion e Inteligencia
> Artificial
> > > > > > Facultad de Informatica, Universidad del Pais Vasco
> > > > > > Paseo de Manuel Lardizabal, 1
> > > > > > 20018 Donostia-San Sebastian
> > > > > > Guipuzcoa, Spain
> > > > > >
> > > > > > Phone : +34 943 01 73 25
> > > > > > Website: http://sites.google.com/site/iargandacarreras/
> > > > > >
> > > > > > --
> > > > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > > > > >
> > > > >
> > > > > --
> > > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Ignacio Arganda-Carreras, Ph.D.
> > > > Ikerbasque Research Fellow
> > > > Departamento de Ciencia de la Computacion e Inteligencia Artificial
> > > > Facultad de Informatica, Universidad del Pais Vasco
> > > > Paseo de Manuel Lardizabal, 1
> > > > 20018 Donostia-San Sebastian
> > > > Guipuzcoa, Spain
> > > >
> > > > Phone : +34 943 01 73 25
> > > > Website: http://sites.google.com/site/iargandacarreras/
> > > >
> > > > --
> > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > > >
> > >
> > > --
> > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> > >
> >
> >
> >
> > --
> > Ignacio Arganda-Carreras, Ph.D.
> > Ikerbasque Research Fellow
> > Departamento de Ciencia de la Computacion e Inteligencia Artificial
> > Facultad de Informatica, Universidad del Pais Vasco
> > Paseo de Manuel Lardizabal, 1
> > 20018 Donostia-San Sebastian
> > Guipuzcoa, Spain
> >
> > Phone : +34 943 01 73 25
> > Website: http://sites.google.com/site/iargandacarreras/
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>



--
Ignacio Arganda-Carreras, Ph.D.
Ikerbasque Research Fellow
Departamento de Ciencia de la Computacion e Inteligencia Artificial
Facultad de Informatica, Universidad del Pais Vasco
Paseo de Manuel Lardizabal, 1
20018 Donostia-San Sebastian
Guipuzcoa, Spain

Phone : +34 943 01 73 25
Website: http://sites.google.com/site/iargandacarreras/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html