# Classification and Predictions of Lung Diseases from Chest X-rays Using MobileNet V2
## 4 Methodology
### Preparation for Training the Data  
In this work, MobileNet deep neural network was used with the supervised learning algorithm. After balancing the disease samples, we used a data generator function to divide the entire dataset into three groups, i.e., training (60%), validation (20%), and testing (20%).  
We also use the sparse technique (also known as one hot encoding, to generate a column for each disease, this column will be given a \"1\" if the image in question has the discussed disease else, we affect to it a \"0\").  
In the processing steps the datasets are loading and transforming images randomly by using TensorFlow and Keras packages. The image batch size is 32 for the three stages.  
* Proposed model was trained in TensorFlow and Keras.
* First, we give inputs (size 224 \(\times\) 224) to the MobileNet V2 as a base and additionally a global average pooling (GAP) layer (2 \(\times\) 2) filter is performed for spatial data and reduce the dimension of data, and finally the Dense layer is an FC (fully connected) layer for all neurons connected to the next output nodes. For the activation function for the fully connected layer, we used the sigmoid function because of its robustness in the classification machine learning model.  
For the training model, we applied several stages by applying fine-tuning the number of epochs and the batch size:  
* At first, we trained the model for the epochs, we floor divided (floor division is a normal division operation except that it returns the largest possible integer), the total number of the train samples by their batch size. We used early stopping to avoid overfitting due to a big load of data in the step per epoch.
* In the second phase, we increased the number of epochs to 15 and divided the steps per epochs into half. To improve the accuracy, we reduced the learning rate.
* Lastly, we added 10 epochs and returned the step per epochs to the initial phase, and to minimize the overfitting, we both reduced the learning rate and early stopping and we configured the patience of the early stopping to force him to finch the 10 epochs.  
We proposed a model performing under different hyper-parameters, namely filter size, number of kernels in all input channels, number weights, and pooling. The activation function translates the input range and calculates the loss function with the help of forward propagation on the training images. Batch normalization (BN) and ReLU were applied after each convolution layer for preventing overfitting problems, while epochs were also responsible for early stopping and data augmentation techniques were implemented (ImageDataGenerator). GAP layers act as a more depth type of reducing dimensionality: \(H_{im}*W_{im}*D_{im}\), where \(H_{im}\) is height, \(W_{im}\) weight and \(D_{im}\) is Dimension. By handling all \(H*W\) average values, the global average pooling (GAP) layer decreased by a single number (1 \(\times\) 1 \(\times\)\(D\)) of each \(H*W\) feature map. The dense layer extracts the features from the convolution layer and was down-sampled by the GAP layer. In a fully connected layer (dense layer), every input node is connected to the output node.  
The Adam optimizer algorithm finds the individual learning rate in every parameter for calculating the loss by binary cross-entropy and MAE (mean absolute error). We measured the performance of the classification and prediction probability value to be between 0 and 1.