This code is for Kaggle competiton Airbus Ship Detection Challenge, which can help you transform RLE into COCO annotations.
It has 3 main functions:
- Delete useless images without ships;
- Find bad annotations and save them in the folder (../tmp/bad_anns);
- 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
},
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
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
-
run 0_airbus_delete_empty_im.py, which can delete empty images without ships
-
run 0_csv_show_RLE.py, which can show dataset in RLE style
-
run 1_ships_to_coco.py, which generates .json file. Here is a finished one:
-
run 2_pycoco_API_Demo.ipynb, which can show dataset in COCO style