kaggle-panda-1st-place-solution

1st place solution for the Kaggle PANDA Challenge

https://github.com/kentaroy47/kaggle-panda-1st-place-solution

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: nature.com, mdpi.com
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.8%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

1st place solution for the Kaggle PANDA Challenge

Basic Info
  • Host: GitHub
  • Owner: kentaroy47
  • License: other
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 289 MB
Statistics
  • Stars: 115
  • Watchers: 2
  • Forks: 19
  • Open Issues: 2
  • Releases: 0
Created almost 6 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

Kaggle-PANDA-1st-place-solution

This is the 1st place solution of the PANDA Competition, where the specific writeup is here.

The codes and models are created by Team PND, @yukkyo and @kentaroy47.

Our model and codes are open sourced under CC-BY-NC 4.0. Please see LICENSE for specifics.

You can skip some steps (because some outputs are already in input dir).

Used in

Nature Medicine: W.Bulten, Artificial intelligence for diagnosis and Gleason grading of prostate cancer: the PANDA challenge

npj Precision Oncology: Y.Tolkach, An international multi-institutional validation study of the algorithm for prostate cancer detection and Gleason grading

Cancers: Label distribution learning for automatic cancer grading of histopathological images of prostate cancer

Slide describing our solution!

https://docs.google.com/presentation/d/1Ies4vnyVtW5U3XNDr_fom43ZJDIodu1SV6DSK8di6fs/

1. Environment

You can choose using docker or not.

1.1 Don't use docker (haven't tested..)

  • Ubuntu 18.04
  • Python 3.7.2
  • CUDA 10.2
  • NVIDIA/apex == 1.0 installed

```bash

main dependency

$ pip install -r docker/requirements.txt

arutema code dependency

$ pip install git+https://github.com/ildoonet/pytorch-gradual-warmup-lr.git $ pip install efficientnet_pytorch ```

1.2 Use docker (Recommended)

```bash

build

$ sh docker/build.sh

run

$ sh docker/run.sh

exec

$ sh docker/exec.sh ```

2. Preparing

2.1 Get Data

Download only trainimages and trainmasks.

bash $ cd input $ kaggle download ... $ unzip ...

(skip) 2.2 Grouping imageids by image hash threshold

  • If you want to do it on your own: https://www.kaggle.com/yukkyo/imagehash-to-detect-duplicate-images-and-grouping
  • We will just place the output of the script as:
    • input/duplicate_imgids_imghash_thres_090.csv

(skip) 2.3 Split kfold

bash $ cd src $ python data_process/s00_make_k_fold.py

  • Is constant with fixed seed
  • output:
    • input/train-5kfold.csv

2.4 Make tile pngs for training

bash $ cd src $ python data_process/s07_simple_tile.py --mode 0 $ python data_process/s07_simple_tile.py --mode 2 $ python data_process/a00_save_tiles.py $ cd ../input $ cd numtile-64-tilesize-192-res-1-mode-0 $ unzip train.zip -d train $ cd .. $ cd numtile-64-tilesize-192-res-1-mode-2 $ unzip train.zip -d train $ cd ..

3. Train base model for removing noise(expected TitanRTX x 1)

Each fold needs about 18 hours.

bash $ cd src $ python train.py --config configs/final_1.yaml --kfold 1 $ python train.py --config configs/final_1.yaml --kfold 2 $ python train.py --config configs/final_1.yaml --kfold 3 $ python train.py --config configs/final_1.yaml --kfold 4 $ python train.py --config configs/final_1.yaml --kfold 5

  • output:
    • output/model/final_1
    • Each weights and train logs

4. Predict to local validation for removing noise

Each fold needs about 1 hour.

bash $ cd src $ python kernel.py --kfold 1 $ python kernel.py --kfold 2 $ python kernel.py --kfold 3 $ python kernel.py --kfold 4 $ python kernel.py --kfold 5

  • outputs are prediction results of the hold-out train data:
    • output/model/final_1/local_preds~~~.csv

5. Remove noise

bash $ cd src $ python data_process/s12_remove_noise_by_local_preds.py

  • output:
    • output/model/final_1
    • local_preds_final_1_efficientnet-b1.csv
      • Concatenated prediction results of the hold-out data
      • This is used to clean labels
    • local_preds_final_1_efficientnet-b1_removed_noise_thresh_16.csv
      • Used to train Model 1
      • Base label cleaning results
    • local_preds_final_1_efficientnet-b1_removed_noise_thresh_rad_13_08_ka_15_10.csv
      • Used to train Model 2
      • Label cleaned to remove 20% Radboud labels
  • FYI: we used this csv at final sub on competition: (did not fix seed at time)
    • input/train-5kfold_remove_noisy_by_0622_rad_13_08_ka_15_10.csv

6. Re-train 5-fold models with noise removed

  • You can replace output/train-5kfold_remove_noisy.csv to input/train-5kfold_remove_noisy_by_0622_rad_13_08_ka_15_10.csv in config

  • Only 1,4,5 folds are used for final inference

  • Each fold needs about 15 hours.

