This task generates object detection rasters using a JSON dataset containing COCO (Common Objects in Context)-formatted annotations. Each raster corresponds to labeled regions of interest defined in the COCO input annotations.

Example


; Start the application
e = ENVI()
 
; Root directory containing a downloaded COCO dataset.
;   Update RootCoco with the path containing directories:
;   - train
;   - valid
;   - test
RootCoco = 'C:\coco_data'
 
; Root directory to output ENVI COCO generated training rasters.
;  Update RootDl with a valid output directory containing folders:
;   - train
;   - valid
RootDl = 'C:\envi_dl_coco'
 
; Define task inputs
;   CocoTrainFile:
;     Annotation file with extension *.json located in a COCO train directory.
;   CocoValidFile:
;     Annotation file with extension *.json located in a COCO valid directory.
CocoTrainFile = RootCoco + Path_Sep() + 'train' + Path_Sep() + '_annotations.coco.json'
CocoValidFile = RootCoco + Path_Sep() + 'valid' + Path_Sep() + '_annotations.coco.json'
 
; Define task outputs
;   OutputTrainDir:
;     User defined output directory to store ENVI generated training rasters.
;   OutputValidDir:
;     User defined output directory to store ENVI generated validation rasters.
OutputTrainDir = RootDl + Path_Sep() + 'train'
OutputValidDir = RootDl + Path_Sep() + 'valid'
 
; Generate training rasters from COCO
 
; Get the task from the catalog
Task1 = ENVITask('BuildObjectDetectionRastersFromCOCO')
 
; Define inputs
Task1.INPUT_COCO_JSON = CocoTrainFile
Task1.NUMBER_OF_RASTERS = 20
Task1.RANDOM_SELECTION = 1
Task1.RANDOM_SEED = 12345
Task1.ENHANCE_DISPLAY = 1
Task1.OUTPUT_RASTER_DIRECTORY = OutputTrainDir
 
; Run the task
Task1.Execute
 
; Generate validation rasters from COCO
 
; Get the task from the catalog
Task2 = ENVITask('BuildObjectDetectionRastersFromCOCO')
; Define inputs
Task2.INPUT_COCO_JSON = CocoValidFile
Task2.NUMBER_OF_RASTERS = 4
Task2.RANDOM_SELECTION = 1
Task2.RANDOM_SEED = 12345
Task2.ENHANCE_DISPLAY = 1
Task2.OUTPUT_RASTER_DIRECTORY = OutputValidDir
; Run the task
Task2.Execute
 
; Prepare training inputs and outputs
 
; Set the output model path
OutputModelUri = RootDl + Path_Sep() + 'model.envi.onnx'
 
; Prepare training rasters
TrainingFiles = File_Search(OutputTrainDir, '*.dat', count = nTraining)
if (nTraining eq 0) then message, 'No training rasters found in training folder'
TrainingRasters = objarr(nTraining)
foreach file, TrainingFiles, idx do TrainingRasters[idx] = ENVIDeepLearningObjectDetectionRaster(file)
 
; Prepare validation rasters
ValidationFiles = File_Search(OutputValidDir, '*.dat', count = nValidation)
if (nValidation eq 0) then message, 'No validation rasters found in training folder'
ValidationRasters = objarr(nValidation)
foreach file, ValidationFiles, idx do ValidationRasters[idx] = ENVIDeepLearningObjectDetectionRaster(file)
 
; Train a model using ENVI COCO generated rasters
 
; Get the task from the catalog
Task3 = ENVITask('TrainDeepLearningObjectModel')
 
; Define inputs
Task3.Model_Name = 'COCO Example'
Task3.Training_Rasters = TrainingRasters
Task3.Validation_Rasters = ValidationRasters
Task3.Epochs = 25
Task3.Patches_Per_Batch = 2
Task3.Output_Model_URI = OutputModelUri
 
; Run the task
Task3.Execute
 
; Get the output model from the task
Model = Task3.Output_Model
 
print, Model.Metrics, /IMPLIED_PRINT

Syntax


Result = ENVITask('BuildObjectDetectionRastersFromCOCO')

Input parameters (Set, Get): ENHANCE_DISPLAY, INPUT_COCO_JSON, NUMBER_OF_RASTERS, RANDOM_SEED, RANDOM_SELECTION, OUTPUT_RASTER_DIRECTORY, VISUAL_RGB

Output parameters (Get only): None

Properties marked as "Set" are those that you can set to specific values. You can also retrieve their current values any time. Properties marked as "Get" are those whose values you can retrieve but not set.

Input Parameters


ENHANCE_DISPLAY (optional)

Specify whether to apply an additional small stretch to the processed data to suppress noise and enhance feature visibility. The optional stretch is effective for improving visual clarity in imagery acquired from aerial platforms or sensors with higher noise profiles.

INPUT_COCO_JSON (required)

Specify the COCO-format annotation JSON file that defines the input raster images and their associated labeled regions of interest. Each entry in the file should follow the COCO specification, including image metadata and bounding box annotations for object detection.

NUMBER_OF_RASTERS (required)

Specify how many object detection rasters to generate from the COCO-annotated dataset. Previously generated rasters are skipped, allowing incremental creation of the full dataset over time.

RANDOM_SEED (optional)

Specify a seed value to ensure reproducible results. When RANDOM_SELECTION is enabled, using the same seed will consistently generate the same subset of rasters from the dataset.

RANDOM_SELECTION (optional)

Enable this parameter for random selection of rasters from the COCO dataset. If the NUMBER_OF_RASTERS equals the total number of available rasters, this parameters will be ignored.

OUTPUT_RASTER_DIRECTORY (required)

Specify the directory where generated object detection rasters from the COCO-annotated dataset will be saved.

VISUAL_RGB (optional)

Specify whether to encode the output raster as a three-band RGB composite (red, green, blue) for color image processing. This ensures consistent band selection from ENVI display types (such as RGB, CIR, and pan) and supports integration of diverse data sources (such as MSI, panchromatic, and VNIR) without band mismatch.

Methods


Execute

Parameter

ParameterNames

See ENVI Help for details on these ENVITask methods.

Properties


DESCRIPTION

DISPLAY_NAME

NAME

REVISION

TAGS

See the ENVITask topic in ENVI Help for details.

Version History


Deep Learning 4.0

Introduced

See Also


BuildObjectDetectionRasterFromAnnotation Task, BuildObjectDetectionRasterFromROI Task, BuildObjectDetectionRasterFromVector Task, ENVIDeepLearningObjectDetectionRaster, TrainDeepLearningObjectDetectionModel Task