Supervised and unsupervised classification, Sentinel 2

In general it works fine.
For some data there are errors. But give it a try - in most of the cases it will perform great.

Good morning everyone,

I am also a student trying to work with the Supervised Classification.
I am trying to classify a raster formed by several bands, each of them containing the temporal profile of a VI o similar features; the bands were derived from landsat8 data.

I have tried to perform the Random Forest and I got the error “bound must be positive”, even if all the values of the used bands were >=0.
I have also tried with MLC and MD, but, just like the people above in this discussion, I got a blank raster, full with NaN.

Has anyone managed to understand what is the problem behind these errors?


‘bound’ could refer to the coordinates of your data. Did you project your raster to a coordinate system? Which one?
What kind of data are you working on?

Generally in java this error means your item is empty, here your image (if a java expert can confirm ?) and when he tries to jump to the next item’s object (pixel) bound is negative (don’t know if it’s clear).

So there’s a problem with the image reading I guess (again if someone can confirm would be great :slight_smile: )

hi , Unfortunately I have the same problem

After the reprojection, I got some output:

Thanks for your reply.



I want to make a supervised classification (RF or SVM), I chose the region of interest, when I do the classification RF I receive the following error “bound must be positive”, I made the reprojection and still I have a problem: the LabeledClasses layer is displayed in black, I can not see the different classes.

Please help me solve this problem

I need tutorials, documents or video on classification under SNAP

I am not sure about “bound must be positive”.
What I did for preprocessing the product:

  1. Atmospheric correction: Sen2Cor algorithm [S2A_OPER…]
  2. Resampling the new product [S2A_USER…]
  3. Subset the area of interest (AOI)
  4. Reproject the AOI
  5. Training vectors (masks) [cluster of pixels]: forest, crop, urban, soil …
  6. Apply the supervised classification algorithm (iterative)


I read in the SNAP tutorial that it supports the SVM classification, but I do not find it in the supervised classification menu.

Is that someone you have already worked with SVM under SNAP ???

Thank you in advance!

I’m not sure but I think it was included once but was then removed again. It was available only a short time between two updates.

1 Like

OK ABraum

Thank you for your answer.

The SVM is implemented but not yet ready for all to use. I’m not sure when I’ll have time to get back to it - maybe by spring.

The SVM is implemented but not yet ready for all to use. I’m not sure when
I’ll have time to get back to it - maybe by spring.


Hi zgramos,
What is the spatial resolution of the result of the classification ??

It is the same as the source image.

Thanks for your quick reply, you used all ten bands for the classification ???

Depends on the goal, but it’s a good start.

Ok thank you, my goal is to do the mapping of the annual crop types, and I need the bands of SWIR and red Edge for the classification.

I could not run the KNN classifier despite reproducing exact steps as described. I made vector layers with training areas and saved the product. Then I ran KNN on vanilla SNAP 5.0. The classifier ran without error, but output data were null, as someone else had.
Then I upgraded the SNAP installation to the latest version and I got Error: [NodeId: KNN-Classifier] node when entering the KNN-Classifier tab.

Can you look into it? :frowning:

Here’s a log snippet I managed to find:

org.esa.snap.core.gpf.graph.GraphException: [NodeId: KNN-Classifier] node
	at org.esa.snap.core.gpf.graph.NodeContext.initTargetProduct(
	at org.esa.snap.core.gpf.graph.GraphContext.initNodeContext(
	at org.esa.snap.core.gpf.graph.GraphContext.initNodeContext(
	at org.esa.snap.core.gpf.graph.GraphContext.initOutput(
	at org.esa.snap.core.gpf.graph.GraphContext.<init>(
	at org.esa.snap.core.gpf.graph.GraphContext.<init>(
	at org.esa.snap.graphbuilder.rcp.dialogs.GraphBuilderDialog.InitGraph(
	at org.esa.snap.graphbuilder.rcp.dialogs.GraphBuilderDialog.ValidateAllNodes(
	at org.esa.snap.graphbuilder.rcp.dialogs.GraphBuilderDialog.access$000(
	at org.esa.snap.graphbuilder.rcp.dialogs.GraphBuilderDialog$1.stateChanged(
	at javax.swing.JTabbedPane.fireStateChanged(Unknown Source)
	at javax.swing.JTabbedPane$ModelListener.stateChanged(Unknown Source)
	at javax.swing.DefaultSingleSelectionModel.fireStateChanged(Unknown Source)
	at javax.swing.DefaultSingleSelectionModel.setSelectedIndex(Unknown Source)
	at javax.swing.JTabbedPane.setSelectedIndexImpl(Unknown Source)
	at javax.swing.JTabbedPane.setSelectedIndex(Unknown Source)
	at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(Unknown Source)
	at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$ Source)

Nothing has changed in the updates for the classifiers. However, this looks like a similar bug to the one reported recently involving S2 masks. This should be fixed now and will be available soon.