• Stars
    star
    167
  • Rank 226,635 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code for a winning model (3 out of 419) in a Dstl Satellite Imagery Feature Detection challenge

THIS REPO IS UNMAINTEINED AND MOSTLY REMAINS AS HISTORIC ARTIFACT.

Please, take a look at versions of software we used to generate our result -- it is ancient now. Do not expect this code to run on Keras above version 1.2.2 and so on. It will not run out of the box, we wouldn't answer any issues about it, sorry. If you manage to run this code on newer versions -- please, feel free to open pull request, we will merge it for the public good.

Take a look at https://github.com/ternaus/TernausNet if you need more up-to-date segmentation solution.

Winning Model Documentation

Name: Vladimir Iglovikov

LinkedIn: https://www.linkedin.com/in/iglovikov/

Location: San-Francisco, United States

Name: Sergey Mushinskiy

LinkedIn: https://www.linkedin.com/in/sergeymushinskiy/

Location: Angarsk, Russia

Competition: Dstl Satellite Imagery Feature Detection

Blog post: http://blog.kaggle.com/2017/05/09/dstl-satellite-imagery-competition-3rd-place-winners-interview-vladimir-sergey/

If you find this code useful for your publications, please consider citing

@article{DBLP:journals/corr/IglovikovMO17,
  author    = {Vladimir Iglovikov and
               Sergey Mushinskiy and
               Vladimir Osin},
  title     = {Satellite Imagery Feature Detection using Deep Convolutional Neural
               Network: A Kaggle Competition},  
  volume    = {abs/1706.06169},
  year      = {2017},  
  archivePrefix = {arXiv},
  eprint    = {1706.06169},     
}

Prerequisites

To train final models you will need the following:

  • OS: Ubuntu 16.04 (although code was successfully ran on Windows 10 too)
  • Required hardware:
    • Any decent modern computer with x86-64 CPU,
    • Fair amount of RAM (we had about 32Gb and 128Gb in our boxes, however, not all memory was used)
    • Powerful GPU: we used Nvidia Titan X (Pascal) with 12Gb of RAM and Nvidia GeForce GTX 1080 with 8Gb of RAM.

Main software for training neural networks:

  • Python 2.7 (preferable and fully tested) or Python 3.5
  • Keras 1.2.2
  • Theano 0.9.0rc1

Utility packages for geometry and image manipulation and other helper functions:

  • h5py
  • matplotlib
  • numba
  • numpy
  • pandas
  • rasterio
  • Shapely
  • scikit_image
  • tifffile
  • OpenCV
  • tqdm
  1. Install required OS and Python
  2. Install packages with pip install -r requirements.txt
  3. Create following directory structure:
  • Data structure:
data / theree_band / *
     / sixteen_band / *
    grid_sizes.csv
    train_wkt_v4.csv
  • Source code
src / *.py

Prepare data for training:

  1. Run python get_3_band_shapes.py
  2. Run cache_train.py

Train models

Each class in our solution has separate neural network, so it requires running of several distinct models one by one (or in parallel if there are enough computing resources)

  1. Run python unet_buidings.py
  2. Run python unet_structures.py
  3. Run python unet_road.py
  4. Run python unet_track.py
  5. Run python unet_trees.py
  6. Run python unet_crops.py

For water predictions we used different method and it can be created by running:

  1. Run python fast_water.py
  2. Run python slow_water.py

After training finishes (it may require quite a long time depending on hardware used, in our case it was about 7 hours for each stage (50 epochs)) trained weights and model architectures are saved in cache directory and can be used by prediction scripts (see the next section).

Create predictions

To create predictions run every make_prediction_cropped_*.py file in src dir. It could take considerable amount of time to generate all predictions as there are a lot of data in test and we use separate models for each class and use test time augmentation and cropping for the best model performance. On Titan X GPU each class took about 5 hours to get predictions.

  1. Run python make_prediction_cropped_buildings.py
  2. Run python make_prediction_cropped_structures.py
  3. Run python make_prediction_cropped_track.py
  4. Run python make_prediction_cropped_road.py
  5. Run python make_prediction_cropped_trees.py
  6. Run python make_prediction_cropped_crops.py

When all predictions are done they should be merged in a single file for submit:

  • Run python merge_predictions.py
  1. Run python merge_predictions.py The previous step will create file joined.csv that just merges predictions per class into the unified format.
  • Last step in the pipeline is to
  1. Run python post_processing.py joined.csv

that will perform some cleaning of the overlapping classes (remove predictions of the slow water from fast water, all other predictions from buildings, etc)

  • Done!

Remarks

Please, keep in mind that this isn't a production ready code but a very specific solution for the particular competition created in short time frame and with a lot of other constrains (limited training data, scarce computing resources and a small number of attents to check for improvements).

So, there are a lot of hardcoded magic numbers and strings and there may be some inconsistensies and differences between different models. Sometimes, it was indentended to get more accurate predictions and there wasn't enough resources to check if changes improve score for other classes after they were introduced for some of them. Sometimes, it just slipped from our attention.

Also, inherent stochasticity of neural networks training on many different levels (random initialization of weights, random cropping of patches into minibatch and so on) makes it impossible to reproduce exact submission from scratch. We went extra mile and reimplemented solution and training procedure from scratch as much as possible in the last two weeks after competition final. We've got up to 20% extra performance for some classes with abundant training data like buildings, tracks and so on. However, some classes proven more difficult to reliably reproduce because of lack of training data and small amount of time. Such classes show high variance of results between epochs. For competition we used our best performing combinations of epoch/model for those classes, which may not be exactly the same as trained for fixed number of epochs (as in this particular code). However, we believe that our model is equally capable to segment any classes, given enough data and/or clear definitions what exactly consists of each class (it wasn't clear how segmentation was performed in the first place for some classes, like road/tracks).

