Home

Awesome

SOLUTION WRITE UP -

https://www.kaggle.com/c/aptos2019-blindness-detection/discussion/108030

Kaggle-APTOS-2019-Blindness-Detection

About Challange:

Imagine being able to detect blindness before it happened.

Millions of people suffer from diabetic retinopathy, the leading cause of blindness among working aged adults. Aravind Eye Hospital in India hopes to detect and prevent this disease among people living in rural areas where medical screening is difficult to conduct. Successful entries in this competition will improve the hospital’s ability to identify potential patients. Further, the solutions will be spread to other Ophthalmologists through the 4th Asia Pacific Tele-Ophthalmology Society (APTOS) Symposium

Currently, Aravind technicians travel to these rural areas to capture images and then rely on highly trained doctors to review the images and provide diagnosis. Their goal is to scale their efforts through technology; to gain the ability to automatically screen images for disease and provide information on how severe the condition may be.

In this synchronous Kernels-only competition, you'll build a machine learning model to speed up disease detection. You’ll work with thousands of images collected in rural areas to help identify diabetic retinopathy automatically. If successful, you will not only help to prevent lifelong blindness, but these models may be used to detect other sorts of diseases in the future, like glaucoma and macular degeneration.

SETUP

OLD DATA - Diabetic Retinopathy Detection (https://www.kaggle.com/c/diabetic-retinopathy-detection) <br/> NEW DATA - APTOS 2019 Blindness Detection (https://www.kaggle.com/c/aptos2019-blindness-detection/data)

EXP_725 (LB: 0.808)

I am gonna first pretrain model on OLD DATA and than fine tune on NEW DATA with 5-fold cross-validaion Important transformation here is zoom crop to the center from (0.9 to 1.4)

EXP_725.ipynb

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              128
SZ:              224
VALID:           NEW DATA

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(0.9, 1.4), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(10, 1e-3,   wd=1e-2, div_factor=10, pct_start=0.3)-UNF
                 fit_one_cycle(5,  1e-3/5, wd=1e-2, div_factor=10, pct_start=0.3)-UNF
                 fit_one_cycle(30, 1e-3/8, wd=1e-2, div_factor=10, pct_start=0.3)-UNF
MODEL WEIGHTS:   NB_EXP_725_UNFREEZE_P3
MODEL TRN_LOSS:  0.305515
MODEL VAL_LOSS:  0.342098
QUADR KAPPA:     0.887489
LB SCORE:        0.725
SUBMISSION FLN:  EXP_725(version 11/14)

Comments: Pretrained model trained just OLD DATA gives pretty good results. Now using best weight to fine tune new data

[EXP_725-CV_0 - EXP_725-CV_4].ipynb

Using weights NB_EXP_725_UNFREEZE_P3To train NEW DATA with 5 fold splits. <br/>

Set up for all CV experimetns:

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              128
SZ:              224
VALID:           NEW DATA CV SPLIT

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(0.9, 1.4), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(15, 1e-3,   wd=1e-2, div_factor=10, pct_start=0.3)-UNF

Summary:

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_725-CV_00.3030280.1986700.924300NB_EXP_725_CV_0_UNFREEZE_P1
EXP_725-CV_10.2597110.2614480.909077NB_EXP_725_CV_1_UNFREEZE_P1
EXP_725-CV_20.3180010.2313780.914873NB_EXP_725_CV_2_UNFREEZE_P1
EXP_725-CV_30.2019590.1828000.929271NB_EXP_725_CV_3_UNFREEZE_P1
EXP_725-CV_40.1957600.2048930.937953NB_EXP_725_CV_4_UNFREEZE_P1

Submission (Average all the predictions)

LB SCORE:        0.808
SUBMISSION FLN:  EXP_725(version 12/14)

EXP_725_352 (LB: 0.785)

Same as EXP_725 but increased image size to 352 and added more robust center zoom crop (1.1 - 1.45x). Trained using weights from EXP_725, NB_EXP_725_UNFREEZE_P3

EXP_725_352.ipynb

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              56
SZ:              352
VALID:           NEW DATA

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.1, 1.45), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(5, 1e-3,    wd=1e-2, div_factor=10, pct_start=0.3)-UNF
                 fit_one_cycle(3, 1e-3/10, wd=1e-2, div_factor=25, pct_start=0.3)-UNF

