Optimized Pixel Classification Using Grid Tutorial

You can train a TensorFlow grid model to locate regions containing targets of interest.

You can also write a script to train a model using the TrainTensorFlowGridModel task.

See the following sections:

Select Training and Validation Rasters


  1. Choose one of the following options to start the Train TensorFlow Grid Model tool:
    • In the ENVI Toolbox, select Deep Learning > Grid > Train TensorFlow Grid Model.
    • In the Deep Learning Guide Map, click this sequence of buttons: Grid > Train a New Grid Model > Train Grid Model.

    The Train TensorFlow Grid Model dialog appears with the Main tab selected. Use this tab to specify the training rasters, validation rasters, and output models.

  2. Click the Add File(s) button next to the Training Rasters field. Select one or more object detection rasters that you want to use for training, and click Open. They are added to the Training Rasters field. Use the Build Object Detection Raster from Annotation or Build Object Detection Raster from ROI tool to create them.

  3. Click the Add File(s) button next to the Validation Rasters field. These are separate object detection rasters that can be used to evaluate the accuracy of a TensorFlow model. Although classification accuracy is typically better if you use different rasters for training and validation, you can still use the same raster for both.

  4. Specify a filename (.h5) and location for the Output Model. This will be the "best" trained model, which is the model from the epoch with the lowest validation loss. By default, the tool will save the best and last model. Usually, the best model will perform the best compared to the last model, but not always. Having both outputs lets you choose which model works best for your scenario.
  5. Specify a filename (.h5) and location for the Output Last Model. This will be the trained model from the last epoch. Usually, the best model will perform the best compared to the last model, but not always. Having both outputs lets you choose which model works best for your scenario.

Set Model Parameters


Select the Model tab. These parameters are optional.

  1. Enter a Model Name. If you do not provide one, "ENVI Deep Learning Grid" will be used as the model name.

  2. Enter a Model Description in the field provided.

  3. From the Model Architecture drop-down list, specify the model architecture to use for training the model. Pre-trained weights for the given architecture will be used as a starting point to enhance model performance. The options are:

    • ResNet50

    • ResNet101

  4. In the Grid Size field, enter the size of the grid bounding box. This number is squared and also represents the patch rows and columns dimensions. The grid size must be a multiple of 32. The default is 224.

Set Training Parameters


Select the Training tab. The parameters on the Training tab are designed for users who want more control over how a TensorFlow model learns to recognize features during training. They are all optional.

If you are not sure how to set the values for these fields, you can use the ENVI Modeler to create random values. See Train Deep Learning Models Using the ENVI Modeler for details.

  1. Set the Augment Scale option to Yes to augment the training data with resized (scaled) versions of the data. See Data Augmentation.
  2. Set the Augment Rotation option to Yes to augment the training data with rotated versions of the data. See Data Augmentation.
  3. In the Number of Epochs field, enter the number of epochs to run. An epoch is a full pass of the entire training dataset through the algorithm's learning process. Training inputs are adjusted at the end of each epoch. The default value is 100. See Epochs and Batches for more information.
  4. In the Patches per Batch field, specify the number of patches to run per batch. A batch comprises one iteration of training; model parameters are adjusted at the end of each iteration. Batches are run in an epoch until the number of patches per epoch is met or exceeded. The default value is 5.
  5. In the Feature Patch Percentage field, enter the percentage of patches containing labeled features to use during training. Values should range from 0 to 1 and applies to both the training and validation datasets. The default value is 1. Example: You have a grid raster with 50 patches that contain labeled features. A value of 0.4 means that 20 of those patches will be used for training (20/50 = 0.4, or 40%), whereas a value of 1 means 100% of those patches will be used for training. The number of resulting patches is used as input to the Background Patch Ratio field. Note that if you have a large training dataset (hundreds of images), lowering the Feature Patch Percentage will reduce training time.

  6. In the Background Patch Ratio field, specify the ratio of background patches containing zero features to patches with features. A ratio of 1.0 for 100 patches with features would provide 100 patches without features. The default value is 0.5. In cases where features are sparse in a training raster, the training can be biased by empty patches throughout. This parameter allows you to restrict the number of empty patches, relative to those that contain features.

Set Advanced Parameters


Select the Advanced tab. The parameters on the Advanced tab are designed for users who want more control over how a TensorFlow model learns to recognize features during training. They are all optional.

  1. The Solid Distance field is only for point and polyline labels used in pixel segmentation. For each class, enter the number of pixels surrounding point or polyline labels that should be considered part of the target feature.
  2. Pad Small Features applies only to object detection rasters. Set to Yes to pad bounding boxes smaller than 40 pixels.
  3. 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.

  4. 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.

  5. Click OK in the Train TensorFlow Pixel Model dialog to start the training process.

Training a model takes a significant amount of time due to the computations involved. Depending on your system and graphics hardware, processing can take several minutes to several hours. While training is in progress, a dialog will show a progress bar, the current Epoch and Step of the progress, and the updated validation loss value. For example:

At the same time, a TensorBoard page displays in a new web browser. TensorBoard is a visualization toolkit included with TensorFlow. It reports real-time metrics such as Loss, Accuracy, Precision, and Recall during training. See View Training Metrics for details.

With each epoch, the weights of the model are adjusted to make it more correct. The weights from the epoch that produces the lowest validation loss will be used in the final, trained model. For example, if you want the model to complete 100 epochs and the lowest validation loss was achieved during Epoch #95, ENVI will retain and use the weights from that epoch in the trained model.

When training is complete, you can pass the trained model to the TensorFlow Grid Classification tool.

See Also


TensorFlow Grid Classification, TensorFlow Optimized Object Classification, TensorFlow Optimized Pixel Classification, Train Deep Learning Models Using the ENVI Modeler