## Training model 2(fam_taro model):

```bash $ cd src

only best LB folds are trained

$ python train.py --config configs/final2.yaml --kfold 1 $ python train.py --config configs/final2.yaml --kfold 4 $ python train.py --config configs/final_2.yaml --kfold 5 ```

Training model 1(arutema model):

Please run train_famdata-kfolds.ipynb on jupyter notebook or

```bash

go to home

$ python train_famdata-kfolds.py ```

I haven't tested .py, so please try .ipynb for operation.

The final models are saved to models.

Each fold will take 4 hours.

Trained models

Models reproducing 1st place score is saved in ./final_models

7. Submit on Kaggle Notebook

  • kernels

    • final sub on competition:
    • score: public 0.904, private 0.940 (1st)
    • url: https://www.kaggle.com/yukkyo/latesub-pote-fam-aru-ensemble-0722-ew-1-0-0?scriptVersionId=39271011
    • reproduced results (seed fixed as in this scripts, you can reproduce)
    • score: public 0.894, private 0.939 (1st)
    • url: https://www.kaggle.com/kyoshioka47/late-famrepro-fam-reproaru-ensemble-0725?scriptVersionId=39879219
    • submitted_notebook.ipynb
    • Simple 5-fold model to get private 0.935(3rd)
    • url: https://www.kaggle.com/kyoshioka47/5-fold-effb0-with-cleaned-labels-pb-0-935
  • You can change paths by changing bellow.

    • You must change Kaggle Dataset path for using your reproduced weights

```python

Model 2

Line [7]

class Config: def init(self, on_kernel=True, kfold=1, debug=False): ... ... ...

    # You can change weight name. But not need on this README
    self.weight_name = "final_2_efficientnet-b1_kfold_{}_latest.pt"
    self.weight_name = self.weight_name.format(kfold)

    ...
    ...
    ...

def get_weight_path(self):
    if self.on_kernel:
        # You should change this path to your Kaggle Dataset path
        return os.path.join("../input/030-weight", self.weight_name)
    else:
        dir_name = self.weight_name.split("_")[0]
        return os.path.join("../output/model", dir_name, self.weight_name)

Model 1

Line [13]

def loadmodels(modelfiles): models = [] for modelf in modelfiles: ## You should change this path to your Kaggle Dataset path modelf = os.path.join("../input/latesubspanda", modelf) ...

modelfiles = [ 'efficientnet-b0famlabelsmodelsubavgpooltile36imsize256mixupfinalepoch20fold0.pth', ]

modelfiles2 = [ 'efficientnet-b0famlabelsmodelsubavgpooltile36imsize256mixupfinalepoch20fold0.pth', "efficientnet-b0famlabelsmodelsubavgpooltile36imsize256mixupfinalepoch20fold1.pth", "efficientnet-b0famlabelsmodelsubavgpooltile36imsize256mixupfinalepoch20fold2.pth", "efficientnet-b0famlabelsmodelsubavgpooltile36imsize256mixupfinalepoch20fold3.pth", "efficientnet-b0famlabelsmodelsubavgpooltile36imsize256mixupfinalepoch20fold4.pth" ]

```

Owner

  • Name: Kentaro Yoshioka
  • Login: kentaroy47
  • Kind: user
  • Location: Tokyo, Japan
  • Company: Keio University

2-year old Ph.D researcher interested in efficient and fast systems.

GitHub Events

Total
  • Issues event: 1
  • Watch event: 13
  • Push event: 1
  • Fork event: 1
Last Year
  • Issues event: 1
  • Watch event: 13
  • Push event: 1
  • Fork event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 19
  • Total Committers: 2
  • Avg Commits per committer: 9.5
  • Development Distribution Score (DDS): 0.053
Past Year
  • Commits: 2
  • Committers: 1
  • Avg Commits per committer: 2.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Kentaro Yoshioka m****7@g****m 18
y.fujimoto y****2@g****m 1

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 3
  • Total pull requests: 2
  • Average time to close issues: about 2 months
  • Average time to close pull requests: less than a minute
  • Total issue authors: 3
  • Total pull request authors: 2
  • Average comments per issue: 3.67
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • lsnls (1)
  • morizin (1)
  • valeriozhang (1)
