Skip To Content

Classify Pixels Using Deep Learning

Available with Image Analyst license.

Summary

Runs a trained deep learning model on an input raster to produce a classified raster, with each valid pixel having a class label assigned.

The trained deep learning model package consists of an Esri model definition (.emd) JSON file. It contains the path to the Python raster function to be called to process each raster tile, and the path to the trained binary deep learning model file created from third-party training software such as TensorFlow or CNTK.

Usage

  • You need to install the proper deep learning framework Python API (TensorFlow or CNTK) into the ArcGIS Pro Python environment; otherwise, an error will occur when you add the Esri model definition file to the tool. The appropriate framework information should be provided by the person who created the Esri model definition file.

  • For information about modifying or cloning the Python environment, see Python Package Manager.

  • This tool calls a third-party deep learning Python API (such as TensorFlow or CNTK) and uses the specified Python raster function to process each raster tile.

  • You can also write your own custom Python modules by following examples and instructions on the Esri Python raster function GitHub pageAnatomy of a Python raster function.

  • The Model Definition parameter can be an Esri model definition (.emd) JSON file or a JSON string. A JSON string is useful when this tool is used on the server, because you can paste the JSON string rather than upload the .emd file.

  • For more information about deep learning, see Deep Learning in ArcGIS Pro.

  • The following code sample uses the Esri model definition (.emd) file:

    {
        "Framework":"TensorFlow",
        "ModelConfiguration":"deeplab",
        "InferenceFunction":"C:\\DeepLearning\\ImageClassifier.py",
        "ModelFile":"\\Data\\ImgClassification\\TF\\froz_inf_graph.pb",
         "ModelType":"ImageClassification",
        "ExtractBands":[0,1,2],
        "ImageHeight":513,
        "ImageWidth":513,
    
        "Classes" : [
            {
                "Value":0,
                "Name":"Evergreen Forest",
                "Color":[0, 51, 0]
             },
             {
                "Value":1,
                "Name":"Grassland/Herbaceous",
                "Color":[241, 185, 137]
             },
             {
                "Value":2,
                "Name":"Bare Land",
                "Color":[236, 236, 0]
             },
             {
                "Value":3,
                "Name":"Open Water",
                "Color":[0, 0, 117]
             },
             {
                "Value":4,
                "Name":"Scrub/Shrub",
                "Color":[102, 102, 0]
             },
             {
                "Value":5,
                "Name":"Impervious Surface",
                "Color":[236, 236, 236]
             }
        ]
    }

Syntax

ClassifyPixelsUsingDeepLearning (in_raster, in_model_definition, {arguments})
ParameterExplanationData Type
in_raster

The input image to classify.

Raster Dataset; Raster Layer; Mosaic Layer; Image Service; MapServer; Map Server Layer; Internet Tiled Layer
in_model_definition

The in_model_definition parameter can be an Esri model definition (.emd) JSON file or a JSON string. A JSON string is useful when this tool is used on the server, because you can paste the JSON string rather than upload the .emd file.

Contains the path to the deep learning binary model file, the path to the Python raster function to be used, and other parameters such as preferred tile size or padding.

File; String
arguments
[arguments,...]
(Optional)

The function arguments are defined in the Python raster function class. This is where you list additional deep learning parameters and arguments for experiments and refinement, such as a confidence threshold for adjusting the sensitivity. The names of the arguments are populated by the tool from reading the Python module.

Value Table

Return Value

NameExplanationData Type
out_classified_raster

The classified image.

Each valid pixel has a class value. The raster has an attribute table with class names, values, and colors.

Raster

Code sample

ClassifyPixelsUsingDeepLearning example 1 (Python window)

This example classifies a raster based on a custom pixel classification using the ClassifyPixelsUsingDeepLearning tool.

# Import system modules
import arcpy
from arcpy.ia import *

# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")

ClassifyPixelsUsingDeepLearning("c:/classifydata/moncton_seg.tif",
     "c:/classifydata/moncton.tif", "c:/classifydata/moncton_sig.emd")
ClassifyPixelsUsingDeepLearning example 2 (stand-alone script)

This example classifies a raster based on a custom pixel classification using the ClassifyPixelsUsingDeepLearning tool.

# Import system modules
import arcpy
from arcpy.ia import *

"""
Usage: ClassifyPixelsUsingDeepLearning(in_raster,out_classified_raster, 
       in_classifier_definition, {arguments})
                      
"""

# Set local variables
in_raster = "c:/classifydata/moncton_seg.tif"
out_classified_raster = "c:/classifydata/moncton.tif"
in_model_definition = "c:/classifydata/moncton_sig.emd"


# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")

# Execute 
ClassifyPixelsUsingDeepLearning("c:/classifydata/moncton_seg.tif",
     "c:/classifydata/moncton.tif", "c:/classifydata/moncton_sig.emd", 
     "padding 2")

Licensing information

  • Basic: Requires Image Analyst
  • Standard: Requires Image Analyst
  • Advanced: Requires Image Analyst

Related topics