text_plain_output_1.png
from keras.layers import Dense, Dropout, Flatten, Input, Conv2D, MaxPooling2D, BatchNormalization, Activation, UpSampling2D, GlobalAveragePooling2D

from keras.models import Sequential, Model

from keras.preprocessing.image import ImageDataGenerator

from keras.preprocessing.image import load_img, img_to_array

from tensorflow.keras.applications import EfficientNetB0

from tensorflow.keras.metrics import AUC

import gc

import glob

import numpy as np

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train_data_dir = '../input/1056lab-covid19-chest-xray-recognit/train'
generator = ImageDataGenerator(width_shift_range=0.3, height_shift_range=0.3, horizontal_flip=True, validation_split=0.2)

train_generator = generator.flow_from_directory(train_data_dir, target_size=(224, 224), color_mode='rgb', batch_size=64, class_mode='categorical', shuffle=True)

from tensorflow.keras.applications import EfficientNetB0
efnb0 = EfficientNetB0(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
model = Sequential()
model.add(efnb0)
model.add(GlobalAveragePooling2D())
model.add(Dropout(0.2))
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(4, activation='sigmoid'))
for layer in efnb0.layers:
    layer.trainable = False
model.summary()

from tensorflow.keras.metrics import AUC
auc = AUC()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy', auc])

hist = model.fit_generator(train_generator, steps_per_epoch=231, epochs=50)

import glob
from keras.preprocessing.image import load_img, img_to_array
import gc
img_list = glob.glob('/kaggle/input/1056lab-covid19-chest-xray-recognit/test/*.png')
img_list.sort()
y_pred = []
for img_sublist in np.array_split(img_list, 10):
    img_array_list = []
    for path in img_sublist:
        img = load_img(path, color_mode='rgb', target_size=(224, 224, 3))
        img_array = img_to_array(img)
        img_array_list.append(img_array)
    X_test = np.array(img_array_list)
    y_test = model.predict(X_test)[:, 0]
    y_pred = np.concatenate([y_pred, y_test])
    del img_array_list
    del X_test
    gc.collect()

submit_df = pd.read_csv('/kaggle/input/1056lab-covid19-chest-xray-recognit/sampleSubmission.csv', index_col=0)
submit_df['COVID'] = y_pred
submit_df.to_csv('submission.csv')
submit_df