MODEL WEIGHTS:   NB_EXP_725_352_UNFREEZE_P2
MODEL TRN_LOSS:  0.289148
MODEL VAL_LOSS:  0.335972
QUADR KAPPA:     0.893238
LB SCORE:        0.727
SUBMISSION FLN:  EXP_725_352(version 16/17)

Comments: Pretrained model on NB_EXP_725_UNFREEZE_P3 with image siae 224, Increaseing image size to 352 and adding extra zoom helped with the validation loss.

[EXP_725_352-CV_0 - EXP_725_352-CV_4].ipynb

Using weights NB_EXP_725_UNFREEZE_P3To train NEW DATA with 5 fold splits. <br/>

Set up for all CV experimetns:

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              56
SZ:              352
VALID:           NEW DATA CV SPLIT

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.1, 1.45), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(15, 1e-3,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF

Summary:

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_725_352-CV_00.2140580.1914760.926447NB_EXP_725_352_CV_0_UNFREEZE_P1
EXP_725_352-CV_10.2206990.2323170.914668NB_EXP_725_352_CV_1_UNFREEZE_P1
EXP_725_352-CV_20.2166040.2188290.921627NB_EXP_725_352_CV_2_UNFREEZE_P1
EXP_725_352-CV_30.2228790.1650610.931339NB_EXP_725_352_CV_3_UNFREEZE_P1
EXP_725_352-CV_40.2186910.1899280.936874NB_EXP_725_352_CV_4_UNFREEZE_P1

Submission (Average all the predictions)

LB SCORE:        0.785
SUBMISSION FLN:  EXP_725_352(version 15/15)

EXP_730_BEN (LB: 0.804)

Same as EXP_725 added more robust center zoom crop (1.02 - 1.35x). Trained using weights from EXP_725, NB_EXP_725_UNFREEZE_P3. Images this time were proces. with Ben Method. Old ben method was not taking in two condiseration image ratio when resizing, I have added function resize_to which preserves image ratio when resizing. For proceessing images I used notebook BEN_PROCESS.ipynb

EXP_730.ipynb

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              128
SZ:              224
VALID:           NEW DATA

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.02, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(10, 1e-3,    wd=1e-2, div_factor=25, pct_start=0.3)-UNF

MODEL WEIGHTS:   NB_EXP_725_352_UNFREEZE_P2
MODEL TRN_LOSS:  0.316414
MODEL VAL_LOSS:  0.302961
QUADR KAPPA:     0.896701
LB SCORE:        0.755
SUBMISSION FLN:  EXP_725_352(version 17/17)

Comments: Model trained using old data and weights from EXP_725, showed good training and loss.

[EXP_730-CV_0 - EXP_730-CV_4].ipynb

Using weights NB_EXP_730_UNFREEZE_P1To train NEW DATA with 5 fold splits. <br/>

Set up for all CV experimetns:

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              56
SZ:              352
VALID:           NEW DATA CV SPLIT

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                  zoom_crop(scale=(1.01, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(15, 1e-3,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF

Summary:

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_730-CV_00.2308800.2143560.920836NB_EXP_730_CV_0_UNFREEZE_P1
EXP_730-CV_10.2983170.2514410.918218NB_EXP_730_CV_1_UNFREEZE_P1
EXP_730-CV_20.2166040.2996890.904481NB_EXP_730_CV_2_UNFREEZE_P1
EXP_730-CV_30.1784830.1768290.932204NB_EXP_730_CV_3_UNFREEZE_P1
EXP_730-CV_40.1701330.2352390.928617NB_EXP_730_CV_4_UNFREEZE_P1

Submission (Average all the predictions)

LB SCORE:        0.804
SUBMISSION FLN:  EXP_730_BEN(version 22/22)

EXP_730_352_BEN (LB: TBD)

Same as EXP_730_BEN added more robust center zoom crop (1.02 - 1.35x) and the image size increased to 352. Trained using weights from EXP_730_BEN, NB_EXP_730_UNFREEZE_P1.

EXP_730_352.ipynb

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              56
SZ:              352
VALID:           NEW DATA

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.02, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(5, 1e-3/2,    wd=1e-2, div_factor=25, pct_start=0.3)-UNF

MODEL WEIGHTS:   NB_EXP_730_352_UNFREEZE_P1
MODEL TRN_LOSS:  0.224072
MODEL VAL_LOSS:  0.342114
QUADR KAPPA:     0.890448
LB SCORE:        TBD
SUBMISSION FLN:  TBD

Comments: This is trained mainly to use for transfer learning

EXP_735 (LB: 0.793)

Training on old data with image size 352, I am using weitts for transfer learning from the notebook EXP_730_352, NB_EXP_730_352_UNFREEZE_P1. Image were first cropped to remove all the black background using script TBD.

EXP_735.ipynb

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              56
SZ:              352
VALID:           NEW DATA

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.02, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(10, 1e-3,    wd=1e-2, div_factor=25, pct_start=0.3)-UNF

MODEL WEIGHTS:   NB_EXP_735_UNFREEZE_P1
MODEL TRN_LOSS:  0.233254
MODEL VAL_LOSS:  0.332348
QUADR KAPPA:     0.893338
LB SCORE:        TBD
SUBMISSION FLN:  TBD

Comments: Looks good move to cv

[EXP_735-CV_0 - EXP_735-CV_4].ipynb

Using weights NB_EXP_735_UNFREEZE_P1To train NEW DATA with 5 fold splits. <br/>

Set up for all CV experimetns:

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              56
SZ:              352
VALID:           NEW DATA CV SPLIT

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                  zoom_crop(scale=(1.01, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(15, 1e-3,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF

Summary:

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_735-CV_00.2501330.2051210.920307NB_EXP_735_CV_0_UNFREEZE_P1
EXP_735-CV_10.1351740.2110530.921838NB_EXP_735_CV_1_UNFREEZE_P1
EXP_735-CV_20.1762700.1706850.932106NB_EXP_735_CV_2_UNFREEZE_P1
EXP_735-CV_30.2300970.2233430.915626NB_EXP_735_CV_3_UNFREEZE_P1
EXP_735-CV_40.1465270.2054500.931362NB_EXP_735_CV_4_UNFREEZE_P1

Submission (Average all the predictions)

LB SCORE:        0.793
SUBMISSION FLN:  EXP_352_crop(version 25/25)

EXP_740 (LB: 0.821, PB: 0.926)

In this experiment I combine OLD DATA with NEW DATA and do StratifiedKFold 5 Fold CV. Before combining I remove in NEW DATA all the duplicates and confusing label images (see in notebooks function get_ign_list). Moreover images are preprocessed using PROCCES.ipynb. This processing helps to remove extra black baground and center the images. Training is done in 3 phases with graudela increasing image sizes - 224, 352, 448

Set up for all CV experimetns:

IMG SIZE 224

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              128
SZ:              224
VALID:           StratifiedKFold split of combined data

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.01, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(10, 1e-2/7,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF
                 fit_one_cycle(5,  1e-2/7/5, wd=1e-2, div_factor=25, pct_start=0.3)-UNF

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_740-CV_00.3070500.3429560.757189NB_EXP_740_CV_0_UNFREEZE_P2
EXP_740-CV_10.3020080.3378400.756192NB_EXP_740_CV_1_UNFREEZE_P2
EXP_740-CV_20.3187440.3684000.740174NB_EXP_740_CV_2_UNFREEZE_P2
EXP_740-CV_30.3064370.3303850.772315NB_EXP_740_CV_3_UNFREEZE_P2
EXP_740-CV_40.3082710.3440590.758115NB_EXP_740_CV_4_UNFREEZE_P2

IMG SIZE 352

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              352
SZ:              52
VALID:           StratifiedKFold split of combined data

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.01, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(5, 1e-3/8,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_740-CV_00.2340840.2525820.821898NB_EXP_740_CV_0_352_UNFREEZE_P1
EXP_740-CV_10.2433290.2457240.825637NB_EXP_740_CV_1_352_UNFREEZE_P1
EXP_740-CV_20.2495290.2622160.814094NB_EXP_740_CV_2_352_UNFREEZE_P1
EXP_740-CV_30.2537430.2428280.832840NB_EXP_740_CV_3_352_UNFREEZE_P1
EXP_740-CV_40.2527610.2494560.823078NB_EXP_740_CV_4_352_UNFREEZE_P1

IMG SIZE 448

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              448
SZ:              32
VALID:           StratifiedKFold split of combined data

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.01, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(5, 1e-3/4,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_740-CV_00.2424960.2461180.815219NB_EXP_740_CV_0_448_UNFREEZE_P1
EXP_740-CV_10.2312800.2318280.822380NB_EXP_740_CV_1_448_UNFREEZE_P1
EXP_740-CV_20.2483600.2495340.813643NB_EXP_740_CV_2_448_UNFREEZE_P1
EXP_740-CV_30.2654760.2312230.829990NB_EXP_740_CV_3_448_UNFREEZE_P1
EXP_740-CV_40.2389910.2355020.826658NB_EXP_740_CV_4_448_UNFREEZE_P1
CV SCORE:        0.821578 
LB SCORE:        0.818
SUBMISSION FLN:  EXP_740(version 32/32)

IMG SIZE 448

MODEL:           EfficientNet-B5
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
SZ:              456
BS:              32
VALID:           StratifiedKFold split of combined data

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 max_zoom(1.3),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.01, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(5, 1e-3/4,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF

Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_740-CV_00.2325610.2473120.813309NB_EXP_740_CV_0_448_UNFREEZE_P1_rs1
EXP_740-CV_10.2125610.2403020.816792NB_EXP_740_CV_1_448_UNFREEZE_P1_rs1
EXP_740-CV_20.2195080.2581050.805388NB_EXP_740_CV_2_448_UNFREEZE_P1_rs1
EXP_740-CV_30.2515550.2374650.822387NB_EXP_740_CV_3_448_UNFREEZE_P1_rs1
EXP_740-CV_40.2358830.2428340.819575NB_EXP_740_CV_4_448_UNFREEZE_P1_rs1
CV SCORE:        0.823
LB SCORE:        0.821
SUBMISSION FLN:  XP_740_448_rs(version 53/53)

EXP_765 (LB: 0.816: PB: 0.927)

Exactly like EXP_740, except training is done in 2 phases with graudela increasing image sizes - 224, 380 with the model EfficientNet-B5. I have used Lookahead with Radam as optimizers. See Notebooks for more details

Set up for all CV experimetns:

IMG SIZE 224

MODEL:           EfficientNet-B4
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              128
SZ:              224
VALID:           StratifiedKFold split of combined data

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.01, 1.45), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(20, 1e-3,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF
Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_740-CV_00.2845350.3491840.754262NB_EXP_765_CV_0_UNFREEZE_P1
EXP_740-CV_10.2768630.3507270.757114NB_EXP_765_CV_1_UNFREEZE_P1
EXP_740-CV_20.2790660.3619140.745415NB_EXP_765_CV_2_UNFREEZE_P1
EXP_740-CV_30.2710240.3322450.777068NB_EXP_765_CV_3_UNFREEZE_P1
EXP_740-CV_40.2826130.3512420.756870NB_EXP_765_CV_4_UNFREEZE_P1

IMG SIZE 380

MODEL:           EfficientNet-B4
NUM_CLASSES:     1 (5 classes but I am treatign this as a regression problem)
BS:              380
SZ:              64
VALID:           StratifiedKFold split of combined data

TFMS:            [flip(p=0.5), 
                 flip_vert(True), 
                 max_rotate(360), 
                 max_lighting(0.1),
                 p_lighting(0.5), 
                 zoom_crop(scale=(1.01, 1.35), do_rand=True))]
                 
NORMALIZE:       IMAGENET
TRAINING:        fit_one_cycle(5, 1e-3,   wd=1e-2, div_factor=25, pct_start=0.3)-UNF
Notebook NameTrain LossValid LossQuadratic KappaWeights
EXP_740-CV_00.2093590.2504110.823727NB_EXP_765_CV_0_380_UNFREEZE_P1
EXP_740-CV_10.2193780.2443170.827123NB_EXP_765_CV_1_380_UNFREEZE_P1
EXP_740-CV_20.2138980.2567960.822892NB_EXP_765_CV_2_380_UNFREEZE_P1
EXP_740-CV_30.2138080.2359580.841296NB_EXP_765_CV_3_380_UNFREEZE_P1
EXP_740-CV_40.2283760.2404360.837558NB_EXP_765_CV_4_380_UNFREEZE_P1
CV SCORE:        0.831
LB SCORE:        0.816
SUBMISSION FLN:  EXP_740(version 32/32)