ArcGIS Developer

ArcGIS API for Python

Detecting Mussel Farms using Deep Learning

  • 🔬 Data Science
  • 🥠 Deep Learning and Object Detection


Mussels are aquatic animals with bivalved hard shells that are consumed by millions of people around the world. Mussels grow in fresh water rivers or lakes near their openings to saline waters of the ocean, as well as in some coastal intertidal regions. Mussel aquaculture involves floating rafts that have ropes suspended in the water on which the mussels are cultured. The farmers collect mussel seeds from nearby rocky shores during low tides and attach them to the ropes in their rafts. Later, these ropes are covered with mesh socks that collect the mussels once they are ripe.

Mussels growing on a rocky shore

Spain is one of the biggest producer of mussels in the world. The Galicia region in Spain accounts for almost 90 percent of the mussel aquaculture in the country. Our study area for this notebook is Ria de Arousa, which is the biggest mussel farming area in Galicia region.

Mussel Farms in Ria de Arousa, Spain

Monitoring of such aquacultures is an important aspect of maintaining the aquatic ecosystems. While sustainable farming can help the ecosystem, it's exploitation can degrade the environment quality and biodiversity. Therefore, it is important to monitor the growth of mussel farms in a region and their expansion into fragile areas. While physical surveys can be arduous and time consuming, satellite imagery and deep learning can help in monitoring mussel farming with much less effort. These analysis can also be helpful in comparing changes over longer periods of time.

In this notebook, we will train a deep learning model to detect mussel farms in high-resolution imagery of the Ria De Arousa region of Spain.

Export training data

In [10]:
# Connect to GIS
from arcgis.gis import GIS
gis = GIS("home")

The following imagery layer contains high resolution imagery of a part of the Ria De Arousa region. The spatial resolution of the imagery is 30 cm, and it contains 3 bands: Red, Green, and Blue. It is used as the 'Input Raster' for exporting the training data.

In [2]:
training_raster = gis.content.get('f2b92eed10394e5eb3c7f135861937d9')
Training Imagery for Mussel Farm DetectionImagery Layer by demos_deldev
Last Modified: December 13, 2021
0 comments, 0 views

The following feature layer contains the bounding boxes for a few mussel farms in the Ria de Arousa region. It is used as the 'Input Feature Class' for exporting the training data.

In [3]:
training_feature_layer = gis.content.get('ff6a48b3391c4a24b807af0eb08bb6c1')
Feature layer with bounding boxes around mussel farms.Feature Layer Collection by api_data_owner
Last Modified: December 16, 2021
0 comments, 1 views

Training data can be exported by using the 'Export Training Data For Deep Learning' tool available in ArcGIS Pro and ArcGIS Enterprise. For this example, we prepared the training data in the 'PASCAL Visual Object Classes' format, using a 'chip_size' of 448px and a 'cell_size' of 0.3m, in ArcGIS Pro. The 'Input Raster' and the 'Input Feature Class' have been made available to export the required training data. We have also provided the exported training data in the next section, if you wish to skip this step.

Export Training Data for Deep Learning

Train the model

Necessary imports

In [1]:
import os
import glob
import zipfile
from pathlib import Path
from arcgis.learn import prepare_data, MMDetection

Get training data

We have already exported the data that can be directly used by following the steps below:

In [7]:
training_data = gis.content.get('57cb821dedca4c5598e81c8d2d510c91')
Training data for Mussel Farm Detection sample notebookImage Collection by api_data_owner
Last Modified: December 10, 2021
0 comments, 0 views
In [5]:
filepath =
In [6]:
import zipfile
with zipfile.ZipFile(filepath, 'r') as zip_ref:
In [7]:
data_path = Path(os.path.join(os.path.splitext(filepath)[0]))

Prepare data

We will specify the path to our training data and a few hyperparameters.

  • path: path of the folder/list of folders containing training data.
  • batch_size: Number of images your model will train on each step inside an epoch. Depends on the memory of your graphic card.
  • chip_size: The same as the tile size used while exporting the dataset.
In [4]:
data = prepare_data(path, batch_size=4, chip_size=448)

Visualize training data

To get a sense of what the training data looks like, the show_batch() method will randomly pick a few training chips and visualize them.

In [7]: