# Using Double Convolution Neural Network for Lung Cancer Stage Detection
## 3 Medical Image Classification Using Double DNN
### Defining, Training and Testing the DNN  
Once the images were ready and in binary matrix form, they were fed to the DNN and trained and tested. However, the network model had to be created so that it could be trained and tested. The creation of the network model means defining the parameters and layers of the DNN. After images were ready to be used for training (Section 3.1), we prepared the Neural Network with additional layers to create the Deep Neural Network. The inner layers are composed of one convolution layer, max pooling layer, followed by double convolution layers (two convolutions) and an additional max pooling. The first convolution layer does the initial segmentation of the images and the interconnection of the nodes. Next, we needed to reduce the size of the data with the max-pooling layer (to avoid over-fitting). The second and the third convolution was done so that we could make a more thorough  
Figure 2: Different angles of CT lung cancer images. search of the problem (the cancer) and obtain more precise information of where the cancer might be. The connection between the convolution layer and the DNN is provided by Equation (2). Equation (2) shows how the state of one isolated neuron is calculated using convolution, if there were \(q\) input connections. \[F^{H}=\sum_{i=1}^{q}W_{i}*x^{i}+b \tag{2}\]  
We can see from Equation (2) that the state of the neuron with one convolution layer is \(F^{H}\), where we have \(H\) kernel filtered images, which use filters \(W\) and a bias factor \(b\). The bias factor \(b\) can have value 0 or 1, telling the network whether to include that neuron. \(x^{i}\) is the value of the input nodes of the previous layer to the i-th node of the current layer. Equation (2) is illustrated on Figure 3.  
The calculation of the correlation between the convolution and the DNN presented in Equation (2) is further explained in Equation (3). Equation (3) is Equation (2) with the addition that the neuron is now a part of a hidden convolution layer and the output energy of the neuron \(E_{j,k}\) is calculated as:  
\[E_{j,k}=\sigma\Bigg{(}b+\sum_{i=0}^{q}\sum_{z=0}^{l}w_{i,z}*X_{ii,zz}\Bigg{)} \tag{3}\]  
where the energy output E is calculated for neuron k in layer j of the DNN where we use \(\sigma\) (sigmoid function) to calculate the fire value. Again, we used the bias factor \(b\), the input connection weights of each neuron in layer j-1 denoted as \"\(w\)\", and we convoluted that value with the input from the nodes in the previous layer, denoted as \"\(x\)\". \"\(q\)\" and \"\(l\)\" represent the size of the input matrix of shared weights of \(W\), and \"\(ii\)\" and \"\(jj\)\" are the indexes of the input activation at position (\(j+i\), \(k+z\)). The calculation of the energy output \(E_{j,k}\) is illustrated on Figure 4.  
When the DNN is trained, the bias factor can be more precisely calculated and the correlations between the nodes adjusted. What the convolution does to an image is shown in Figure 5.  
As shown in Figure 5, we further divided the image into smaller parts, where the parts overlap. This way, we could focus on (isolate) a certain part of the image and use that (smaller) image to search for a pattern. In our network, we defined the convolution parameters and the slicing window. Our convolution layer takes input of 128 \(\times\) 128 \(\times\) 1 (width \(\times\) height \(\times\) color). We used 1 for color (depth) since the image was grayscale. Furthermore, we used Rectified Linear Unit as an activation  
Figure 4: Calculation of the energy output of neuron \(k\) in layer j in a multi-layered Neural Network. Figure 3: Calculation of the state of an isolated neuron. function, which means that all negative values of activation are replaced with a value of 0. There is a tradeoff here as to how much overlapping there should be. If we increase the overlapping, we make more window images and thus more detailed search. However, by doing so, we slow down the process of learning and classifying, as the window-cutting requires more resources.