CLIJ Weka segmentation exception

Hi All,

I am trying to use weka in CLIJ to do some machine learning to pull some blobs out of my images.

Pretty sure i have followed everything like i should but i keep getting a java.lang.ClassCastException: [B cannot be cast to [F error when trying to train the classifier.

Below is an example code that generates the feature stack and ground truth images using the blobs demo image. If you then take those images and try to train the classifier on them you get an error.

Any ideas on what is going on?

run("CLIJ2 Macro Extensions");

run("Blobs (25K)");

image1 = "blobs.gif";

image2 = "Feature Stack";
feature_definitions = "original gaussianBlur=1 gaussianBlur=2 gaussianBlur=4 gaussianBlur=8 gaussianBlur=16 SobelofGaussian=1 SobelofGaussian=2 SobelofGaussian=4 SobelofGaussian=8 SobelofGaussian=16 LaplacianofGaussian=1 LaplacianofGaussian=2 LaplacianofGaussian=4 LaplacianofGaussian=8 LaplacianofGaussian=16 entropy=1 entropy=2 entropy=4 entropy=8 entropy=16";
Ext.CLIJx_generateFeatureStack(image1, image2, feature_definitions);


newImage("Ground Truth", "8-bit black", 256, 254, 1);
selectWindow("Ground Truth");
makeOval(65, 30, 19, 20);
selectWindow("Ground Truth");
makeOval(103, 37, 18, 14);
run("Select None");
setMinAndMax(0, 2);

Hi @Cameron.Nowell

How do you train and what’s the full error message? :slightly_smiling_face:

Maybe a link to a (bit old) example script helps: clijx/weka_segmentation.ijm at c6f5ece952acd4384a02ad34317e3a138d1aba06 · clij/clijx · GitHub

Furthermore, you can train those models interactively in the assistant and generate a script to apply them.

Let me know if this helps!


@haesleinhuepf that old script was exactly what i needed. Looking through it it looked pretty much identical to what i was doing except for one thing. Your ground truth image was 32bit mine was 8.

As soon as i changed it to 32bit it all works. Didn’t realise that would be an issue. I assumed a value of 1 intensity would be the same no matter what…


Ok, that looks like a bug then. I can dive a bit into this. Would you mind sharing the full error log? That helps me reproducing the issue.

1 Like

This is the only error info i get out. Is there something else i can pull out?

java.lang.ClassCastException: [B cannot be cast to [F
at net.haesleinhuepf.clijx.weka.CLIJxWeka.featureStackToInstance(
at net.haesleinhuepf.clijx.weka.CLIJxWeka.trainClassifier(
at net.haesleinhuepf.clijx.weka.CLIJxWeka.saveClassifier(
at net.haesleinhuepf.clijx.weka.CLIJxWeka2.saveClassifier(
at net.haesleinhuepf.clijx.weka.TrainWekaModel.trainWekaModel(
at net.haesleinhuepf.clijx.weka.TrainWekaModel.executeCL(
at ij.plugin.filter.PlugInFilterRunner.processOneImage(
at ij.plugin.filter.PlugInFilterRunner.(
at ij.IJ.runUserPlugIn(
at ij.IJ.runPlugIn(
at ij.Executer.runCommand(

1 Like

Thanks, that’s it what I need to debug efficiently :smiley:

1 Like