Corona Detection from X-ray using CNN

corona detection from xray using cnn

Corona virus disease (COVID-19) is an infectious disease caused by a newly discovered corona virus. 465,915 Confirmed cases & 21,031 Confirmed deaths (Updated : 27 March 2020 ) , corona has spread in m ore than 200 countries.  

Corona virus caused cluster of pneumonia cases, in late 2019,  majority suffering from only mild, cold-like symptoms.  According to researchers, the lining of the respiratory tree becomes injured, causing inflammation. This in turn irritates the nerves in the lining of the airway. Just a speck of dust can stimulate a cough. If the condition becomes intense, lungs that become filled with inflammatory material become unable to get enough oxygen to the bloodstream, reducing the body’s ability to take on oxygen and get rid of carbon dioxide which finally lead to death.

The white patches on the CT scan (X-Ray) indicate pneumonia, as the spaces which are normally filled by air are being filled with something else instead.

STEPS TO BUILD DETECTION MODEL

 

  • X-ray images for patients who have tested positive for COVID-19 are collected
  • “normal” (i.e., not infected) X-ray images from healthy patients are collected
  • Divide the dataset in test, train and validate dataset ( click here for dataset)
  • Train a CNN to automatically detect COVID-19 in X-ray images via the dataset we created
  • Evaluate the results

The CNN consist layer of neurons and it is optimized for two-dimensional pattern recognition. CNN has three types of layer namely convolutional layer, pooling layer and fully connected layer. Our network consists of 11 layers excluding the input layer. The input layer takes in a RGB color image where each color channel is processed separately.

The first 6 layers of convolution network are convolution layer. First 2 convolution layer applies 16 of 3*3 filters to an image in the layer. The other two layer applies 32 of 3*3 filters to an image. And the last 2 layers of convolution applies 64 of 3*3 filters to an image. The nonlinear transformation sublayer employs the ReLU activation function. The max pooling sublayer applies a 2*2 filter to the image which results in reducing the image size to its half. At this point, convolution network extracts 64 features, each represented by a 32*32 array for each color channel.

 The eighth layer is the flatten layer. The flatten layer transforms a multidimensional array into one-dimensional array by simply concatenating the entries of the multidimensional array together. The output of this flatten layer is a one-dimensional array of size 4800. The ninth layer is the fully connected ANN with the ReLU activation function that maps 4800 input values to the 64 output values. The tenth layer is the dropout layer. 50% of the input values coming to the layer are dropped to zero to reduce the problem of overfitting. The eleventh and the final layer is a fully connected ANN with the sigmoid activation function that maps 64 input values to 2 class labels.

First, we train convolution network using the data in training set to find appropriated filters’ weights in the three convolutional sublayers and the weights that yield minimum error in the two fully connected layers. Next, we evaluate convolution network using the data in the validation set to obtain validation error and cross-entropy loss. We repeat the training of convolution network in this same procedure until we complete 10 epochs. Last, we evaluate the performance of convolution network using data in the test set.

30 Comments on “Corona Detection from X-ray using CNN”

  1. ValueError Traceback (most recent call last)
    in
    1 import tensorflow as tf
    —-> 2 model = tf.keras.models.load_model(“D:/corona-detection-model-master/mymodel.h5”)
    3 model.compile(loss=’binary_crossentropy’,
    4 optimizer=’rmsprop’,
    5 metrics=[‘accuracy’])

    ~\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\models.py in load_model(filepath, custom_objects, compile)
    244 raise ValueError(‘No model found in config file.’)
    245 model_config = json.loads(model_config.decode(‘utf-8’))
    –> 246 model = model_from_config(model_config, custom_objects=custom_objects)
    247
    248 # set weights

    ~\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\models.py in model_from_config(config, custom_objects)
    322 ‘Maybe you meant to use ‘
    323 ‘`Sequential.from_config(config)`?’)
    –> 324 return layer_module.deserialize(config, custom_objects=custom_objects)
    325
    326

    ~\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\layers\serialization.py in deserialize(config, custom_objects)
    61 module_objects=globs,
    62 custom_objects=custom_objects,
    —> 63 printable_module_name=’layer’)

    ~\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    162 custom_objects=dict(
    163 list(_GLOBAL_CUSTOM_OBJECTS.items()) +
    –> 164 list(custom_objects.items())))
    165 with CustomObjectScope(custom_objects):
    166 return cls.from_config(config[‘config’])

    ~\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\models.py in from_config(cls, config, custom_objects)
    1331 model = cls()
    1332 for conf in config:
    -> 1333 layer = layer_module.deserialize(conf, custom_objects=custom_objects)
    1334 model.add(layer)
    1335 return model

    ~\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\layers\serialization.py in deserialize(config, custom_objects)
    61 module_objects=globs,
    62 custom_objects=custom_objects,
    —> 63 printable_module_name=’layer’)

    ~\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\_impl\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    182 if fn is None:
    183 raise ValueError(‘Unknown ‘ + printable_module_name + ‘:’ +
    –> 184 function_name)
    185 return fn
    186 else:

    ValueError: Unknown layer:name

    *** Getting This error*** please tell me how to resolve this

  2. So I did train a cnn model which is giving great results on the test and validation data. But if I use this model on x-rays outside the given data, results are pretty disappointing.

  3. Hi,
    I am going to use the dataset provided for college purposes if possible. I will like to know the source of it, to check the license and give the credit.

Leave a Reply

Your email address will not be published. Required fields are marked *