text_html_output_1.png
from efficientnet import EfficientNetB5

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

from keras.models import Model, Sequential

import cv2

import numpy as np

import os

import pandas as pd

import sys

import numpy as np
import pandas as pd
import cv2
import os
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.layers import Dense, Dropout, GlobalAveragePooling2D, LeakyReLU
from keras.models import Model, Sequential
def create_effnetB5_model(input_shape, n_out):
    base_model = EfficientNetB5(weights=None, 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
PRETRAINED_MODEL = '../input/efficientnetb5-blindness-detector/blindness_detector_best_qwk.h5'
model = create_effnetB5_model(input_shape=(IMAGE_HEIGHT, IMAGE_WIDTH, 3), n_out=num_classes)
model.load_weights(PRETRAINED_MODEL)
model.summary()

from tqdm import tqdm_notebook as tqdm
submit = pd.read_csv('../input/aptos2019-blindness-detection/sample_submission.csv')
predicted = []
print('Making predictions...')
for i, name in tqdm(enumerate(submit['id_code'])):
    path = os.path.join('../input/aptos2019-blindness-detection/test_images/', name + '.png')
    image = cv2.imread(path)
    image = cv2.resize(image, (IMAGE_HEIGHT, IMAGE_WIDTH))
    X = np.array(image[np.newaxis] / 255)
    raw_prediction = model.predict(X) > 0.5
    prediction = raw_prediction.astype(int).sum(axis=1) - 1
    predicted.append(prediction[0])