Login  Register

Re: Using TrainableWeka objects in scripts

Posted by Marcello DiStasio on Nov 23, 2013; 8:09pm
URL: http://imagej.273.s1.nabble.com/Using-TrainableWeka-objects-in-scripts-tp5005479p5005674.html

Thank you very much for the clarifications, Ignacio. I really appreciate
the help!   Using only the WekaSegmentation object to save the classifier
model object there and then loading in the GUI later seems quite
reasonable.   I primarily want the ability to run my WEKA training script
in headless mode on a cluster. The script now appears to work on my
desktop, with the GUI in place, but no overt calls to display any windows,
just saving outputs.   I am having a bit of trouble doing so, however,
since a couple of of the plugins I call seem not to be working in headless
mode.  I am making a couple calls like this in python:

IJ.run(imp_h, "Auto Threshold", "method=Li white")   # imp_h is an
imagePlus object

and getting java.lang.NullPointerException.  This does not happen when I
run fiji from the command line, but on a computer that has X11.


I am also getting java.awt.HeadlessException when I try creating an ROI
Manager, e.g.  with

roim = RoiManager(True) # I thought "True" was supposed to make the thing
run without a GUI window?

I am invoking fiji with the following:

~/Programs/fiji/fiji -Xms6400m -Xmx6400m -Xincgc -XX:MaxPermSize=256m
-XX:PermSize=256m -XX:NewRatio=5 -XX:CMSTriggerRatio=50
-XX:+UseCompressedOops -- --classpath ~/Programs/fiji/plugins
--headlessmyscript.py


Any ideas on what is going on?  Will the headless.java plugin help with
this?

Thanks!!
-Marcello


On Thu, Nov 7, 2013 at 4:32 AM, Ignacio Arganda-Carreras <
[hidden email]> wrote:

> Hello Marcello,
>
> Thanks for your interest in the Trainable Weka Segmentation. Let me try to
> address your questions between your lines:
>
>
>  I am trying to write a python script using the trainable weka plugin for
> > Fiji.  I am using the two libraries, imported like so:
> >
> > from trainableSegmentation import WekaSegmentation
> > from trainableSegmentation import Weka_Segmentation
> >
> >
> What do you exactly want to do? WekaSegmentation is the back-end class,
> where all the methods are stored in a library fashion. Weka_Segmentation is
> the plugin class, which contains the GUI and calls the library methods to
> perform learning and segmentation.
>
>
> >
> > My question is, how do I get the object for the learner (class
> > WekaSegmentation) I create and populate with my script to be "loaded
> > into"/used by the GUI I create with an object of class Weka_Segmentation
>
>
> If you already trained a classifier, you can get it from your
> WekaSegmentation object using the method:
>
> AbstractClassifier<
> http://weka.sourceforge.net/doc.dev/weka/classifiers/AbstractClassifier.html?is-external=true
> >
> *getClassifier
> <
> http://fiji.sc/javadoc/trainableSegmentation/WekaSegmentation.html#getClassifier()
> >*
> ()
> Returns the current classifier.
>
> Equivalently you can set a new classifier to your WekaSegmentation object
> using the method:
>
> void *setClassifier
> <
> http://fiji.sc/javadoc/trainableSegmentation/WekaSegmentation.html#setClassifier(weka.classifiers.AbstractClassifier)
> >*
> (AbstractClassifier<
> http://weka.sourceforge.net/doc.dev/weka/classifiers/AbstractClassifier.html?is-external=true
> >
>  cls)
> Set current classifier
>
> If what you want is to load a new classifier into the GUI
> (Weka_Segmentation object) then you have to do it from file using the
> following method:
>
> static void *loadClassifier
> <
> http://fiji.sc/javadoc/trainableSegmentation/Weka_Segmentation.html#loadClassifier(java.lang.String)
> >*
> (String<
> http://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true
> >
>  newClassifierPathName)
> Load a new classifier
>
> For encapsulation reasons there's no easy way to access the
> WekaSegmentation object from the GUI. There's a workaround if you need it
> by getting the object from the CustomWindow:
>
> final ImageWindow iw = WindowManager.getCurrentImage().getWindow();
> if( iw instanceof CustomWindow )
> {
> final CustomWindow win = (CustomWindow) iw;
>  final WekaSegmentation wekaSegmentation = win.getWekaSegmentation();
> }
>
>
> > .
> >
> > Or, alternatively, is there a way to get a handle for the
> WekaSegmentation
> > object (I am guessing might be) a member of the Weka_Segmentation class?
> >  This way I could just populate the images+ROIs in that.
> >
> >
> Just the way I just explained.
>
>
>
> > The goal here is to get my Images and ROIs to appear in the Plugin GUI.
> >  For now.  But with the possibility of doing all the processing headless
> > if/when the time comes...
> >
>
> I see. That's a bit tricky. The idea behind the library + plugin (GUI)
> structure is that you can call all the library methods from any script or
> plugin without the need of the GUI. If you then need to go back to the GUI,
> you're supposed to load the classifier and/or data using the corresponding
> buttons or macro commands. Why is that strategy not working for you?
>
> Best,
>
> ignacio
>
>
> --
> Ignacio Arganda-Carreras, Ph.D.
> Seung's lab, 46-5065
> Department of Brain and Cognitive Sciences
> Massachusetts Institute of Technology
> 43 Vassar St.
> Cambridge, MA 02139
> USA
>
> Phone: (001) 617-324-3747
> Website: http://bioweb.cnb.csic.es/~iarganda/index_EN.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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