More Repositories

1

TernausNet

UNet model with VGG11 encoder pre-trained on Kaggle Carvana dataset
Python
1,044
star
2

robot-surgery-segmentation

Wining solution and its improvement for MICCAI 2017 Robotic Instrument Segmentation Sub-Challenge
Jupyter Notebook
620
star
3

TernausNetV2

TernausNetV2: Fully Convolutional Network for Instance Segmentation
Jupyter Notebook
548
star
4

retinaface

The remake of the https://github.com/biubug6/Pytorch_Retinaface
Python
345
star
5

cloths_segmentation

Code for binary segmentation of cloths
Python
166
star
6

people_segmentation

Code for the model to segment people at the image
Python
97
star
7

angiodysplasia-segmentation

Wining solution and its further development for MICCAI 2017 Endoscopic Vision Challenge Angiodysplasia Detection and Localization
Jupyter Notebook
78
star
8

midv-500-models

Model for document segmentation trained on the midv-500-models dataset.
Python
57
star
9

check_orientation

Model to check if image was rotated by 90, 180, 270 degrees.
Python
56
star
10

iglovikov_helper_functions

An unstructured set of helper functions
Python
55
star
11

datasouls_antispoof

Code and pre-trained models for detecting spoofing attacks from images.
Python
31
star
12

facemask_detection

Detection masks on faces.
Python
29
star
13

kaggle_allstate

Repository with files somehow relevant to the Kaggle competition https://www.kaggle.com/c/allstate-claims-severity
Python
28
star
14

imread_benchmark

I/O benchmark for different image processing python libraries.
Python
23
star
15

iglovikov_segmentation

Semantic segmentation pipeline using Catalyst.
Python
20
star
16

base64ToImageConverters

Library for converting from RGB / GrayScale image to base64 and back.
Python
16
star
17

retinafacemask

Detector for faces with masks / no masks on top of them.
Python
16
star
18

retinaface_demo

Code for webapp for https://github.com/ternaus/retinaface
Python
14
star
19

kaggle_planet

Planet: Understanding the Amazon from Space
Jupyter Notebook
12
star
20

react_face_detection

Detect faces in react App.
TypeScript
11
star
21

kaggle_cdiscount

Python
11
star
22

yolov5faceInference

YoloV5FaceWrapper
Python
11
star
23

High-Resolution-Image-Inpainting-GAN

Python
9
star
24

kaggle_alaska_2

https://www.kaggle.com/c/alaska2-image-steganalysis
Python
8
star
25

spb_bridges

Jupyter Notebook
8
star
26

insightfaceWrapper

Wrapper for easier inference for insightface
Python
8
star
27

frog-rcnn

Mask RCNN by Heng CherKeng
Python
7
star
28

giana

WORK IN PROGRESS. Code for GIANA challenge
Python
7
star
29

lsun_2017

Large-Scale Scene Understanding Challenge at CVPR 2017
Python
7
star
30

people_segmentation_demo

Python
4
star
31

kaggle_otto

Otto Group Product Classification Challenge
Python
4
star
32

kaggle_camera

https://www.kaggle.com/c/sp-society-camera-model-identification
Jupyter Notebook
3
star
33

nexar

https://www.getnexar.com/challenge-2
Python
3
star
34

kaggle_liberty

https://www.kaggle.com/c/liberty-mutual-group-property-inspection-prediction/data
Python
3
star
35

onnx_model_optimizations

Python
2
star
36

clip2onnx

Converts CLIP models to ONNX
Python
2
star
37

kaggle_ICDM

https://www.kaggle.com/c/icdm-2015-drawbridge-cross-device-connections
Python
2
star
38

add_logo

Adds pre-defined logo to the image
Python
2
star
39

nuscenes-devkit

Jupyter Notebook
2
star
40

imagenet18

Python
2
star
41

cloths_segmentation_demo

Web App for binary cloths segmentation
Python
2
star
42

nexar2_ssd

Python
2
star
43

ternaus_chrome_extension

Chrome extension for Image and Reverse Image Search on Ternaus
JavaScript
2
star
44

quest-qmc

Automatically exported from code.google.com/p/quest-qmc
Fortran
2
star
45

ternaus-cleantext

Cleans text as in the CLIP model
Python
2
star
46

ternaus.github.io

HTML
2
star
47

quest-qmc-analyzer

Python
1
star
48

mask_generator

Random Mask generator
1
star
49

grade-system

1
star
50

kaggle_statefarm

Python
1
star
51

imagenet_2017

raw code for ImageNet 2017
1
star
52

FaceSwap

Based oon https://github.com/MarekKowalski/FaceSwap
Python
1
star
53

kaggle_mnist

Python
1
star
54

satelite_paper

TeX
1
star
55

kaggle_eeg

Python
1
star
56

kaggle_seals

Jupyter Notebook
1
star
57

boost_imagenet

Example on how to fine tune models to boost the performance of models on ImageNet
Python
1
star
58

kaggle_santander2

Supplementary code for competition https://www.kaggle.com/c/santander-product-recommendation
Python
1
star
59

submission_merger

tool to merge submissions generated by different models for kaggle competitions.
Python
1
star
60

kaggle_bag

Python
1
star