This article is intended as a quick primer to get you started using some of the Machine Learning operators introduced with ERDAS IMAGINE 2018.
There are two broad categories of Machine Learning classifiers introduced in ERDAS IMAGINE 2018. One deals with the broader category of Machine Learning which can be thought of as traditional classifiers (supervised or unsupervised) and includes Random Forest, Support Vector Machines (SVM), CART, etc. There's also a more modern, narrower sub-group referred to as Deep Learning.
This article will deal with the broader Machine Learning category by looking at the Random Forest algorithm. The same approach can be used for the other algorithm Operators which fall into this category (substitute Initialize SVM for Initialize Random Forest, for example).
The data we have to work with in our example is a 4-band CIR air photo (land_cover.img), a set of polygons derived from segmenting the image (unclassified_land_cover_segments.shp) and another set of polygons representing our training locations of known landcover classes (land_cover_training_data.shp), The screenshot below shows the training polygons overlaid on the image with the shapefile's attribute information displayed. The only attributes we start with are the landcover class names of the training polygons.
|land_cover_training_data.shp overlaid on land_cover.img|
What we are going to do in this scenario is use information derived from the airphoto at the locations of the training polygons to train the Random Forest algorithm. We are then going to use the trained Random Forest network (termed a Machine Intellect) to classify the segmentation polygons (i.e. to assign each polygon with the highest probability landcover type). We'll do the classification step using the same airphoto as an input, but the trained Machine Intellect could be used to classify other (similar) airphotos and polygons. It is important to note that we are not classifying the image. We aren't even classifying the geometries associated with the segmentation polygons. The Machine Learning algorithms are simply classifying the features - the rows of attribute numbers that are present in the database of information are what is important and used by Machine Learning. This is a critical point to understand: It is only by providing meaningful attribute information associated to each feature record that Machine Learning can learn (be trained) and then classify.
It is also a critical point to understand that for this broader category of Machine Learning algorithms, it is down to the user (designing the Spatial Model) to know and understand what types of information are appropriate to provide as attribute fields in order to classify the data into the desired landcover classes. This is in comparison to Deep Learning algorithms which tend to figure out for themselves what information needs to be derived from the training data provided.
For example, if trying to discriminate a Forest landcover class from a Grassland class, from a Water class, the designer of a Random Forest Spatial Model should understand that providing the NIR and Red color information will be important in differentiating vegetation from water, and texture is going to help discriminate between forest and grassland. And if we train a classifier based on these types of information input we will also have to provide the same type of information when it comes time to classify a different set of data.
With that in mind let's take a look at how the Training model has been constructed:
This simple example model has two inputs. The first is a Features Input which ingests the land_cover_training_data.shp shapefile and turns it into a Features steam. It's these Features that will form the primary set of information used by the Random Forest algorithm. But on input they are simply Features which only have two main attributes associated with them - the Geometry field and the Class known to exist at the location of the geometry.
The second input is the Raster Input which ingests the land_cover.img airphoto. This raster stream will be used as the basis for extracting the attribute information we want to associate with the training Features.
So the two inputs feed into the next Operator which is a Raster Statistics per Feature operator. This has been set to extract the Mean DN and Standard Deviation (SD) values per band within the spatial extent of the Geometry associated with each Features. In other words, each Feature record gains 8 new attribute fields, one for each band, containing the mean DN and SD value in that polygon. Other basic statistics could also be added, such as Mode, Median, etc. But for this simple example we just use Mean and SD.
The Features are then fed to the Kurtosis Texture per Feature Operator. Again this makes a measurement per geometry, but this time it is a measure of the texture of the imagery within the geometry extent. Again this information is added to the Features stream as new attribute fields and values, one per band. Note that the raster stream plays no further part in the Model beyond this point - it's the Features (and their attributes) that are used to train the classifier.
But we could have added far more sets of derived information to the Features if we were performing a true training and classification process. We might have derived information from band ratios, Tasseled Cap transformations, different texture measures, other raster or vector features sources (such as Slope and Aspect derived from a DEM), and so on. Just remember that what attributes you measure and use for Training also have to be provided when it comes to Classification. If you provided TC1 as an input when training, you'll need to be able to generate TC1 as an attribute field for the data to be classified.
Next is the Select Attributes operator. The vector layer we fed into the model may have contained existing attribute fields that would play no (positive) part in constructing a Random Forest network. So it's important to identify exactly which attribute fields are going to be used in the Initialize Random Forest operator. One of the attribute fields must identify the "Classes" you are interested in (in this case, the Name field) as well as all the attribute fields you have identified as providing information that helps discriminate between those classes. So effectively you could perform Machine Learning using just Features (you don't even need Geometries), so long as you have all the attribute information you need associated with the Features.
Then it's straight into the Initialize Random Forest operator. this "crunches the numbers" and constructs a random forest network which best describes the relationship between the Classes and the attribute information associated to each of those classes. Once constructed (trained) this network can be used to ingest other sets of attribute information and separate them into their most likely class matches. But we don't do that in this model - we just train and then feed the network to the Machine Intellect Output operator to create a file which encapsulates the trained Random Forest network.
By limiting the Training step to its own Model we can train once and then re-use the Machine Intellect file to classify multiple times in a separate Model (without needing to re-run the training step each time). This is the more common way of approaching Machine Learning. But if we just had one set of data to train and classify, you could combine the Training Model and the Classification Model (described below) into a single model and not output the Machine Intellect file.
Now let's take a look at how the Classification model has been constructed:
As mentioned above, when classifying you need to provide the same attribute fields that you used to train the Machine Intellect (the Random Forest network in this instance). So one of the biggest time-savers you can make for yourself when constructing your classification model is to copy / paste the majority of the "attribute generation" steps (including the Input operators) from the Training model to the Classification model as a starting point. This way you are more or less guaranteed to set the Classification model up correctly to supply all the necessary training attributes populated and named in the manner expected by the trained Machine Intellect.
Really then all that's required is to add the Classify Using Machine Learning operator fed by a Machine Intellect Input operator and a Features Output to write out the features with the Class association made to each record. You can also add any clean-up operators you might want to use as well, such as a Merge Features to dissolve the boundaries between neighboring polygons with he same Class. But in this example we've left it simple.
So in this Classification model we have three inputs:
The model then measures all the attributes and associates them to the Features stream and feeds those, plus the Machine Intellect, to the Classify Using Machine Learning operator, which "crunches the numbers" and produces output Features that have a new attribute filed identifying the most probable Class for each feature. This particular model is set to also create and populate Probability fields for each class assignment. The screenshot below shows the classified features overlaid on the airphoto
|Output features containing landcover classification attributes produced by the Random Forest classifier|
There you have it - simple example models showing the theory behind training a Random Forest machine learning network and using that network to classify other data. In this instance we classified the Features. However it is certainly possible to apply the same techniques to directly classify a raster image (and produce a raster classification layer), but in that instance you would use point features to train the classifier. That process will be the focus of a further Spatial Recipe. Or, more likely, an eTraining video, as will the process for using Deep learning and also the Machine Learning Layout.