Deep learning can be used to automate the task of manually extracting features from imagery. With ArcGIS pretrained models, you can mitigate the need for large datasets, significant compute power, and knowledge or expertise in deep learning. These models have been trained on diverse geographical data and perform well across various regions. ArcGIS pretrained models are available to anyone with an ArcGIS account through ArcGIS Living Atlas of the World. In the following workflow, the Car Detection-USA model is used to identify cars in high-resolution drone and aerial imagery.
Requirements
The following requirements are necessary to perform this workflow:
- Aerial imagery to run the model on.
Note:
You can download aerial imagery containing cars from OpenAerialMap.
- Deep learning is computationally intensive, and it is recommended that you use a powerful GPU to process large datasets.
Inferencing with pretrained models
The following sections describe the processes involved in inferencing with an ArcGIS pretrained model.
Python library imports
Import the following Python libraries:from arcgis.gis import GIS
from arcgis.learn import detect_objects
from arcgis.raster.analytics import copy_raster
gis = GIS("home")
Add the data and model for analysis
There are two methods you can use to add your dataset to your notebook.
The first method involves uploading the aerial imagery into your notebook workspace, adding it into the code cell, and running the copy_raster() function to extract the data. dataset = "/arcgis/home/Aerial imagery.tif"
imagery = copy_raster(input_raster=dataset, output_name="Aerial_imagery", raster_type_name="Raster Dataset")
The second method involves adding the aerial imagery as a hosted imagery layer to your portal and adding the imagery layer to your notebook using its itemID.imagery = gis.content.get("<imagery-layer-item-id>")
Add the deep learning package
You can download the pretrained Car Detection - USA model from ArcGIS Living Atlas. Once you have downloaded the model, add it as an item to your portal and access it in your notebook using its itemID. model = gis.content.get("<deep-learning-package-item-id>")
Run the model
To run the pretrained model in your notebook, use the detect_objects module from arcgis.learn. The module will take your imagery as an input and detect and count the number of cars present in it.
Note:
You can potentially increase the model's performance by augmenting the model's arguments with varying values until your desired output is achieved:
model_arguments = {
"padding": "100", # The number of pixels at the border of image tiles from which predictions are blended for adjacent tiles. To smooth the output while reducing artifacts, increase the value
"batch_size": "16", # Change batch size as per GPU specifications
"threshold": "0.5", # Get detections greater than 50% confidence
"tile_size": "224", # The width and height of image tiles into which the imagery is split for prediction
}
Note:
If a GPU is configured, you can set a context inside the detect_object() method to set it to the GPU environment:context = { "processorType": "GPU" }
num_cars = {}
detected_cars = detect_objects(
input_raster=imagery,
model = model,
output_name = "detected_cars",
)
num_cars[imagery.name] = len(detected_cars.query(as_df=True))
Model results
Finally, once you have run your model, you can display the output of num_cars:print(f"Number of cars is {num_cars}.")