Home

Awesome

Shoreline_Extraction_GAN

Author: Mark Lundine, PhD Candidate, University of Delaware, mlundine@udel.edu

Some Cool Examples

Delmarva, New Jersey Shore, Long Island, USA

Mid_Atlantic_Trends

Delmarva

delmarva_ex

Delaware oceanside trends. delaware_trends

Delaware estuary trends. delaware_estuary_trends

Broadkill Beach trends, big nourishment in 2015-2016, followed by erosion focused on the center of the nourishment zone. broadkill_trends

Jersey Shore

jersey_ex

Long Island

longisland_ex

Northern Tuscany, Italy:

tuscanytrends

LSTM Example Outputs from Cape Henlopen

cape_lstm_fig

Satellite Shoreline Trends

An interactive web map to visualize the linear trends is available here.

This includes data from the US Mid-Atlantic and Northern Tuscany.

Synopsis

Data-driven satellite shoreline analysis with GANs and LSTMs.

How can we use satellite imagery to quantify historical patterns in sandy beach dynamics?

How can we use data to predict future sandy beach dynamics?

Extraction Model Flow Diagram

Input: 256x256 RGB coastal satellite imagery is the input data.

  1. These images get segmented into land and water binary images by the GAN (which consists of a 256x256 U-Net for the generator and a Patch-GAN for the discriminator, pix2pix-style).

  2. Marching squares contouring algorithm is then used to delineate the land/water boundary. marching_squares

  3. The vector outputs from marching squares are then smoothed out using Chaikin's corner cutting algorithm (five refinements). chaikins

  4. Filters:

    • Recursive 3-sigma vertex filter: discard all shorelines that have mean vertices +/- 3*sigma vertices until no more shorelines can be discarded.
    • Reference shoreline filter (and buffer radius), all features that lie outside of the buffer radius of the reference shoreline are discarded.
    • Reference region filter, all shorelines that are not contained within the reference region are discarded.

Output: Timestamped vector shorelines

model_flow

Current Shoreline Extraction Training Data Domain

Training data outlined in black in each image. Annotation pairs consist of an RGB image and a segmented land/water binary image.

Currently, training data encompasses Delmarva, New Jersey Shore, and Long Island (all USA), as well as a section of coast in northern Tuscany, Italy.

I aimed to cover most of the mid-Atlantic and then added the Tuscany section during my time working at the University of Pisa in Pisa, Italy.

Viriginia Beach and the Outer Banks of North Carolina will be added to the model training data domain later this spring.

Great Lakes data will be added hopefully this summer.

If you have any training data I could use (and possibly in-situ comparison data), feel free to reach out (mlundine@udel.edu).

usa_domain

italy_domain

Augmentations can help increase the variability in the annotation dataset. Augmentations included vertical flip, horizontal flip, 90 degree CW rotation, 90 degree CCW rotation, and combined vertical and horizontal flip. These augmentations were chosen to show the model more spatial configurations of beaches.

augementations

Total set of labeled images was 128,012. Split was 80% training, 10% validation, and 10% testing.

GAN Training Details

GAN Dice Scores

Quantifying the segmentation accuracy over training epochs. Perfect segmentation would be a Dice Score of 1.0.

dice

Final model run on the test dataset.

dice_test

Test Dataset Examples

test_examples

Manually Delineated Vs. Shoreline Extraction Model

This is showing how the deviation in shoreline position between the extracted shorelines and manually delineated shorelines improves through model training on both the training and validation images.

training_val_geo

This is a box plot of the deviations for the testing images, with shorelines extracted with the final model (epoch 15).

testing_geo

Here is how the deviations compare from the four separate satellites in box plot form. Landsat 7 has greater variance mainly due to artifacts in Landsat 7 imagery due to the scan-line corrector failure in 2003.

sat_geo

Here is how the deviations differ over separate decades in box plot form. We can see greater variance in the 2000s likely again due to the Landsat 7 issues.

decade_geo

Here is how the deviations differ each year in box plot form.

year_geo

And last here are the median deviations each year as a timeseries.

year_geo

The deviations are fairly consistent across the available temporal range, meaning the model is providing consistent results no matter the year. Larger deviations, and hence poor automated delineation of shorelines, is likely occuring in cloudy and noisy images.

In-Situ Data Comparison at Duck, NC

Using the satellite-derived shoreline benchmark software, found here, shorelines extracted through the methods developed in this repo were compared with shorelines derived from in-situ survey methods. The training data for the GAN was mainly from US East Coast beaches, so the Duck dataset served as a solid comparison site. Shown below is a histogram (left) and box and whisker plot (right) of the deviation between the satellite shorelines and the in-situ shorelines at Duck, NC. The root mean squared error (RMSE) is probably the most appropriate metric, which ended up being 12.7 m. duck_accuracy

