{"id":13490155,"url":"https://github.com/amirassov/kaggle-imaterialist","last_synced_at":"2025-03-28T05:32:07.785Z","repository":{"id":69798004,"uuid":"191402162","full_name":"amirassov/kaggle-imaterialist","owner":"amirassov","description":"The First Place Solution of Kaggle iMaterialist (Fashion) 2019 at FGVC6","archived":false,"fork":false,"pushed_at":"2020-01-12T17:57:34.000Z","size":10493,"stargazers_count":484,"open_issues_count":3,"forks_count":118,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-10-31T03:35:31.692Z","etag":null,"topics":["computer-vision","deep-learning","hybrid-task-cascade","imaterialist","instance-segmentation","kaggle","kaggle-imaterialist","mmdetection","object-detection","pytorch"],"latest_commit_sha":null,"homepage":"https://www.kaggle.com/c/imaterialist-fashion-2019-FGVC6","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amirassov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-06-11T15:39:49.000Z","updated_at":"2024-08-27T09:35:41.000Z","dependencies_parsed_at":"2023-07-10T07:00:52.440Z","dependency_job_id":null,"html_url":"https://github.com/amirassov/kaggle-imaterialist","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirassov%2Fkaggle-imaterialist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirassov%2Fkaggle-imaterialist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirassov%2Fkaggle-imaterialist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirassov%2Fkaggle-imaterialist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amirassov","download_url":"https://codeload.github.com/amirassov/kaggle-imaterialist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245978200,"owners_count":20703675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","deep-learning","hybrid-task-cascade","imaterialist","instance-segmentation","kaggle","kaggle-imaterialist","mmdetection","object-detection","pytorch"],"created_at":"2024-07-31T19:00:41.770Z","updated_at":"2025-03-28T05:32:06.975Z","avatar_url":"https://github.com/amirassov.png","language":"Python","funding_links":[],"categories":["Image Segmentation","Python"],"sub_categories":["[[2019] iMaterialist (Fashion) 2019 at FGVC6](https://www.kaggle.com/c/imaterialist-fashion-2019-FGVC6/)"],"readme":"# The First Place Solution of [iMaterialist (Fashion) 2019](https://www.kaggle.com/c/imaterialist-fashion-2019-FGVC6/)\n\n![ensemble](figures/prediction.png)\n\n## Solution\nMy solution is based on the COCO challenge 2018 winners article: https://arxiv.org/abs/1901.07518. \n\n### Model: \n[Hybrid Task Cascade with ResNeXt-101-64x4d-FPN backbone](https://github.com/open-mmlab/mmdetection/blob/master/configs/htc/htc_dconv_c3-c5_mstrain_400_1400_x101_64x4d_fpn_20e.py). This model has a metric Mask mAP = 43.9 on COCO dataset. This is SOTA for instance segmentation.\n\n### Validation:\nFor validation, I used 450 training samples splitted using https://github.com/trent-b/iterative-stratification.\n\n### Preprocessing:\nI applied light augmentatios from the [albumentations](https://github.com/albu/albumentations) library to the original image. Then I use multi-scale training: in each iteration, the scale of short edge is randomly sampled\nfrom [600, 1200], and the scale of long edge is fixed as 1900.\n\n![preprocessing](figures/preproc.png)\n\n### Training details:\n* pre-train from COCO\n* optimizer: `SGD(lr=0.03, momentum=0.9, weight_decay=0.0001)`\n* batch_size: 16 = 2 images per gpu x 8 gpus Tesla V100\n* learning rate scheduler:\n```\nif iterations \u003c 500:\n   lr = warmup(warmup_ratio=1 / 3)\nif epochs == 10:\n   lr = lr ∗ 0.1\nif epochs == 18:\n   lr = lr ∗ 0.1\nif epochs \u003e 20:\n   stop\n```\n* training time: ~3 days.\n\n### Parameter tuning:\nAfter the 12th epoch with the default parameters, the metric on LB was **0.21913**. Next, I tuned postprocessing thresholds using validation data:\n```\nrcnn=dict(\n    score_thr=0.5,\n    nms=dict(type='nms', iou_thr=0.3),\n    max_per_img=100,\n    mask_thr_binary=0.45\n)\n```\n\nThis improved the metric on LB: **0.21913 -\u0026gt; 0.30011.**\n\n### Test time augmentation:\nI use 3 scales as well as horizontal flip at test time and ensemble the results. Testing scales are (1000, 1600), (1200, 1900), (1400, 2200). \n\nI drew a TTA scheme for Mask R-CNN, which is implemented in mmdetection library. For Hybrid Task Cascade R-CNN, I rewrote this code. \n\nThis improved the metric on LB: **0.30011 -\u0026gt; 0.31074.**\n\n![TTA](figures/tta.png)\n\n### Ensemble:\nI ensemble the 3 best checkpoints of my model. The ensemble scheme is similar to TTA. \n\nThis improved the metric on LB: **0.31074 -\u0026gt; 0.31626.**\n\n![ensemble](figures/ensemble.png)\n\n### Attributes:\nI didn't use attributes at all: they were difficult to predict and the removal of classes with attributes greatly improved the metric. \n\nDuring the whole competition, I deleted classes with attributes: `{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}` U `{27, 28, 33}`. But two days before the end I read [the discussion] (https://www.kaggle.com/c/kaggle-imaterialist-fashion-2019-FGVC6/discussion/94811#latest548137) and added back classes `{27, 28, 33 }`. \n\nThis improved the metric on LB: **0.31626 -\u0026gt; 0.33511.**\n\n### Postprocessing for masks\nMy post-processing algorithm for avoid intersections of masks of the same class:\n```python\ndef hard_overlaps_suppression(binary_mask, scores):\n    not_overlap_mask = []\n    for i in np.argsort(scores)[::-1]:\n        current_mask = binary_mask[..., i].copy()\n        for mask in not_overlap_mask:\n            current_mask = np.bitwise_and(current_mask, np.invert(mask))\n        not_overlap_mask.append(current_mask)\n    return np.stack(not_overlap_mask, -1)\n```\n\n### Small postprocessing:\nI deleted objects with an area of less than 20 pixels. \n\nThis improved the metric on LB: **0.33511 -\u0026gt; 0.33621.**\n\n## How to run?\n\n### Docker\n```bash\nmake build\nmake run-[server-name]\nmake exec\n```\n\n### Build mmdetection:\n```bash\ncd mmdetection\nbash compile.sh\npython setup.py develop\n```\n\n### Prepare pretrained weights:\n```bash\nbash prepare_weights.sh\n```\n\n### Data structure\n```\n/data/\n├── train/\n│   └── ...\n├── test/\n│   └── ...\n└── train.csv.zip\n/dumps/\n└── htc_dconv_c3-c5_mstrain_x101_64x4d_fpn_20e_1200x1900/\n\n```\nFix the [error](https://www.kaggle.com/c/kaggle-imaterialist-fashion-2019-FGVC6/discussion/91217#latest-529042) in `train.csv.zip.`\n\n### Prepare annotations for mmdetection:\n```bash\ncd scripts\nbash create_mmdetection_train.sh\nbash create_mmdetection_test.sh\nbash split.sh\n```\n\n### Training the model:\n```bash\nCUDA_VISIBLE_DEVICES=[list of gpus] bash dist_train.sh [config] [gpus] [--validate] \n```\n\n#### My best checkpoint:\nhttps://yadi.sk/d/-raqliq_ad6r_Q\n\n### Test the model:\n```bash\nCUDA_VISIBLE_DEVICES=[list of gpus] bash dist_test_ensemble.sh [config] [gpus]\n```\n\n\n## References\n* https://github.com/open-mmlab/mmdetection\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirassov%2Fkaggle-imaterialist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famirassov%2Fkaggle-imaterialist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirassov%2Fkaggle-imaterialist/lists"}