COVID-19 Detection from Chest X-Ray using CNN-part 2

Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 222, 222, 32) 896
_________________________________________________________________
conv2d_1 (Conv2D) (None, 220, 220, 64) 18496
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 110, 110, 64) 0
_________________________________________________________________
dropout (Dropout) (None, 110, 110, 64) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 108, 108, 64) 36928
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 54, 54, 64) 0
_________________________________________________________________
dropout_1 (Dropout) (None, 54, 54, 64) 0
_________________________________________________________________
conv2d_3 (Conv2D) (None, 52, 52, 128) 73856
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 26, 26, 128) 0
_________________________________________________________________
dropout_2 (Dropout) (None, 26, 26, 128) 0
_________________________________________________________________
flatten (Flatten) (None, 86528) 0
_________________________________________________________________
dense (Dense) (None, 64) 5537856
_________________________________________________________________
dropout_3 (Dropout) (None, 64) 0
_________________________________________________________________
dense_1 (Dense) (None, 1) 65
=================================================================
Total params: 5,668,097
Trainable params: 5,668,097
Non-trainable params: 0
_________________________________________________________________
train_datagen = image.ImageDataGenerator(
rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True,
)
test_dataset = image.ImageDataGenerator(rescale=1./255)train_generator = train_datagen.flow_from_directory(
'CovidDataset/Train',
target_size = (224,224),
batch_size = 32,
class_mode = 'binary')
Epoch 1/10
6/6 [==============================] - 9s 2s/step - loss: 0.6833 - accuracy: 0.6146 - val_loss: 0.6807 - val_accuracy: 0.6333
Epoch 2/10
6/6 [==============================] - 8s 1s/step - loss: 0.6296 - accuracy: 0.6510 - val_loss: 0.5913 - val_accuracy: 0.9333
Epoch 3/10
6/6 [==============================] - 8s 1s/step - loss: 0.4616 - accuracy: 0.7760 - val_loss: 0.4218 - val_accuracy: 0.9333
Epoch 4/10
6/6 [==============================] - 8s 1s/step - loss: 0.3298 - accuracy: 0.8698 - val_loss: 0.2801 - val_accuracy: 0.9667
Epoch 5/10
6/6 [==============================] - 8s 1s/step - loss: 0.3021 - accuracy: 0.8854 - val_loss: 0.1959 - val_accuracy: 0.9500
Epoch 6/10
6/6 [==============================] - 8s 1s/step - loss: 0.2848 - accuracy: 0.8698 - val_loss: 0.1728 - val_accuracy: 0.9667
Epoch 7/10
6/6 [==============================] - 8s 1s/step - loss: 0.2362 - accuracy: 0.8698 - val_loss: 0.1508 - val_accuracy: 0.9833
Epoch 8/10
6/6 [==============================] - 8s 1s/step - loss: 0.1897 - accuracy: 0.9479 - val_loss: 0.1357 - val_accuracy: 0.9667
Epoch 9/10
6/6 [==============================] - 8s 1s/step - loss: 0.1858 - accuracy: 0.9271 - val_loss: 0.1632 - val_accuracy: 1.0000
Epoch 10/10
6/6 [==============================] - 8s 1s/step - loss: 0.4694 - accuracy: 0.8385 - val_loss: 0.1054 - val_accuracy: 0.9833
model.evaluate_generator(train_generator)[0.12117815017700195, 0.9642857313156128]model.evaluate_generator(validation_generator)[0.1054450049996376, 0.9833333492279053]
y_actual=[]
y_test=[]
for i in os.listdir("./CovidDataset/Val/Normal/"):
img=image.load_img("./CovidDataset/Val/Normal/"+i,target_size=(224,224))
img=image.img_to_array(img)
img=np.expand_dims(img,axis=0)
p=model.predict_classes(img)
y_test.append(p[0,0])
y_actual.append(1)
for i in os.listdir("./CovidDataset/Val/Covid/"):
img=image.load_img("./CovidDataset/Val/Covid/"+i,target_size=(224,224))
img=image.img_to_array(img)
img=np.expand_dims(img,axis=0)
p=model.predict_classes(img)
y_test.append(p[0,0])
y_actual.append(0)
y_actual=np.array(y_actual)
y_test=np.array(y_test)
from sklearn.metrics import confusion_matrix
cm=confusion_matrix(y_actual,y_test)
import seaborn as sns
sns.heatmap(cm,cmap="plasma",annot=True)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store