Pull Request Authors
  • yukkyo (1)
  • kentaroy47 (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

docker/requirements.txt pypi
  • Cython ==0.29.19
  • ImageHash ==4.1.0
  • Jinja2 ==2.11.2
  • Keras-Preprocessing ==1.1.2
  • Mako ==1.1.3
  • Markdown ==3.2.2
  • MarkupSafe ==1.1.1
  • Pillow ==7.1.2
  • PyWavelets ==1.1.1
  • PyYAML ==5.3.1
  • Pygments ==2.6.1
  • SQLAlchemy ==1.3.17
  • Send2Trash ==1.5.0
  • Werkzeug ==1.0.1
  • absl-py ==0.9.0
  • addict ==2.2.1
  • albumentations ==0.4.1
  • alembic ==1.4.2
  • astropy ==4.0.1.post1
  • astunparse ==1.6.3
  • attrs ==19.3.0
  • backcall ==0.1.0
  • bleach ==3.1.5
  • cachetools ==4.1.0
  • catboost ==0.23.2
  • certifi ==2020.4.5.1
  • chardet ==3.0.4
  • cliff ==3.1.0
  • cmaes ==0.5.0
  • cmd2 ==0.8.9
  • cnn-finetune ==0.6.0
  • colorlog ==4.1.0
  • confuse ==1.1.0
  • cycler ==0.10.0
  • decorator ==4.4.2
  • defusedxml ==0.6.0
  • efficientnet-pytorch ==0.6.3
  • entrypoints ==0.3
  • future ==0.18.2
  • gast ==0.3.3
  • google-auth ==1.16.0
  • google-auth-oauthlib ==0.4.1
  • google-pasta ==0.2.0
  • graphviz ==0.14
  • grpcio ==1.29.0
  • h5py ==2.10.0
  • htmlmin ==0.1.12
  • idna ==2.9
  • imagecodecs ==2020.5.30
  • imageio ==2.8.0
  • imgaug ==0.2.6
  • importlib-metadata ==1.6.0
  • ipykernel ==5.3.0
  • ipython ==7.15.0
  • ipython-genutils ==0.2.0
  • ipywidgets ==7.5.1
  • iterative-stratification ==0.1.6
  • jedi ==0.17.0
  • joblib ==0.15.1
  • json5 ==0.9.5
  • jsonschema ==3.2.0
  • jupyter-client ==6.1.3
  • jupyter-core ==4.6.3
  • jupyterlab ==2.1.4
  • jupyterlab-server ==1.1.5
  • kaggle ==1.5.6
  • kiwisolver ==1.2.0
  • lightgbm ==2.3.1
  • llvmlite ==0.32.1
  • matplotlib ==3.2.1
  • missingno ==0.4.2
  • mistune ==0.8.4
  • munch ==2.5.0
  • nbconvert ==5.6.1
  • nbformat ==5.0.6
  • networkx ==2.4
  • notebook ==6.0.3
  • numba ==0.49.1
  • numpy ==1.18.5
  • oauthlib ==3.1.0
  • opencv-python ==4.2.0.34
  • opencv-python-headless ==4.2.0.34
  • opt-einsum ==3.2.1
  • optuna ==1.5.0
  • packaging ==20.4
  • pandas ==1.0.4
  • pandas-profiling ==2.8.0
  • pandocfilters ==1.4.2
  • parso ==0.7.0
  • pbr ==5.4.5
  • pexpect ==4.8.0
  • phik ==0.10.0
  • pickleshare ==0.7.5
  • plotly ==4.8.1
  • pretrainedmodels ==0.7.4
  • prettytable ==0.7.2
  • prometheus-client ==0.8.0
  • prompt-toolkit ==3.0.5
  • protobuf ==3.12.2
  • ptyprocess ==0.6.0
  • pyasn1 ==0.4.8
  • pyasn1-modules ==0.2.8
  • pyparsing ==2.4.7
  • pyperclip ==1.8.0
  • pyrsistent ==0.16.0
  • python-dateutil ==2.8.1
  • python-editor ==1.0.4
  • python-slugify ==4.0.0
  • pytorch-lightning ==0.8.5
  • pytorch-ranger ==0.1.1
  • pytz ==2020.1
  • pyzmq ==19.0.1
  • requests ==2.23.0
  • requests-oauthlib ==1.3.0
  • retrying ==1.3.3
  • rsa ==4.0
  • scikit-image ==0.17.2
  • scikit-learn ==0.23.1
  • scipy ==1.4.1
  • seaborn ==0.10.1
  • six ==1.15.0
  • sklearn-pandas ==1.8.0
  • slackweb ==1.0.5
  • stevedore ==1.32.0
  • tangled-up-in-unicode ==0.0.6
  • tb-nightly ==2.3.0a20200603
  • tensorboard ==2.2.2
  • tensorboard-plugin-wit ==1.6.0.post3
  • tensorboardX ==2.0
  • tensorflow ==2.2.0
  • tensorflow-estimator ==2.2.0
  • termcolor ==1.1.0
  • terminado ==0.8.3
  • testpath ==0.4.4
  • text-unidecode ==1.3
  • threadpoolctl ==2.1.0
  • tifffile ==2020.6.3
  • torch ==1.5.0
  • torch-optimizer ==0.0.1a13
  • torchvision ==0.6.0
  • tornado ==6.0.4
  • tqdm ==4.46.1
  • traitlets ==4.3.3
  • ttach ==0.0.2
  • urllib3 ==1.24.3
  • visions ==0.4.4
  • wcwidth ==0.2.3
  • webencodings ==0.5.1
  • widgetsnbextension ==3.5.1
  • wrapt ==1.12.1
  • zipp ==3.1.0
docker/Dockerfile docker
  • nvidia/cuda 10.2-cudnn7-devel-ubuntu18.04 build