image_output_1.png
from efficientnet import EfficientNetB5

from keras.applications import DenseNet121, ResNet50, InceptionV3, Xception

from keras.layers import Dense, Dropout, GlobalAveragePooling2D, LeakyReLU

from keras.models import Model, Sequential

import os

import pandas as pd

import sys

test_df = pd.read_csv('../input/aptos2019-blindness-detection/test.csv')
test_df['id_code'] = test_df['id_code'].apply(lambda x: x + '.png')
diag_text = ['Normal', 'Mild', 'Moderate', 'Severe', 'Proliferative']
num_classes = 5

sys.path.append(os.path.abspath('../input/efficientnet/efficientnet-master/efficientnet-master/'))
from efficientnet import EfficientNetB5

from keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint, Callback
from keras.layers import Dense, Dropout, GlobalAveragePooling2D, LeakyReLU
from keras.applications import DenseNet121, ResNet50, InceptionV3, Xception
from keras.models import Model, Sequential
from keras.optimizers import Adam
def create_resnet50_model(input_shape, n_out):
    base_model = ResNet50(weights=None, include_top=False, input_shape=input_shape)
    base_model.load_weights('../input/keras-pretrained-models/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5')
    model = Sequential()
    model.add(base_model)
    model.add(GlobalAveragePooling2D())
    model.add(Dropout(0.5))
    model.add(Dense(2048, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(n_out, activation='sigmoid'))
    return model
def create_inception_v3_model(input_shape, n_out):
    base_model = InceptionV3(weights=None, include_top=False, input_shape=input_shape)
    base_model.load_weights('../input/keras-pretrained-models/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5')
    model = Sequential()
    model.add(base_model)
    model.add(GlobalAveragePooling2D())
    model.add(Dropout(0.5))
    model.add(Dense(2048, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(n_out, activation='sigmoid'))
    return model
def create_xception_model(input_shape, n_out):
    base_model = Xception(weights=None, include_top=False, input_shape=input_shape)
    base_model.load_weights('../input/keras-pretrained-models/xception_weights_tf_dim_ordering_tf_kernels_notop.h5')
    model = Sequential()
    model.add(base_model)
    model.add(GlobalAveragePooling2D())
    model.add(Dropout(0.5))
    model.add(Dense(2048, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(n_out, activation='sigmoid'))
    return model
def create_densenet121_model(input_shape, n_out):
    base_model = DenseNet121(weights=None, include_top=False, input_shape=input_shape)
    base_model.load_weights('../input/densenet-keras/DenseNet-BC-121-32-no-top.h5')
    model = Sequential()
    model.add(base_model)
    model.add(GlobalAveragePooling2D())
    model.add(Dropout(0.5))
    model.add(Dense(2048, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(n_out, activation='sigmoid'))
    return model
def create_effnetB5_model(input_shape, n_out):
    base_model = EfficientNetB5(weights=sys.path.append(os.path.abspath('../input/efficientnet-keras-weights-b0b5/efficientnet-b5_imagenet_1000_notop.h5')), include_top=False, input_shape=input_shape)
    model = Sequential()
    model.add(base_model)
    model.add(Dropout(0.25))
    model.add(Dense(1024))
    model.add(LeakyReLU())
    model.add(GlobalAveragePooling2D())
    model.add(Dropout(0.5))
    model.add(Dense(n_out, activation='sigmoid'))
    return model

IMAGE_HEIGHT = 340
IMAGE_WIDTH = 340
model = create_effnetB5_model(input_shape=(IMAGE_HEIGHT, IMAGE_WIDTH, 3), n_out=num_classes)
model.summary()

PRETRAINED_MODEL = '../input/efficientnetb5-blindness-detector/blindness_detector_bestqwk.h5'
if os.path.exists(PRETRAINED_MODEL):
    print('Restoring model from ' + PRETRAINED_MODEL)
    model.load_weights(PRETRAINED_MODEL)
else:
    print('No pretrained model found. Using fresh model.')