Setup

Tutorial Videos

You will need a Windows PC, an NVIDIA graphics card, and Anaconda to run this software.

Anaconda can be downloaded here.

Download the source code, latest_net_G.pth, and latest_net_D.pth from the latest Release.

Unzip the source code somewhere on your machine and remove the version tag from the outermost directory so that it reads "Shoreline_Extraction_GAN".

Make a new directory in .../Shoreline_Extraction_GAN/pix2pix_modules/ called "checkpoints".

Make a new directory in .../Shoreline_Extraction_GAN/pix2pix_modules/checkpoints called "shoreline_gan_nov".

Place latest_net_G.pth and latest_net_D.pth in .../Shoreline_Extraction_GAN/pix2pix_modules/checkpoints/shoreline_gan_nov.

envs/ holds three environment files that list all of the requirements.

pix2pix_shoreline is used for running the GANs, shoreline_prediction is for training/running LSTMS, while shoreline_gan is for everything else.

Use Anaconda to set these up.

conda env create --file envs/pix2pix_shoreline.yml
conda env create --file envs/shoreline_prediction.yml
conda env create --file envs/shoreline_gan.yml

Start Up

Tutorial Video

shoreline_gan_gui.py contains a gui for running this project.

After the three necessary Anaconda environments have been created, activate the shoreline_gan environment.

conda activate shoreline_gan

Next, run the GUI Python file. Make sure you are sitting in the .../Shoreline_Extraction_GAN/ directory.

python shoreline_gan_gui.py

The GUI should look like this, with eight separate buttons for various tasks related to shoreline extraction.

home_screen

Downloading satellite data

Tutorial Video

Click on 1. Download Imagery.

download_screen

Data is downloaded using CoastSat.

CoastSat allows users to download Landsat 5, 7, 8 and Sentinel-2 imagery from anywhere around the world.

CoastSat also includes a number of useful preprocessing tools.

To download satellite data, find an area where there are beaches and design a rectangular-shaped, north-up oriented, UTM aligned box.

If your area of interest is not rectangular and UTM-aligned, the Landsat images will have cropped out sections and lots of no-data areas.

The cloud-cover threshold is set to 0.30 in this code. You can change this in the file utils/download_utils, under the download_imagery function.

Pick a site name and enter this in the name text box.

Select a range of dates and enter these in the start and end date text boxes.

You will need the corner coordinates to download imagery:

Then select which satellites you would like to pull imagery from (L5, L7, L8, and/or S2).

Once everything is ready, hit Start Download. This will make a new folder data/sitename where images get saved. The metadata for all of the images are saved to a csv in this folder.

Optionally, you can choose a shapefile with already constructed study areas. This is useful if you wish to download imagery from many study areas.

Preprocessing for pix2pix

Tutorial Video

Before running pix2pix, the images need to be split and resized into 256 x 256.

Hit Preprocess Images. This will ask for a directory with the satellite jpegs. This should be under data/sitename/jpg_files/preprocessed.

It will save the pix2pix ready images (each image gets split into a 'one' and 'two' image) to data/sitename/jpg_files/pix2pix_ready.

Shoreline_Extraction

Tutorial Video

Hit Shoreline Extraction.

shorelineExtraction

filters

Make Transects

Tutorial Video

transects_ex

Hit Make Transects.

transect_diagram

transects

Make Timeseries

Tutorial Video

Hit Make Timeseries.

timeseries_diagram

timeseries

Making Linear Trend Shapefile

Tutorial Video

This tool allows for the construction of shapefiles that help with visualization of linear trends computed on each transect's cross-shore position timeseries. Each transect will be re-scaled and the direction changed to correspond with the value of the computed linear trend.

Fit a linear model to this data using ordinary least squares (OLS)

Making a map of shoreline change vectors

trends_visual

To use this tool, hit "Get Linear Trend Shapefile"

get_linear_trend

Project Timeseries

Tutorial Videos

Hit Project Timeseries

project_timeseries

Using LSTMs to project cross-shore positions into the future for an entire section of the coast.

predictioncape projectioncape

Merge Projections

Tutorial Video

With timeseries of projected cross-shore positions, as well as the transects at which the timeseries data was originally extracted from, we can re-cast these values into UTM coordinates with simple trigonmetry.

projection_geom

Hit Merge Projections

merge_projections

projected_cape

Retraining Model

It is very possible that the area you are testing the model contains completely novel data for the GAN. This might make the results quite bad. To get better results, you need to train the GAN on annotations from the new study area.

I will add more details on how to set up a training dataset in the future.

Click Retraining Model.

train

Once the training dataset is set up, type in the model name. It is probably best to use the default epochs and decay epochs. If you are continuing training from existing checkpoints, hit the continuing training check box, and specify the starting epoch. Then hit Run.