{"id":15935287,"url":"https://github.com/ysh329/kaggle-cervical-cancer-screening-classification","last_synced_at":"2025-03-24T21:32:46.903Z","repository":{"id":83527094,"uuid":"89240348","full_name":"ysh329/kaggle-cervical-cancer-screening-classification","owner":"ysh329","description":"Solution and summary for Intel \u0026 MobileODT Cervical Cancer Screening (3-class classification)","archived":false,"fork":false,"pushed_at":"2017-12-02T08:10:11.000Z","size":9175,"stargazers_count":5,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T08:25:03.156Z","etag":null,"topics":["classification","deep-learning","image-processing","kaggle","kaggle-competition","medical-imaging"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ysh329.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-24T12:58:17.000Z","updated_at":"2020-10-01T07:47:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"10abbb0b-69aa-4d0c-aba3-99af2071187b","html_url":"https://github.com/ysh329/kaggle-cervical-cancer-screening-classification","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/ysh329%2Fkaggle-cervical-cancer-screening-classification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysh329%2Fkaggle-cervical-cancer-screening-classification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysh329%2Fkaggle-cervical-cancer-screening-classification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysh329%2Fkaggle-cervical-cancer-screening-classification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysh329","download_url":"https://codeload.github.com/ysh329/kaggle-cervical-cancer-screening-classification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245355631,"owners_count":20601764,"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":["classification","deep-learning","image-processing","kaggle","kaggle-competition","medical-imaging"],"created_at":"2024-10-07T03:41:03.910Z","updated_at":"2025-03-24T21:32:45.952Z","avatar_url":"https://github.com/ysh329.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kaggle-cervical-cancer-screening-classification\n\nTop 18% (153rd of 848) solution for [Kaggle Intel \u0026amp; MobileODT Cervical Cancer Screening](https://www.kaggle.com/c/intel-mobileodt-cervical-cancer-screening).\n\nOther solutions:  \n\n1. 9th solution: https://www.kaggle.com/c/intel-mobileodt-cervical-cancer-screening/discussion/35104  \n2. 20th solution: https://www.kaggle.com/c/intel-mobileodt-cervical-cancer-screening/discussion/35168\n3. 26th solution: https://www.kaggle.com/c/intel-mobileodt-cervical-cancer-screening/discussion/35111  \n3. 94th solution: https://www.kaggle.com/c/intel-mobileodt-cervical-cancer-screening/discussion/35176\n\n## Introduction\n\nIn this competition, [Intel](https://www.kaggle.com/intel) is partnering with [MobileODT](http://www.mobileodt.com/) to challenge Kagglers to develop an algorithm which accurately identifies a woman’s cervix type based on images. Doing so will prevent ineffectual treatments and allow healthcare providers to give proper referral for cases that require more advanced treatment.\n\n## Basic Idea with Step-by-Step Implementation\n\n1. [[pre-processing]](./code/cervix-part-crop-GMM-Method-on-train-additional-train-and-test-set.ipynb) Due to being slow to process high resolution (`4000*4000`, etc) images, I resize the original images to fixed size (`224*224`) and crop out the no-relevant part.\n2. [Generate MXNet format binary file of images] Prepare `.lst` and `.rec` files referring [Prepare Datasets | MXNet](https://github.com/dmlc/mxnet/tree/master/example/image-classification#prepare-datasets).\n3. [[Train models from scratch]](./train-or-finetune-model/models/) use `run_train_scripts.sh` and `train_ccs-train.py` to train a network from scratch.\n4. [[fine-tune models]](./train-or-finetune-model/finetune-models/) use `run_finetune_script.sh`, `run_finetune.py` and `run_finetune_data-aug.py` to fine-tune pre-trained models.\n5. [[prepare submission]](./train-or-finetune-model/) use `get_result_for_one_network.sh` and `run_inference.py` scripts to prepare submission based on test set.\n6. [[Boosting multi-sub-models and prepare submission]](./code/train-boost-model-based-on-multi-features.ipynb) train a boosting model based on multi-sub-models. Of course, you should select some sub-models from last step and put preparing-boosting sub-models in `./models` directory.\n\n\n## Repo. Structure\n\n```\n├── `code` contains pre-processing step (image crop), boosting Jupyter notebook\n├── `intel` contains remote host environments intel provided (useless for me)\n├── `model` MXNet models, which prepare to make boosting based on these models\n├── `pre-submit` preparing submit file\n│   ├── [result]finetune-resnet-152-train-add-seg-224-lr-0.001-momentum-0.9\n│   ├── [result]finetune-resnet-200-train-add-seg-224-lr-0.001-momentum-0.9\n│   └── [result]inception-resnet-v2-152-train-add-seg-224-lr-0.01\n├── `submitted` stage1 submitted file\n│   ├── [result]finetune-resnet-101-train-add-seg-224-lr-0.001-momentum-0.9\n│   ├── [result]finetune-resnet-152-imagenet-11k-365-ch-train-add-seg-224-lr-0.01\n│   ├── [result]finetune-resnet-152-imagenet-11k-train-add-seg-224-lr-0.01\n│   ├── [result]finetune-resnet-200-train-add-seg-224\n│   ├── [result]finetune-resnet-34-train-add-seg-224-lr-0.01\n│   ├── [result]finetune-resnet-50-imagenet-11k-365-ch-train-add-seg-224-lr-0.01\n│   ├── [result]finetune-resnet-50-trian-add-seg-224-lr-0.01\n│   ├── [result]finetune-resnext-101-train-add-seg-224-lr-0.001-momentum-0.9\n│   ├── [result]finetune-resneXt-101-train-add-seg-224-lr-0.01\n│   ├── [result]finetune-resnext-50-train-add-seg-224-lr-0.001-momentum-0.9\n│   ├── [result]finetune-resneXt-50-train-add-seg-224-lr-0.01\n│   ├── [result]inception-resnet-v2-18-train-add-seg-224-lr-0.01\n│   ├── [result]inception-resnet-v2-50-train-add-seg-224-lr-0.01\n│   ├── [result]inception-resnet-v2-train-add-seg-224-lr-0.01\n│   ├── [result]inception-resnet-v2-train-seg-224-lr-0.05\n│   ├── [result]inception-resnt-v2-train-224-lr-0.05\n│   ├── [result]resnet-50-train-seg-224-lr-0.05\n│   └── [result-v2?]inception-resnet-v2-50-train-add-seg-224-lr-0.01\n└── `train-or-finetune-model` those train-from-scratched and fine-tuned models\n    ├── `finetune-models` those checkpoints and logs of fine-tuning models\n    ├── `models` those checkpoints and logs of train-from-scratch models\n    ├── `submitted` stage1 submission file\n    └── `tmp` useless files\n```\n\n## 0. Data\n\n* 3-class classification\n* Training set has 1400+ images( type1: 250, type2: 781, type3: 450 ).\n* Training + Additional set have 8000+ images ( all type1: 1440,  all type2: 4346, all type3: 2426 ) .\n\nBlank files (0 KB) :\n\n1. `additional/Type_1/5893.jpg`\n2. `additional/Type_2/5892.jpg`\n3. `additional/Type_2/2845.jpg`\n4. `additional/Type_2/6360.jpg`\n\nNon-cervix images:\n\n1. `additional/Type_1/746.jpg`\n2. `additional/Type_1/2030.jpg`\n3. `additional/Type_1/4065.jpg`\n4. `additional/Type_1/4706.jpg`\n5. `additional/Type_2/1813.jpg`\n6. `additional/Type_2/3086.jpg`\n\n## 1. Train from Scratch\n\nFirst, I tried train `MLP`, `LeNet`, `GoogLeNet`, `AlexNet`, `ResNet-50`, `ResNet-152`, `inception-ResNet-v2`, and `ResNeXt` models from scratch based on training and additional data.\n*  `MLP` and `LeNet` doesn't converge in 30 even more epochs, logging as the accuracy of validation and training set is between 17%~30%;\n*  `ResNeXt`, `AlexNet`, `GoogLeNet` in 30 even more epochs, logging as the accuracy of validation and training set is between 30%~50%;\n*  I found that `inception-ResNet-v2`, `ResNet` performance are best, in 300 epochs val-acc can reach 50% above even 60%.\n\nAccording to some papers, resolution of image is also significant for performance. Due to limited GPU RAM, three GPUs (0  GeForce GTX TIT 6082MiB, 1  Tesla K20c 4742MiB, 2  TITAN X (Pascal) 12189MiB) , I set batch size (not batch number) between 10 and 30 (10+ images per gpu) and resize original image to `224*224`.\n\nHowever, the best submission is not those models, which have highest val-acc (such as 70% while not over-fitting), but those models whose train-acc and val-acc are similar and just reach a not bad val-acc (such as 60%).\n\nWhat a pity! I don't try to make augmentation based on original training and additional images. I think it must make sense.\n\nNote: I found that the index order of GPU in `MXNet` (when declaring `mx.gpu(i)`) is opposite to `nvidia-smi` printed order( below ). In MXNet, the 0 is not GeForce GTX TITAN but TITAN X (Pascal).\n\n```\n+-----------------------------------------------------------------------------+\n| NVIDIA-SMI 375.39                 Driver Version: 375.39                    |\n|-------------------------------+----------------------+----------------------+\n| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |\n| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |\n|===============================+======================+======================|\n|   0  GeForce GTX TIT...  Off  | 0000:02:00.0     Off |                  N/A |\n| 26%   36C    P8    14W / 250W |      2MiB /  6082MiB |      0%      Default |\n+-------------------------------+----------------------+----------------------+\n|   1  Tesla K20c          Off  | 0000:03:00.0     Off |                    0 |\n| 30%   36C    P8    26W / 225W |      2MiB /  4742MiB |      0%      Default |\n+-------------------------------+----------------------+----------------------+\n|   2  TITAN X (Pascal)    Off  | 0000:82:00.0     Off |                  N/A |\n| 44%   73C    P2   156W / 250W |   8713MiB / 12189MiB |     99%      Default |\n+-------------------------------+----------------------+----------------------+\n\n+-----------------------------------------------------------------------------+\n| Processes:                                                       GPU Memory |\n|  GPU       PID  Type  Process name                               Usage      |\n|=============================================================================|\n|    2     31661    C   python                                        8707MiB |\n+-----------------------------------------------------------------------------+\n```\n\n\n## 2. Fine-tune from Pre-Trained Model\n\nAlthough results of training `inception-ResNet-v2` and `ResNet` from scratch are good, but I found the results from fine-tuning pre-trained models (based on ImageNet data set) are better.\n\n### 2.1 Easily Over-Fitting and Great ResNet Model\n\n* I fine-tuned `ResNet-18`, `ResNet-34`, `ResNet-50`, `ResNet-101`, `ResNet-152`, `ResNet-200`, `ResNeXt-50`, `ResNeXt-101` models.\n* It's very easily over-fitting to fine-tuning on pre-trained model. After three or four epoch, model have apparently over-fitting evidence.\n\n### 2.2 Hyper-Parameter Optimization\n\nBesides, I only made parameter optimization about learning rate, which I find **smaller the learning rate is, more easily over-fitting the model is.** Of course, you can make some regularization such as `early stopping` to delay this procedure.\n\n### 2.3 Network Depth\n\nGenerally speaking, I found deeper the network is, better the result I get, but it's not always true, such as below ones (of course, good networks after the final fine-tune):\n\n |        model        |best val-acc epoch|submission score (log-loss) | val-acc   |train-acc |\n |---------------------| ---------------- | -------------------------  |---------  |--------- |\n |ResNeXt-50-lr-0.01   |         3        | 0.74195                    |  0.695312 | 0.875    |\n |ResNeXt-101-lr-0.01  |         3        | 0.77904                    |  0.630208 | 0.864583 |\n |ResNet-101-lr-0.01   |         2        | 0.77222                    |  0.605769 | 0.645833 |\n |ResNet-152-lr-0.01   |         3        | 0.74618                    |  0.673077 | 0.822917 |\n |ResNet-200-lr-0.01   |         3        | 0.76409                    |  0.666667 | 0.84375  |\n\nso far, I make some parameter modified about learning rate and adding momentum. However, after reducing the learning rate to 0.001 and adding momentum as 0.9, the validation accuracy and submission score (log-loss) have no improvement but submission score dropped.\n\n### 2.4 Pre-Trained Model\n\nAll pre-trained models're from [data.dmlc.ml/models](http://data.dmlc.ml/models/).\n\nDifferent pre-trained data sets make fine-tuned model different performance.\n\nI tried pre-trained models based on two kind images: the one is `ImageNet-11k`, the other is `ImageNet-11k-place365-ch`.\n\nI don't know what's the `ImageNet-11k-place365-ch` image, it seems place or street-view images. The performance of this kind pre-trained model is not good, same as train from scratch.\n\n## 3. Boosting\n\nAfter fine-tuning those networks, I think I can make more progress on submission score using boosting based on fine-tuned models.\n\nHowever, it seems no improvement but dropped a lot (dropped 0.4~0.6 log-loss). I think maybe I have something wrong with use of `XGBoost`. Of course, I have to admit I'm, in fact, new to use `XGBoost`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysh329%2Fkaggle-cervical-cancer-screening-classification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysh329%2Fkaggle-cervical-cancer-screening-classification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysh329%2Fkaggle-cervical-cancer-screening-classification/lists"}