Hi all,
I am trying to use the WekaSegmentation class available among fiji's plugins. So, I use the addElement method to add examples to each of my two classes, and then i run the classifier with the trainClassifier method. The problem is that I have the following error message: "Cannot train without at least 2 sets of examples!". (the examples exist, i can see the number of examples for each classes with 'weka.getExamples(OTHER_CLASS, SLICE).size()') Would you have any solution for my problem? Sincerely, Davd |
Hello David,
Can you please send me the piece of code you're using to reproduce your error? thanks! ignacio On Thu, Mar 22, 2012 at 6:43 AM, David Rueda <[hidden email]> wrote: > Hi all, > > I am trying to use the WekaSegmentation class available among fiji's plugins. > So, I use the addElement method to add examples to each of my two > classes, and then i run the classifier with the trainClassifier > method. > The problem is that I have the following error message: "Cannot train > without at least 2 sets of examples!". > (the examples exist, i can see the number of examples for each classes > with 'weka.getExamples(OTHER_CLASS, SLICE).size()') > > Would you have any solution for my problem? > > Sincerely, > Davd -- 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 |
Here is the code i am using:
> ImagePlus imp = getImp(); > WekaSegmentation weka = new WekaSegmentation(); > weka.setTrainingImage(imp); > weka.setNumOfClasses(2); > > if (imp.getProcessor().getNChannels() != 3) > throw new ScriptException(Bundle.UI.getString("message_rgbonly")); > > ColorProcessor cp = new ColorProcessor(imp.getImage()); > for (int x = 0; x < imp.getWidth(); x++) { > for (int y = 0; y < imp.getHeight(); y++) { > int[] pixel = imp.getPixel(x, y); > if (pixel[0] == 0 && pixel[1] == 255 && pixel[2] == 255) { > cp.setColor(Color.BLACK); > } else { > cp.setColor(Color.WHITE); > } > cp.drawPixel(x, y); > } > } > // weka.addExample(OTHER_CLASS, negSelection, SLICE); > > imp.setImage(cp.convertToByte(true).createImage()); > > ResultsTable paResults = new ResultsTable(); > ParticleAnalyzer particleAnalyzer = new ParticleAnalyzer( > ParticleAnalyzer.SHOW_NONE, > Measurements.RECT | Measurements.ELLIPSE, > paResults, > 0.0, > INFINITY > ); > particleAnalyzer.analyze(imp); > > // X Y Major Minor Angle > ImagePlus labelImp = imp.duplicate(); > for (int row = 0; row < paResults.getCounter(); row++) { > double bX = paResults.getColumnAsDoubles(paResults.getColumnIndex("BX"))[row], > bY = paResults.getColumnAsDoubles(paResults.getColumnIndex("BY"))[row], > bWidth = paResults.getColumnAsDoubles(paResults.getColumnIndex("Width"))[row], > bHeight = paResults.getColumnAsDoubles(paResults.getColumnIndex("Height"))[row], > eAngle = paResults.getColumnAsDoubles(paResults.getColumnIndex("Angle"))[row]; > > EllipseRoi posSelection = null; > if (eAngle < 90) { > posSelection = new EllipseRoi(bX + bWidth, bY, bX, bY + bHeight, 0.60); > } else { > posSelection = new EllipseRoi(bX, bY, bX + bWidth, bY + bHeight, 0.60); > } > > posSelection.setFillColor(Color.BLACK); > labelImp.getProcessor().fillPolygon(posSelection.getPolygon()); > weka.addExample(OSTEO_CLASS, posSelection, SLICE); > } > > int[] xpoints = {928,897,800,756,627,462,372,233,238,149,159,441,502,586,622,661,680,710,701,498}; > int[] ypoints = {727,571,664,852,800,702,700,811,892,959,910,927,842,748,664,556,399,302,229,149}; > weka.addExample(OTHER_CLASS, new PolygonRoi(xpoints,ypoints,20,Roi.POLYLINE), SLICE); > > System.out.println(weka.getExamples(OTHER_CLASS, SLICE).size()); > System.out.println(weka.getExamples(OSTEO_CLASS, SLICE).size()); > > if (weka.trainClassifier()) { > weka.applyClassifier(false); > weka.getClassifiedImage().show(); > } Thanks, Davd Le 22 mars 2012 15:02, Ignacio Arganda-Carreras <[hidden email]> a écrit : > Hello David, > > Can you please send me the piece of code you're using to reproduce your error? > > thanks! > > ignacio > > On Thu, Mar 22, 2012 at 6:43 AM, David Rueda <[hidden email]> wrote: >> Hi all, >> >> I am trying to use the WekaSegmentation class available among fiji's plugins. >> So, I use the addElement method to add examples to each of my two >> classes, and then i run the classifier with the trainClassifier >> method. >> The problem is that I have the following error message: "Cannot train >> without at least 2 sets of examples!". >> (the examples exist, i can see the number of examples for each classes >> with 'weka.getExamples(OTHER_CLASS, SLICE).size()') >> >> Would you have any solution for my problem? >> >> Sincerely, >> Davd > > > > -- > 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 |
Hello again David,
The error comes from the fact that you don't add examples to (at least) two classes. You need to have samples of of two classes to start training. If you have a binary image with the labels of one class in white and the labels of the other class in black, I would recommend you to use this method: http://fiji.sc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=src-plugins/Trainable_Segmentation/trainableSegmentation/WekaSegmentation.java;h=f3222f5c88e5e7514a16dea632f0f5c10087421a;hb=HEAD#l822 Cheers! 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 |
Ok thanks you, now the trainclassifier is launched. But also, the it
block the execution of the end of my script... Of course the train classifier takes some seconds, but i can not understand why the instructions after the trainClassifier method are not executed. Do you have an idea? thank you a lot! Davd Le 22 mars 2012 15:46, Ignacio Arganda-Carreras <[hidden email]> a écrit : > Hello again David, > > The error comes from the fact that you don't add examples to (at > least) two classes. You need to have samples of of two classes to > start training. > > If you have a binary image with the labels of one class in white and > the labels of the other class in black, I would recommend you to use > this method: > > http://fiji.sc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=src-plugins/Trainable_Segmentation/trainableSegmentation/WekaSegmentation.java;h=f3222f5c88e5e7514a16dea632f0f5c10087421a;hb=HEAD#l822 > > Cheers! > > 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 |
Free forum by Nabble | Edit this page |