Caused by: java.lang.OutOfMemoryError: Java heap space

Hello
I am trying to segment a light sheet image with weka segmentation. the total image stack is only one time point and about 200 MB. I keep getting this error, see below. Does anybody have a suggestion how to get around this? The computers I work on have 32 or 64 Gb ram and as far as I can understand my Fiji is set well above the image size in memory allocation.
Best regards
Fredrik

WARNING: core mtj jar files are not available as resources to this classloader (sun.misc.Launcher$AppClassLoader@c387f44)
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
	java.util.concurrent.FutureTask.report(FutureTask.java:122)
	java.util.concurrent.FutureTask.get(FutureTask.java:192)
	trainableSegmentation.FeatureStack3D.updateFeaturesMT(FeatureStack3D.java:1083)
	trainableSegmentation.WekaSegmentation.trainClassifier(WekaSegmentation.java:5279)
	trainableSegmentation.Weka_Segmentation$4.run(Weka_Segmentation.java:1461)

	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at trainableSegmentation.FeatureStack3D.updateFeaturesMT(FeatureStack3D.java:1083)
	at trainableSegmentation.WekaSegmentation.trainClassifier(WekaSegmentation.java:5279)
	at trainableSegmentation.Weka_Segmentation$4.run(Weka_Segmentation.java:1461)
Caused by: java.lang.OutOfMemoryError: Java heap space

Dear @fwallberg,

Sorry for the late answer. Even if your image takes only 200 MB, the number of image features created in the Trainable Weka Segmentation plugin may increase the RAM consumption a lot. To avoid running into memory problems, I would try either reducing the number of features in the Settings dialog, or training on a sub-stack of your original data and then applying the saved classifier to the whole stack using this script that divides the image into tiles to save memory.

Let me know if that solves your problem!

2 Likes

Thanks, I will give that a try.

Dear @iarganda,

Sorry for bumping this conversation again.
I actually had the same problem so I tried reducing the number of features in Settings but it didn’t solve the problem, so I tried the script and got this error message:

<eval>:9:0 Expected an operand but found import
import trainableSegmentation.WekaSegmentation;
^ in <eval> at line number 9 at column number 0

I would greatly appreciate any other suggestions!
Thank you in advance.

In the Language menu of the Script Editor, did you set the language to BeanShell before trying to run it?

1 Like

Thank you for your reply!
I just did and got this:
Attempt to resolve method: equals() on undefined variable or class name: resultMode in line number 19

I apologize in advance, I’m very new to this.

@seulbs Hmm, that shouldn’t be possible. (Famous last words!) Are you using the ImageJ2 Script Editor? File > New > Script…? After pasting in the script and changing the language to BeanShell, then clicking the Run button, do you see a dialog box like this appear?

03%20

Which version of Fiji are you using?

1 Like