/airbus_rle_to_coco

Kaggle airbus

Primary LanguageJupyter NotebookApache License 2.0Apache-2.0

Make COCO Dateset

This code is for Kaggle competiton Airbus Ship Detection Challenge, which can help you transform RLE into COCO annotations.

dataset annotation

It has 3 main functions:

  1. Delete useless images without ships;
  2. Find bad annotations and save them in the folder (../tmp/bad_anns);
  3. Transform RLE into COCO annotations;
        {
            "id": 27614,
            "image_id": 14332,
            "category_id": 1,
            "iscrowd": 0,
            "area": 3307,
            "bbox": [
                168.0,
                65.0,
                170.0,
                24.0
            ],
            "segmentation": [
                [
                    189.0,
                    88.5,
                    168.0,
                    88.5,
                    167.5,
                    70.0,
                    336.5,
                    65.0,
                    337.0,
                    84.5,
                    189.0,
                    88.5
                ]
            ],
            "width": 768,
            "height": 768
        },

File structure

airbus_dataset
├─input                                     # dataset and annotations
│  ├─annotations            		
│  │  └─ instances_ships_train2018.json     # .json, which will be generated by us
│  │
│  ├─ships_train2018                        # ship pictures
│  │  ├─ 000d42241.jpg
│  │  ├─ 000e6378b.jpg
│  │  └─ xxx.jpg
│  │
│  └─train_ship_segmentations_v2.csv        # annotations in RLE style
│
├─airbus_rle_to_coco                        # here we are
│  ├─ 0_airbus_delete_empty_im.py           # delete images without ships
│  ├─ 0_csv_show_RLE.py                     # show annotations in RLE style
│  ├─ 1_ships_to_coco.py                    # turn RLE into COCO
│  └─ 2_pycoco_API_Demo.ipynb               # show annotations in COCO style 
│
└─tmp                                       # bad annotations

Installation

1、install pycocotool

git clone https://github.com/waleedka/coco
cd coco/PythonAPI
make
python setup.py install

2、install pycococreator

pip install git+git://github.com/waspinator/pycococreator.git@0.2.0

3、install pandas and something others

pip install pandas

Step

  1. run 0_airbus_delete_empty_im.py, which can delete empty images without ships

  2. run 0_csv_show_RLE.py, which can show dataset in RLE style

  3. run 1_ships_to_coco.py, which generates .json file. Here is a finished one:

    instances_ships_train2018.json

  4. run 2_pycoco_API_Demo.ipynb, which can show dataset in COCO style

Train with Detectron

result1

result1