Here, we use pre-trained and new models to identify active wave breaking
at the pixel level by using semantic segmentation neural nets. Two models are currently implemented, Xception and MobileNetV2. Xception is trained end-to-end and MobileNetV2 is initialized from the weights of the image classification task.
Both models use a modified U-Net architecture. Data augmentation is used at training time.
| Dataset | Link | Alternative link |
|---|---|---|
| Segmentation V1 | - |
The segmentation dataset was manually put together by me and Pedro Guimarães. Data is organized as follows:
└───train /or/ test /or/ valid
├───images
├───data
├───img1.png
├───img2.png
...
├───masks
├───data
├───img1.png
├───img2.png
...
python train.py --backbone "xception" -i "path/to/data" --model "myxception" --logdir "myxception" --batch-size 32 --epochs 128python train.py --backbone "mobilenet" --pre-trained "mobilenet.h5" -i "path/to/data" --model "mymobilenet" --logdir "mymobilenet" --batch-size 32 --epochs 128Arguments:
-
-iInput data path. -
--modelModel name. -
--backboneWhich backbone to use. Only mobilenet or xception for now. -
--random-stateRandom seed for reproducibility. Default is 11. -
--epochsNumber of epochs (iterations) to train the model. Default is 200. -
--batch-sizeNumber of images to process in each step. Decrease if running into memory issues. Default is 64. -
--input-sizeImage input size. Decrease if running into memory issues. Default is 256x256px. -
--pre-trainedPath to a pre-trained model.
| Model | Link | Alternative link |
|---|---|---|
| Xception | - | |
| MobileNetV2 | - |
To segment new images, use predict.py. Note that the data will be processed in 256x256 blocks.
python predict.py --model "pre_trained/seg_xception.h5" --frames "path/to/images" -o "segmentation.csv" --region-of-interest 256 256 1024 512Arguments:
-
--framesInput data path. -
--modelPre-trained model path. -
--region-of-interestRegion of the image to look at. Use Matplotlib convention. -
--regexRegular expression used to look for frames. -
--from-frameFirst frame. -
--frames-to-processNumber of frames to process. -
--outputOutput csv file. -
save-plotsWill save output plots. -
plot-pathWhere to save the plots.
It is also possible to obtain bounding boxes from the results of segmentation. This data can be used to track the waves using SORT.
This is a slower approach but more precise.
python extract_detections_by_clustering.py --frames "path/to/frames" --pixels "segmentation.csv" -o "detections.csv" --plot --plot-path "plt" -eps 20 -nmin 10Arguments:
-
--min-samplesminimum number of samples for DBSCAN. -
--epsMaximum distance parameter for DBSCAN. -
--framesInput data path. -
--pixelsSegmented pixels, usepredict.pyto get a valid file. -
--regexRegular expression used to look for frames. -
--from-frameFirst frame. -
--frames-to-processNumber of frames to process. -
--outputOutput csv file. -
save-plotsWill save output plots. -
plot-pathWhere to save the plots.
This is faster but a lot less precise.
python extract_detections_by_labelling.py --frames "path/to/frames" --pixels "segmentation.csv" -o "detections.csv" --plot --plot-path "plt" -min-area 20Arguments:
-
--min-areaminimum number area to consider as a region. -
--framesInput data path. -
--pixelsSegmented pixels, usepredict.pyto get a valid file. -
--regexRegular expression used to look for frames. -
--from-frameFirst frame. -
--frames-to-processNumber of frames to process. -
--outputOutput csv file. -
save-plotsWill save output plots. -
plot-pathWhere to save the plots.