pkann(1) classify raster image using Artificial Neural Network


pkann -t training [-i input] [-cv value] [options] [advanced options]


pkann implements an artificial neural network (ANN) to solve a supervised classification problem. The implementation is based on the open source C++ library ( fann <> ). Both raster and vector files are supported as input. The output will contain the classification result, either in raster or vector format, corresponding to the format of the input. A training sample must be provided as an OGR vector dataset that contains the class labels and the features for each training point. The point locations are not considered in the training step. You can use the same training sample for classifying different images, provided the number of bands of the images are identical. Use the utility pkextract(1) to create a suitable training sample, based on a sample of points or polygons. For raster output maps you can attach a color table using the option -ct.


-i filename, --input filename
input image
-t filename, --training filename
training vector file. A single vector file contains all training features (must be set as: B0, B1, B2,...) for all classes (class numbers identified by label option). Use multiple training files for bootstrap aggregation (alternative to the --bag and --bsize options, where a random subset is taken from a single training file)
-tln layer, --tln layer
training layer name(s)
-label attribute, --label attribute
identifier for class label in training vector file. (default: label)
-prior value, --prior value
prior probabilities for each class (e.g., -prior 0.3 -prior 0.3 -prior 0.2 )
-cv value, --cv value
n-fold cross validation mode (default: 0)
-nn number, --nneuron number
number of neurons in hidden layers in neural network (multiple hidden layers are set by defining multiple number of neurons: -nn 15 -nn 1, default is one hidden layer with 5 neurons)
-m filename, --mask filename
Only classify within specified mask (vector or raster). For raster mask, set nodata values with the option --msknodata.
-msknodata value, --msknodata value
mask value(s) not to consider for classification. Values will be taken over in classification image. Default is 0.
-nodata value, --nodata value
nodata value to put where image is masked as nodata (default: 0)
-o filename, --output filename
output classification image
-ot type, --otype type
Data type for output image ({Byte / Int16 / UInt16 / UInt32 / Int32 / Float32 / Float64 / CInt16 / CInt32 / CFloat32 / CFloat64}). Empty string: inherit type from input image
-of GDALformat, --oformat GDALformat
Output image format (see also gdal_translate(1)). Empty string: inherit from input image
-f OGRformat, --f OGRformat
Output ogr format for active training sample (default: SQLite)
-ct filename, --ct filename
colour table in ASCII format having 5 columns: id R G B ALFA (0: transparent, 255: solid)
Creation option for output file. Multiple options can be specified.
-c name, --class name
list of class names.
-r value, --reclass value
list of class values (use same order as in --class option).
-v 0|1|2, --verbose 0|1|2
set to: 0 (results only), 1 (confusion matrix), 2 (debug)

Advanced options

-bal size, --balance size
balance the input data to this number of samples for each class (default: 0)
-min number, --min number
if number of training pixels is less then min, do not take this class into account (0: consider all classes)
-b band, --band band
band index (starting from 0, either use --band option or use --start to --end)
-sband band, --startband band
start band sequence number (default: 0)
-eband band, --endband band
end band sequence number
-offset value, --offset value
offset value for each spectral band input features: refl[band]=(DN[band]-offset[band])/scale[band]
-scale value, --scale value
scale value for each spectral band input features: refl=(DN[band]-offset[band])/scale[band]
-a 1|2, --aggreg 1|2
how to combine aggregated classifiers, see also --rc option (1: sum rule, 2: max rule).
--connection 0|1
connection rate (default: 1.0 for a fully connected network)
-w weights, --weights weights
weights for neural network. Apply to fully connected network only, starting from first input neuron to last output neuron, including the bias neurons (last neuron in each but last layer)
-l rate, --learning rate
learning rate (default: 0.7)
--maxit number
number of maximum iterations (epoch) (default: 500)
-comb rule, --comb rule
how to combine bootstrap aggregation classifiers (0: sum rule, 1: product rule, 2: max rule). Also used to aggregate classes with --rc option. Default is sum rule (0)
-bag value, --bag value
Number of bootstrap aggregations (default is no bagging: 1)
-bs value, --bsize value
Percentage of features used from available training features for each bootstrap aggregation (one size for all classes, or a different size for each class respectively. default: 100)
-cb filename, --classbag filename
output for each individual bootstrap aggregation (default is blank)
--prob filename
probability image. Default is no probability image
-na number, --na number
number of active training points (default: 1)


Classify input image input.tif with an Artificial Neural Network using one hidden layer with 5 neurons. A training sample that is provided as an OGR vector dataset. It contains all features (same dimensionality as input.tif) in its fields (please check pkextract(1) on how to obtain such a file from a "clean" vector file containing locations only). A two-fold cross validation (cv) is performed (output on screen).

pkann -i input.tif -t training.sqlite -o output.tif --nneuron 5 -cv 2

Same example as above, but use two hidden layers with 15 and 5 neurons respectively.

pkann -i input.tif -t training.sqlite -o output.tif --nneuron 15 --neuron 5 -cv 2