Optimized Pixel Classification Using Grid Tutorial

The TensorFlow Optimized Pixel Classification tool uses a trained TensorFlow pixel segmentation model to perform inference on a raster in regions that contain features of interest identified by a trained grid model (patent pending). Run this tool as many times as needed to classify multiple rasters. The result is a classification image and a grid output vector.

You can also write a script to classify a raster using the TensorFlowOptimizedPixelClassification task.

Follow these steps:

  1. In the ENVI Toolbox, select Deep Learning > Grid > TensorFlow Optimized Pixel Classification.

  2. In the Input Raster field of the TensorFlow Pixel Classification tool, select a raster to classify. It must contain at least as many bands as the raster that was used to train the model.
  3. In the Input Trained Pixel Model field, select a trained TensorFlow model file in HDF5 format (.h5).
  4. In the Input Trained Grid Model field, select a trained TensorFlow grid model file in HDF5 format (.h5).
  5. For the Confidence Threshold, use the slider bar or up/down arrow buttons to specify a threshold value between 0 and 1.0. Bounding boxes with a confidence score less than this value will be discarded. The default value is 0.2. Decreasing this value generally results in more classification bounding boxes throughout the scene. Increasing it results in fewer classification bounding boxes.
  6. In the Output Classification Raster field, select a path and filename for the output classification raster (.dat). You must specify this or the Output Class Activation Raster, or both.
  7. Enable the Display result check box to display the output in the view when processing is complete.

  8. In the Output Class Activation Raster field, select a path and filename for the output class activation raster (.dat). This is a grayscale image, one band per feature, that shows the probability of pixels belonging to the features of interest.
  9. Enable the Display result check box to display the output in the view when processing is complete.
  10. In the Output Classification Vector field, select a path and filename for the output shapefile (.shp). The shapefile contains bounding boxes for each class.
  11. Enable the Display result check box to display the output in the view when processing is complete.
  12. To reuse these task settings in future ENVI sessions, save them to a file. Click the down arrow next to the OK button and select Save Parameter Values, then specify the location and filename to save to. Note that some parameter types, such as rasters, vectors, and ROIs, will not be saved with the file. To apply the saved task settings, click the down arrow and select Restore Parameter Values, then select the file where you previously stored your settings.

  13. To run the process in the background, click the down arrow and select Run Task in the Background. If an ENVI Server has been set up on the network, the Run Task on remote ENVI Server name is also available. The ENVI Server Job Console will show the progress of the job and will provide a link to display the result when processing is complete. See the ENVI Servers topic in ENVI Help for more information.

  14. Click OK. ENVI adds the resulting output to the Data Manager and Layer Manager.

Evaluate the Results


Optimized pixel segmentation is the process of first eliminating unnecessary portions of the raster quickly. Using grid, you can determine the areas of the raster that contain zero features of interest. Once valid areas of interest are outlined by grid, you can apply pixel classification to those areas.

The example image below was generated with the Grid_Tutorial_Data content that can be downloaded from our ENVI Tutorials web page. The grid tutorial data provides a NAIP dataset with boats that have been labeled with points using ENVI’s Labeling Tool. The input classification raster is \Classification\Rasters\massachusetts_1_20100821.tif

The following input models are in Grid_Tutorial_Data\Classification\Models:

  • TrainedPixelModel.h5

  • TrainedGridModel.h5

The output image below was generated by enabling the Display result check boxes under the Output Classification Raster and Output Classification Vector. The Confidence Threshold was set to 0.90, to detect only features with a 90% accuracy rating.

Follow these steps to overlay the output classification raster and vector over the Input Raster:

  1. Display the Input Raster in the current view.

  2. In the Layer Manager, click and drag the Input Raster below the raster and vector classification outputs.

  3. To view the input raster, clear the check box for the 0: Unclassified class of the output classification raster in the Layer Manager.

    The view should now be identical to the image above. When zoomed out to the extents of the input raster, you will see green boxes representing grid detections, and red pixels representing pixel classification.

  4. Zoom in to the image for a closeup of the results. In the Layer Manager, select the output vector classification and change the zoom to 1:10,000 from the Zoom drop-down list, highlighted in blue in the image below.

  5. In the Go To field, enter the following coordinates and press the Enter key: 2688.2629p, 5825.6826p, highlighted in the next image.

  6. To see the classified features that are under the red pixel segments, select the output classification raster in Layer Manager, then move the Transparency slider back and forth to see the underlying feature. A transparency value of 84 is good for viewing features while still easily seeing the red classification pixels.

    The example above displays multiple boats docked and in open water. Zoom in for a closer look.

  7. Use the output vector classification to determine the confidence of features detected in a given grid cell. This will help determine how well the model did and help guide additional classification using a higher or lower confidence threshold. In the Layer Manager, select the output classification vector, then right-click, and select Filter Records by Attributes.

  8. In the Filter by Attributes dialog, select the Class_ID drop-down list, then select Confidence.

  9. Move the slider bar to the far right for a 0.999 confidence search. Green squares will turn black to show the areas with the selected confidence value.

  10. If the view is still centered on the coordinates, you will see three grid cells highlighted in black and a partial top-right grid cell in black shown in the image. All black grids are 0.999 confidence of the features within in them.

See Also


Train TensorFlow Pixel Models, Train TensorFlow Grid Models, TensorFlow Grid Classification