Login  Register

Re: weka segmentation in batch mode

Posted by Aryeh Weiss on Mar 22, 2014; 5:24pm
URL: http://imagej.273.s1.nabble.com/weka-segmentation-in-batch-mode-tp5007024p5007044.html

On 3/21/14, 7:00 PM, William Menegas wrote:

> Thanks for all the suggestions!
>
> I'll try the 'quick fix' which is based on Aryeh's suggestion:
>
> call("trainableSegmentation.Weka_Segmentation.getProbability");
> waiting = 0;
> while (waiting == 0){
> if (isOpen("Probability maps") == true)
> waiting = 1;
> else
> wait(10000);
> }
> selectWindow("Probability maps");
>
> If that doesn't work, I'll try rewriting everything to run as a beanshell
> script, or just the weka part as a beanshell script - as Ignacio suggested.
If so, here is a better version. It does not require that elapsedTime be
exactly 10000ms when you test it:

     initTime = getTime();
     oldTime = initTime;
     while (!isOpen("Output")) {
         elapsedTime = getTime() - initTime;
         newTime = getTime() - oldTime;
         if (newTime > 10000) {
             oldTime = getTime();
             newTime = 0;
             print(elapsedTime/1000, " seconds elapsed");
         }

     }
     wait(1000); // to make sure that the window is really ready...

I hope it helps

--aryeh

> And I was planning on running this on a cluster, so I'll check out Larry's
> plugin as well...
>
> Thanks again everybody!
> Will
>
>
> On Fri, Mar 21, 2014 at 12:14 PM, Larry Lindsey <[hidden email]>wrote:
>
>> Hi List,
>>
>> I ran into a similar problem a little while ago. There's a plugin (full
>> disclosure: I wrote it) for the 2D case [1]. It's intended to run on a
>> networked cluster, but it would be simple to modify it for single computers
>> as well. Let me know if that sounds like it would be useful.
>>
>> Larry
>>
>> 1: http://fiji.sc/FijiArchipelago#Batch_Weka_Segmentation
>>
>>
>> On Fri, Mar 21, 2014 at 3:56 AM, Ignacio Arganda-Carreras <
>> [hidden email]> wrote:
>>
>>> Hello Aryeh and Will,
>>>
>>> For the classification task I think it's a bit risky to use a delay
>> anyway
>>> because you don't know how long the classification will take. Have you
>>> tried using a script instead of a macro? That allows you to have much
>> more
>>> control over the images and the commands are executed as in a regular
>>> program, so you won't need any wait call.
>>>
>>> Have a look at:
>>>
>>> http://fiji.sc/Scripting_the_Trainable_Segmentation
>>>
>>> A simple Beanshell script equivalent to your macro code would be:
>>>
>>> import trainableSegmentation.*;
>>>
>>>   // input train image
>>>   input  = IJ.openImage( "input-grayscale-or-color-image.tif" );
>>>   // create Weka Segmentation object
>>>   segmentator = new WekaSegmentation( input );
>>>   // load classifier from file
>>>   segmentator.loadClassifier( "my-cool-trained-classifier.model" );
>>>
>>>   // apply classifier to current training image and get label result
>>>   // (set parameter to true to get probabilities)
>>>   segmentator.applyClassifier( false );
>>>   // get result (float image)
>>>   result = segmentator.getClassifiedImage();
>>> Let me know if you have questions about it!
>>>
>>> ignacio
>>>
>>>
>>>
>>> On Fri, Mar 21, 2014 at 7:11 AM, Aryeh Weiss <[hidden email]>
>> wrote:
>>>> On 3/21/14, 7:52 AM, William Menegas wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I was wondering if anyone could give me some advice on using "Weka
>>>>> Segmentation" in headless mode or in a normal session of fiji in batch
>>>>> mode. I am using:
>>>>>
>>>>> ...
>>>>> run("Trainable Weka Segmentation");
>>>>> call("trainableSegmentation.Weka_Segmentation.loadClassifier",
>>>>> "/path/classifier.model");
>>>>> call("trainableSegmentation.Weka_Segmentation.getProbability");
>>>>> selectWindow("Probability maps");
>>>>> ...
>>>>>
>>>>> The problem is that fiji doesn't seem to want to wait for the
>>>>> classification. I tried inserting "wait(100000)" before
>>>>> "selectWindow("Probability maps"), but it didn't help and I don't
>> think
>>>>> there was even a wait.
>>>>>
>>>>> Any help would be much appreciated!
>>>>> Will
>>>>>
>>>>> --
>>>>> ImageJ mailing list:http://imagej.nih.gov/ij/list.html
>>>>>
>>>>>   I had a similar problem with the EDF plugin. Here is a quote form
>> that
>>>> post:
>>>>
>>>>> The problem I have is that the macro does not wait for EDF to finish,
>>> and
>>>>> EDF can take a while.
>>>>> My solution to this is based on the fact that EDF creates a window
>>> called
>>>>> "Output". so I did the following:
>>>>>
>>>>> initTime = getTime();
>>>>> while ( !isOpen("Output") ) {
>>>>>      elapsedTime = getTime() - initTime;
>>>>>      if (elapsedTime%10000 == 0) {
>>>>>          print(elapsedTime/1000, " seconds elapsed");
>>>>>          wait(10);
>>>>>      }
>>>>>
>>>>> which works (as  long as there is no other window called "Output"). I
>>>>> print an occasional reminder that the macro is still alive within this
>>> wait
>>>>> loop.
>>>>>
>>>> I posted this as a question, wondering if there is a better way to do
>> it.
>>>> I did not receive any reply, so perhaps in a macro this is the way to
>> go.
>>>> You should replace "Output" with "Probability maps".
>>>>
>>>> --aryeh
>>>>
>>>> --
>>>> Aryeh Weiss
>>>> Faculty of Engineering
>>>> Bar Ilan University
>>>> Ramat Gan 52900 Israel
>>>>
>>>> Ph:  972-3-5317638
>>>> FAX: 972-3-7384051
>>>>
>>>>
>>>>
>>>> --
>>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>>>
>>>> --
>>>> 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://imagej.nih.gov/ij/list.html>
>>>> 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
>>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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