Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views93 pages

Brain Tumor Downconvolution

cnn based cancer detection

Uploaded by

Shardul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views93 pages

Brain Tumor Downconvolution

cnn based cancer detection

Uploaded by

Shardul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 93

5/25/2021 brainTumorDownconvolution

Segmentation of brain tumor images with unet neural


network
In this problem we are given 4 MRI scans per sample of brains of patients suffering from brain tumor. The
tumor section marked in each sample by 3 experts in the field are also given. The given samples are divided
as 28 training samples and 4 validation samples.

In [1]:

import numpy as np
import nibabel as nb

Using the nibabel library we wil convert the .ngz images to numpy arrays. Using numpy reshape we will
reshape the images in required dimensions for input and output for the neural network.

In [2]:

def doubledigit(x):
if x<10:
return ("0"+str(x))
return str(x)
def genratedataset():
inputlist=[]
outputlist=[]
filename="C:/Users/Shardul/Desktop/training_data_v2/brain-tumor/training/case"
for i in range(28*3):
inputlist.append(np.asarray(nb.load(filename+doubledigit(int(i/3+1))+"/image.ni
i.gz").get_fdata()))
outputlist.append(np.asarray(nb.load(filename+doubledigit(int(i/3+1))+"/task"+
"01"+"_seg"+doubledigit(i%3+1)+".nii.gz").get_fdata()))
return(np.asarray(inputlist),np.asarray(outputlist).reshape(28*3,240,240,1))
def genratevalidationdataset():
inputlist=[]
outputlist=[]
filename="C:/Users/Shardul/Desktop/Validation_data_v2/brain-tumor/Validation/case"
for i in range(28*3,32*3):
inputlist.append(np.asarray(nb.load(filename+doubledigit(int(i/3+1))+"/image.ni
i.gz").get_fdata()))
outputlist.append(np.asarray(nb.load(filename+doubledigit(int(i/3+1))+"/task"+
"01"+"_seg"+doubledigit(i%3+1)+".nii.gz").get_fdata()))
return(np.asarray(inputlist),np.asarray(outputlist).reshape(4*3,240,240,1))
i,o=genratedataset()
vi,vo=genratevalidationdataset()

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 1/93
5/25/2021 brainTumorDownconvolution

Now we will build the unet neural network. The U-net is a fully convolutional neural network. It consists of a
contracting path and an expansive path. The contracting path is a neural network that consists of repeated
convolutions followed by a max-pooling. But in this program instead of the max-pooling layer I have used
convolutional layer with multiple strides. This method reduces training time from about 100 seconds per
epoch to 67 seconds per epoch and also gives slightly better accuracy. I found information about this type of
neural network in the paper "nnU-net for Brain Tumor Segmentation" written by Fabian Isenee, Paul F. Jager,
Peter M. FUll, Philip Vollmuth and Klaus H.Maier-Hein During the contraction feature information is is
increased while spatial information is reduced. The expansive layer combines the features and spatial
information by series of up-convolutions and skip connections with high resolution layers.

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 2/93
5/25/2021 brainTumorDownconvolution

In [3]:

import keras as k
li=k.Input((240,240,4))
l1=k.layers.Convolution2D(64,kernel_size=(3,3),padding="same",activation="relu")(li)
l2=k.layers.Convolution2D(64,kernel_size=(3,3),padding="same",strides=(2,2),activation=
"relu")(l1)
l3=k.layers.Convolution2D(64,(1,1),activation="relu")(l2)
l4=k.layers.Convolution2D(128,kernel_size=(3,3),padding="same")(l2)
l5=k.layers.Convolution2D(128,kernel_size=(3,3),strides=(2,2),padding="same")(l4)
l6=k.layers.Convolution2D(128,(1,1),activation="relu")(l5)
l7=k.layers.Convolution2D(256,kernel_size=(3,3),padding="same")(l5)
l8=k.layers.Convolution2D(256,(3,3),activation="relu",strides=(2,2),padding="same")(l7)
l9=k.layers.Convolution2D(256,(1,1),activation="relu")((l8))
l10=k.layers.Convolution2D(512,(3,3),activation="relu",padding="same")(l8)
l11=k.layers.Convolution2D(512,(3,3),activation="relu",strides=(2,2),padding="same")(l1
0)
l12=k.layers.Convolution2D(512,(1,1),activation="relu")(l11)
l13=k.layers.Convolution2D(1024,(3,3),activation="relu",padding="same")(l11)
l14=k.layers.Convolution2D(1024,(3,3),activation="relu",padding="same",strides=(3,3))(l
13)
l15=k.layers.Convolution2D(1024,(1,1),activation="relu",padding="same")(l14)
l16=k.layers.Convolution2D(2048,(3,3),activation="relu",padding="same")(l15)
l17=k.layers.Convolution2D(1024,(3,3),activation="relu",padding="same")(l16)
l18=k.layers.Add()([l17,l15])
l19=k.layers.Conv2DTranspose(1024,(3,3),activation="relu",padding="same",strides=(3,3))
(l18)
l20=k.layers.Convolution2D(512,(3,3),activation="relu",padding="same")(l19)
l21=k.layers.Add()([l12,l20])
l22=k.layers.Conv2DTranspose(256,(3,3),activation="relu",padding="same",strides=(2,2))(
l21)
l23=k.layers.Convolution2D(256,(3,3),activation="relu",padding="same")(l22)
l24=k.layers.Add()([l9,l23])
l25=k.layers.Conv2DTranspose(128,(3,3),activation="relu",padding="same",strides=(2,2))(
l24)
l26=k.layers.Convolution2D(128,(3,3),padding="same",activation="relu")(l25)
l27=k.layers.Add()([l6,l26])
l28=k.layers.Conv2DTranspose(64,(3,3),padding="same",activation="relu",strides=(2,2))(l
27)
l29=k.layers.Convolution2D(64,(3,3),padding="same",activation="relu")(l28)
l30=k.layers.Add()([l3,l29])
l31=k.layers.Conv2DTranspose(64,(3,3),padding="same",activation="relu",strides=(2,2))(l
30)
l32=k.layers.Convolution2D(1,(3,3),activation="sigmoid",padding="same")(l31)
m=k.Model( li,l32)
m.compile(optimizer="adam",loss="binary_crossentropy")
m.summary()
m.fit(np.asarray(i),np.asarray(o),epochs=150,validation_data=(vi,vo))

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 3/93
5/25/2021 brainTumorDownconvolution

Using TensorFlow backend.

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 4/93
5/25/2021 brainTumorDownconvolution

Model: "model_1"
__________________________________________________________________________
________________________
Layer (type) Output Shape Param # Connected
to
==========================================================================
========================
input_1 (InputLayer) (None, 240, 240, 4) 0

__________________________________________________________________________
________________________
conv2d_1 (Conv2D) (None, 240, 240, 64) 2368 input_1
[0][0]
__________________________________________________________________________
________________________
conv2d_2 (Conv2D) (None, 120, 120, 64) 36928 conv2d_1
[0][0]
__________________________________________________________________________
________________________
conv2d_4 (Conv2D) (None, 120, 120, 128 73856 conv2d_2
[0][0]
__________________________________________________________________________
________________________
conv2d_5 (Conv2D) (None, 60, 60, 128) 147584 conv2d_4
[0][0]
__________________________________________________________________________
________________________
conv2d_7 (Conv2D) (None, 60, 60, 256) 295168 conv2d_5
[0][0]
__________________________________________________________________________
________________________
conv2d_8 (Conv2D) (None, 30, 30, 256) 590080 conv2d_7
[0][0]
__________________________________________________________________________
________________________
conv2d_10 (Conv2D) (None, 30, 30, 512) 1180160 conv2d_8
[0][0]
__________________________________________________________________________
________________________
conv2d_11 (Conv2D) (None, 15, 15, 512) 2359808 conv2d_10
[0][0]
__________________________________________________________________________
________________________
conv2d_13 (Conv2D) (None, 15, 15, 1024) 4719616 conv2d_11
[0][0]
__________________________________________________________________________
________________________
conv2d_14 (Conv2D) (None, 5, 5, 1024) 9438208 conv2d_13
[0][0]
__________________________________________________________________________
________________________
conv2d_15 (Conv2D) (None, 5, 5, 1024) 1049600 conv2d_14
[0][0]
__________________________________________________________________________
________________________
conv2d_16 (Conv2D) (None, 5, 5, 2048) 18876416 conv2d_15
[0][0]
__________________________________________________________________________
________________________
conv2d_17 (Conv2D) (None, 5, 5, 1024) 18875392 conv2d_16
[0][0]
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 5/93
5/25/2021 brainTumorDownconvolution

__________________________________________________________________________
________________________
add_1 (Add) (None, 5, 5, 1024) 0 conv2d_17
[0][0]
conv2d_15
[0][0]
__________________________________________________________________________
________________________
conv2d_transpose_1 (Conv2DTrans (None, 15, 15, 1024) 9438208 add_1[0]
[0]
__________________________________________________________________________
________________________
conv2d_12 (Conv2D) (None, 15, 15, 512) 262656 conv2d_11
[0][0]
__________________________________________________________________________
________________________
conv2d_18 (Conv2D) (None, 15, 15, 512) 4719104 conv2d_tr
anspose_1[0][0]
__________________________________________________________________________
________________________
add_2 (Add) (None, 15, 15, 512) 0 conv2d_12
[0][0]
conv2d_18
[0][0]
__________________________________________________________________________
________________________
conv2d_transpose_2 (Conv2DTrans (None, 30, 30, 256) 1179904 add_2[0]
[0]
__________________________________________________________________________
________________________
conv2d_9 (Conv2D) (None, 30, 30, 256) 65792 conv2d_8
[0][0]
__________________________________________________________________________
________________________
conv2d_19 (Conv2D) (None, 30, 30, 256) 590080 conv2d_tr
anspose_2[0][0]
__________________________________________________________________________
________________________
add_3 (Add) (None, 30, 30, 256) 0 conv2d_9
[0][0]
conv2d_19
[0][0]
__________________________________________________________________________
________________________
conv2d_transpose_3 (Conv2DTrans (None, 60, 60, 128) 295040 add_3[0]
[0]
__________________________________________________________________________
________________________
conv2d_6 (Conv2D) (None, 60, 60, 128) 16512 conv2d_5
[0][0]
__________________________________________________________________________
________________________
conv2d_20 (Conv2D) (None, 60, 60, 128) 147584 conv2d_tr
anspose_3[0][0]
__________________________________________________________________________
________________________
add_4 (Add) (None, 60, 60, 128) 0 conv2d_6
[0][0]
conv2d_20
[0][0]
__________________________________________________________________________
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 6/93
5/25/2021 brainTumorDownconvolution

________________________
conv2d_transpose_4 (Conv2DTrans (None, 120, 120, 64) 73792 add_4[0]
[0]
__________________________________________________________________________
________________________
conv2d_3 (Conv2D) (None, 120, 120, 64) 4160 conv2d_2
[0][0]
__________________________________________________________________________
________________________
conv2d_21 (Conv2D) (None, 120, 120, 64) 36928 conv2d_tr
anspose_4[0][0]
__________________________________________________________________________
________________________
add_5 (Add) (None, 120, 120, 64) 0 conv2d_3
[0][0]
conv2d_21
[0][0]
__________________________________________________________________________
________________________
conv2d_transpose_5 (Conv2DTrans (None, 240, 240, 64) 36928 add_5[0]
[0]
__________________________________________________________________________
________________________
conv2d_22 (Conv2D) (None, 240, 240, 1) 577 conv2d_tr
anspose_5[0][0]
==========================================================================
========================
Total params: 74,512,449
Trainable params: 74,512,449
Non-trainable params: 0
__________________________________________________________________________
________________________
Train on 84 samples, validate on 12 samples
Epoch 1/150
84/84 [==============================] - 69s 819ms/step - loss: 2.9988 - v
al_loss: 1.3109
Epoch 2/150
84/84 [==============================] - 67s 792ms/step - loss: 1.0088 - v
al_loss: 0.8200
Epoch 3/150
84/84 [==============================] - 65s 779ms/step - loss: 0.6797 - v
al_loss: 0.5900
Epoch 4/150
84/84 [==============================] - 66s 784ms/step - loss: 0.5777 - v
al_loss: 0.5360
Epoch 5/150
84/84 [==============================] - 65s 778ms/step - loss: 0.5546 - v
al_loss: 0.5151
Epoch 6/150
84/84 [==============================] - 65s 775ms/step - loss: 0.4623 - v
al_loss: 0.6627
Epoch 7/150
84/84 [==============================] - 65s 772ms/step - loss: 0.5170 - v
al_loss: 0.4960
Epoch 8/150
84/84 [==============================] - 64s 768ms/step - loss: 0.5260 - v
al_loss: 0.4949
Epoch 9/150
84/84 [==============================] - 65s 769ms/step - loss: 0.4948 - v
al_loss: 0.4400
Epoch 10/150
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 7/93
5/25/2021 brainTumorDownconvolution

84/84 [==============================] - 64s 765ms/step - loss: 0.4450 - v


al_loss: 0.1776
Epoch 11/150
84/84 [==============================] - 64s 763ms/step - loss: 0.5280 - v
al_loss: 0.3643
Epoch 12/150
84/84 [==============================] - 64s 764ms/step - loss: 0.4332 - v
al_loss: 0.4263
Epoch 13/150
84/84 [==============================] - 64s 765ms/step - loss: 0.4326 - v
al_loss: 0.4071
Epoch 14/150
84/84 [==============================] - 64s 763ms/step - loss: 0.3891 - v
al_loss: 0.3307
Epoch 15/150
84/84 [==============================] - 64s 766ms/step - loss: 0.2650 - v
al_loss: 0.0807
Epoch 16/150
84/84 [==============================] - 64s 768ms/step - loss: 0.0924 - v
al_loss: 0.0561
Epoch 17/150
84/84 [==============================] - 65s 772ms/step - loss: 0.0841 - v
al_loss: 0.0895
Epoch 18/150
84/84 [==============================] - 65s 772ms/step - loss: 0.0761 - v
al_loss: 0.0467
Epoch 19/150
84/84 [==============================] - 65s 768ms/step - loss: 0.0655 - v
al_loss: 0.0487
Epoch 20/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0595 - v
al_loss: 0.0496
Epoch 21/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0581 - v
al_loss: 0.0443
Epoch 22/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0560 - v
al_loss: 0.0453
Epoch 23/150
84/84 [==============================] - 65s 768ms/step - loss: 0.0550 - v
al_loss: 0.0462
Epoch 24/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0537 - v
al_loss: 0.0395
Epoch 25/150
84/84 [==============================] - 64s 764ms/step - loss: 0.0527 - v
al_loss: 0.0396
Epoch 26/150
84/84 [==============================] - 65s 769ms/step - loss: 0.0516 - v
al_loss: 0.0465
Epoch 27/150
84/84 [==============================] - 64s 766ms/step - loss: 0.0547 - v
al_loss: 0.0465
Epoch 28/150
84/84 [==============================] - 65s 768ms/step - loss: 0.0527 - v
al_loss: 0.0388
Epoch 29/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0505 - v
al_loss: 0.0425
Epoch 30/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0487 - v
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 8/93
5/25/2021 brainTumorDownconvolution

al_loss: 0.0361
Epoch 31/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0475 - v
al_loss: 0.0365
Epoch 32/150
84/84 [==============================] - 64s 766ms/step - loss: 0.0506 - v
al_loss: 0.0354
Epoch 33/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0503 - v
al_loss: 0.0401
Epoch 34/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0533 - v
al_loss: 0.0508
Epoch 35/150
84/84 [==============================] - 64s 766ms/step - loss: 0.0507 - v
al_loss: 0.0395
Epoch 36/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0461 - v
al_loss: 0.0330
Epoch 37/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0400 - v
al_loss: 0.0274
Epoch 38/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0339 - v
al_loss: 0.0295
Epoch 39/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0338 - v
al_loss: 0.0229
Epoch 40/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0313 - v
al_loss: 0.0227
Epoch 41/150
84/84 [==============================] - 64s 765ms/step - loss: 0.0277 - v
al_loss: 0.0223
Epoch 42/150
84/84 [==============================] - 64s 767ms/step - loss: 0.0248 - v
al_loss: 0.0208
Epoch 43/150
84/84 [==============================] - 75s 896ms/step - loss: 0.0240 - v
al_loss: 0.0187
Epoch 44/150
84/84 [==============================] - 85s 1s/step - loss: 0.0218 - val_
loss: 0.0177
Epoch 45/150
84/84 [==============================] - 85s 1s/step - loss: 0.0220 - val_
loss: 0.0188
Epoch 46/150
84/84 [==============================] - 87s 1s/step - loss: 0.0312 - val_
loss: 0.0243
Epoch 47/150
84/84 [==============================] - 86s 1s/step - loss: 0.0273 - val_
loss: 0.0226
Epoch 48/150
84/84 [==============================] - 86s 1s/step - loss: 0.0291 - val_
loss: 0.0290
Epoch 49/150
84/84 [==============================] - 87s 1s/step - loss: 0.0282 - val_
loss: 0.0222
Epoch 50/150
84/84 [==============================] - 169s 2s/step - loss: 0.0254 - val
_loss: 0.0205
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 9/93
5/25/2021 brainTumorDownconvolution

Epoch 51/150
84/84 [==============================] - 9408s 112s/step - loss: 0.0220 -
val_loss: 0.0187
Epoch 52/150
84/84 [==============================] - 89s 1s/step - loss: 0.0195 - val_
loss: 0.0184
Epoch 53/150
84/84 [==============================] - 90s 1s/step - loss: 0.0187 - val_
loss: 0.0178
Epoch 54/150
84/84 [==============================] - 104s 1s/step - loss: 0.0179 - val
_loss: 0.0196
Epoch 55/150
84/84 [==============================] - 89s 1s/step - loss: 0.0176 - val_
loss: 0.0178
Epoch 56/150
84/84 [==============================] - 76s 907ms/step - loss: 0.0166 - v
al_loss: 0.0183
Epoch 57/150
84/84 [==============================] - 71s 851ms/step - loss: 0.0160 - v
al_loss: 0.0181
Epoch 58/150
84/84 [==============================] - 71s 843ms/step - loss: 0.0158 - v
al_loss: 0.0189
Epoch 59/150
84/84 [==============================] - 70s 829ms/step - loss: 0.0156 - v
al_loss: 0.0184
Epoch 60/150
84/84 [==============================] - 73s 873ms/step - loss: 0.0153 - v
al_loss: 0.0186
Epoch 61/150
84/84 [==============================] - 73s 874ms/step - loss: 0.0151 - v
al_loss: 0.0181
Epoch 62/150
84/84 [==============================] - 72s 859ms/step - loss: 0.0154 - v
al_loss: 0.0179
Epoch 63/150
84/84 [==============================] - 76s 899ms/step - loss: 0.0158 - v
al_loss: 0.0225
Epoch 64/150
84/84 [==============================] - 74s 884ms/step - loss: 0.0158 - v
al_loss: 0.0176
Epoch 65/150
84/84 [==============================] - 74s 882ms/step - loss: 0.0157 - v
al_loss: 0.0190
Epoch 66/150
84/84 [==============================] - 73s 870ms/step - loss: 0.0149 - v
al_loss: 0.0189
Epoch 67/150
84/84 [==============================] - 73s 864ms/step - loss: 0.0155 - v
al_loss: 0.0176
Epoch 68/150
84/84 [==============================] - 74s 879ms/step - loss: 0.0174 - v
al_loss: 0.0219
Epoch 69/150
84/84 [==============================] - 73s 869ms/step - loss: 0.0156 - v
al_loss: 0.0177
Epoch 70/150
84/84 [==============================] - 74s 877ms/step - loss: 0.0150 - v
al_loss: 0.0213
Epoch 71/150
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 10/93
5/25/2021 brainTumorDownconvolution

84/84 [==============================] - 73s 873ms/step - loss: 0.0147 - v


al_loss: 0.0182
Epoch 72/150
84/84 [==============================] - 73s 871ms/step - loss: 0.0156 - v
al_loss: 0.0239
Epoch 73/150
84/84 [==============================] - 75s 890ms/step - loss: 0.0148 - v
al_loss: 0.0186
Epoch 74/150
84/84 [==============================] - 75s 891ms/step - loss: 0.0148 - v
al_loss: 0.0231
Epoch 75/150
84/84 [==============================] - 74s 882ms/step - loss: 0.0139 - v
al_loss: 0.0185
Epoch 76/150
84/84 [==============================] - 74s 876ms/step - loss: 0.0141 - v
al_loss: 0.0271
Epoch 77/150
84/84 [==============================] - 72s 856ms/step - loss: 0.0144 - v
al_loss: 0.0189
Epoch 78/150
84/84 [==============================] - 66s 784ms/step - loss: 0.0152 - v
al_loss: 0.0290
Epoch 79/150
84/84 [==============================] - 66s 783ms/step - loss: 0.0151 - v
al_loss: 0.0182
Epoch 80/150
84/84 [==============================] - 66s 791ms/step - loss: 0.0149 - v
al_loss: 0.0244
Epoch 81/150
84/84 [==============================] - 66s 789ms/step - loss: 0.0139 - v
al_loss: 0.0191
Epoch 82/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0136 - v
al_loss: 0.0231
Epoch 83/150
84/84 [==============================] - 66s 785ms/step - loss: 0.0129 - v
al_loss: 0.0215
Epoch 84/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0125 - v
al_loss: 0.0222
Epoch 85/150
84/84 [==============================] - 66s 784ms/step - loss: 0.0126 - v
al_loss: 0.0211
Epoch 86/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0122 - v
al_loss: 0.0239
Epoch 87/150
84/84 [==============================] - 65s 780ms/step - loss: 0.0119 - v
al_loss: 0.0219
Epoch 88/150
84/84 [==============================] - 66s 787ms/step - loss: 0.0117 - v
al_loss: 0.0227
Epoch 89/150
84/84 [==============================] - 66s 783ms/step - loss: 0.0116 - v
al_loss: 0.0244
Epoch 90/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0115 - v
al_loss: 0.0222
Epoch 91/150
84/84 [==============================] - 65s 778ms/step - loss: 0.0115 - v
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 11/93
5/25/2021 brainTumorDownconvolution

al_loss: 0.0227
Epoch 92/150
84/84 [==============================] - 65s 780ms/step - loss: 0.0112 - v
al_loss: 0.0256
Epoch 93/150
84/84 [==============================] - 66s 789ms/step - loss: 0.0110 - v
al_loss: 0.0224
Epoch 94/150
84/84 [==============================] - 68s 805ms/step - loss: 0.0114 - v
al_loss: 0.0286
Epoch 95/150
84/84 [==============================] - 66s 782ms/step - loss: 0.0118 - v
al_loss: 0.0231
Epoch 96/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0121 - v
al_loss: 0.0215
Epoch 97/150
84/84 [==============================] - 66s 788ms/step - loss: 0.0126 - v
al_loss: 0.0262
Epoch 98/150
84/84 [==============================] - 65s 780ms/step - loss: 0.0119 - v
al_loss: 0.0245
Epoch 99/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0121 - v
al_loss: 0.0200
Epoch 100/150
84/84 [==============================] - 66s 782ms/step - loss: 0.0118 - v
al_loss: 0.0213
Epoch 101/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0115 - v
al_loss: 0.0235
Epoch 102/150
84/84 [==============================] - 66s 782ms/step - loss: 0.0108 - v
al_loss: 0.0244
Epoch 103/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0105 - v
al_loss: 0.0199
Epoch 104/150
84/84 [==============================] - 66s 790ms/step - loss: 0.0108 - v
al_loss: 0.0204
Epoch 105/150
84/84 [==============================] - 66s 782ms/step - loss: 0.0104 - v
al_loss: 0.0281
Epoch 106/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0105 - v
al_loss: 0.0222
Epoch 107/150
84/84 [==============================] - 66s 782ms/step - loss: 0.0105 - v
al_loss: 0.0212
Epoch 108/150
84/84 [==============================] - 65s 777ms/step - loss: 0.0101 - v
al_loss: 0.0287
Epoch 109/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0107 - v
al_loss: 0.0226
Epoch 110/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0109 - v
al_loss: 0.0223
Epoch 111/150
84/84 [==============================] - 66s 784ms/step - loss: 0.0113 - v
al_loss: 0.0279
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 12/93
5/25/2021 brainTumorDownconvolution

Epoch 112/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0098 - v
al_loss: 0.0231
Epoch 113/150
84/84 [==============================] - 66s 784ms/step - loss: 0.0099 - v
al_loss: 0.0253
Epoch 114/150
84/84 [==============================] - 65s 777ms/step - loss: 0.0099 - v
al_loss: 0.0257
Epoch 115/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0099 - v
al_loss: 0.0212
Epoch 116/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0102 - v
al_loss: 0.0339
Epoch 117/150
84/84 [==============================] - 66s 790ms/step - loss: 0.0103 - v
al_loss: 0.0216
Epoch 118/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0107 - v
al_loss: 0.0261
Epoch 119/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0099 - v
al_loss: 0.0258
Epoch 120/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0094 - v
al_loss: 0.0263
Epoch 121/150
84/84 [==============================] - 65s 778ms/step - loss: 0.0092 - v
al_loss: 0.0247
Epoch 122/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0093 - v
al_loss: 0.0328
Epoch 123/150
84/84 [==============================] - 65s 777ms/step - loss: 0.0099 - v
al_loss: 0.0245
Epoch 124/150
84/84 [==============================] - 66s 782ms/step - loss: 0.0093 - v
al_loss: 0.0238
Epoch 125/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0094 - v
al_loss: 0.0301
Epoch 126/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0096 - v
al_loss: 0.0240
Epoch 127/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0107 - v
al_loss: 0.0325
Epoch 128/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0095 - v
al_loss: 0.0235
Epoch 129/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0091 - v
al_loss: 0.0315
Epoch 130/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0098 - v
al_loss: 0.0249
Epoch 131/150
84/84 [==============================] - 66s 790ms/step - loss: 0.0092 - v
al_loss: 0.0311
Epoch 132/150
http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 13/93
5/25/2021 brainTumorDownconvolution

84/84 [==============================] - 66s 784ms/step - loss: 0.0087 - v


al_loss: 0.0236
Epoch 133/150
84/84 [==============================] - 65s 778ms/step - loss: 0.0088 - v
al_loss: 0.0266
Epoch 134/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0089 - v
al_loss: 0.0326
Epoch 135/150
84/84 [==============================] - 65s 778ms/step - loss: 0.0088 - v
al_loss: 0.0257
Epoch 136/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0089 - v
al_loss: 0.0341
Epoch 137/150
84/84 [==============================] - 66s 780ms/step - loss: 0.0092 - v
al_loss: 0.0248
Epoch 138/150
84/84 [==============================] - 66s 781ms/step - loss: 0.0105 - v
al_loss: 0.0265
Epoch 139/150
84/84 [==============================] - 65s 776ms/step - loss: 0.0100 - v
al_loss: 0.0284
Epoch 140/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0099 - v
al_loss: 0.0211
Epoch 141/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0102 - v
al_loss: 0.0286
Epoch 142/150
84/84 [==============================] - 65s 778ms/step - loss: 0.0096 - v
al_loss: 0.0265
Epoch 143/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0090 - v
al_loss: 0.0209
Epoch 144/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0094 - v
al_loss: 0.0221
Epoch 145/150
84/84 [==============================] - 65s 775ms/step - loss: 0.0086 - v
al_loss: 0.0276
Epoch 146/150
84/84 [==============================] - 65s 778ms/step - loss: 0.0086 - v
al_loss: 0.0244
Epoch 147/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0086 - v
al_loss: 0.0259
Epoch 148/150
84/84 [==============================] - 65s 777ms/step - loss: 0.0083 - v
al_loss: 0.0230
Epoch 149/150
84/84 [==============================] - 65s 778ms/step - loss: 0.0084 - v
al_loss: 0.0284
Epoch 150/150
84/84 [==============================] - 65s 779ms/step - loss: 0.0079 - v
al_loss: 0.0271

Out[3]:

<keras.callbacks.callbacks.History at 0x27338a01b88>

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 14/93
5/25/2021 brainTumorDownconvolution

After training the neural network we will print its output and the ideal output. We have got 0.0322 training
binary crossentrop yloss and 0.0281 validation binary crossentropy loss . In the code below first all the input
slices will be displayed then the average of the ideal output indentified the 3 experts and then output of the
neural network. This will be repeated for all the samples. The images below are actualy greycale but to make
them more understandable I am printing them with colours, because on greyscale all input imges appear
white ovals and it is difficult to observe tumors with human eye. So on the top I will first print a square to
show which colours represent which value on greyscale with the leftmost side showing colour for black that is
0 and rightmost side showing colour for white that is 1 and the area in the middle increasing linearly on
greyscale. We will also plot a image that will be difference of the ideal output and our output. We will also
calculate the diceloss for each sample and avaerage diceloss over all the samples. The diceloss is defined
as 1-2*intersection/(Sum of the two areas).

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 15/93
5/25/2021 brainTumorDownconvolution

In [4]:

averagetrainingdiceloss=0
averagevalidationdiceloss=0
def diceloss(x,y):
return(1-np.sum(x*y)*2/(np.sum(x+y)))
import matplotlib.pyplot as pl
greyscale=np.zeros((256,256))
for i in range(256):
greyscale[i]=np.arange(0,256)
pl.imshow(greyscale)
pl.show()
print("colours reprsenting the greyscale")
filename="C:/Users/Shardul/Desktop/training_data_v2/brain-tumor/training/case"
for i in range(0,28):
print("training image",i+1)
x=(np.asarray(nb.load(filename+doubledigit(i+1)+"/image.nii.gz").get_fdata()))
yl=[]
for j in range(3):
yl.append(np.asarray(nb.load(filename+doubledigit(int(i+1))+"/task"+"01"+"_se
g"+doubledigit(j+1)+".nii.gz").get_fdata()))
pl.imshow(x[:,:,0])
pl.show()
print("input slice 1 of sample "+str(i+1))
pl.imshow(x[:,:,1])
pl.show()
print("input slice 2 of sample "+str(i+1))
pl.imshow(x[:,:,2])
pl.show()
print("input slice 3 of sample "+str(i+1))
pl.imshow(x[:,:,3])
pl.show()
print("input slice 4 of sample "+str(i+1))
pl.imshow(np.average(yl,axis=0)*255)
pl.show()
print("average of the three expected outputs of sample "+str(i+1))
prediction=np.reshape(m.predict(x.reshape(1,240,240,4)),(240,240))
pl.imshow(prediction*255)
pl.show()
print("neural network ouput of sample "+str(i+1))
pl.imshow(np.ones((240,240))*127+np.average(yl,axis=0)*127-prediction*127)
pl.show()
print("difference in ideal and neural network outputs of sample "+str(i+1))
diceLoss=diceloss(np.average(yl,axis=0),prediction)
print("diceloss is "+str(diceLoss))
averagetrainingdiceloss=averagetrainingdiceloss+diceLoss/28

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 16/93
5/25/2021 brainTumorDownconvolution

print("____________________")
filename="C:/Users/Shardul/Desktop/Validation_data_v2/brain-tumor/Validation/case"
for i in range(28,32):
print("validation image",i+1)
x=(np.asarray(nb.load(filename+doubledigit(i+1)+"/image.nii.gz").get_fdata()))
yl=[]
for j in range(3):
yl.append(np.asarray(nb.load(filename+doubledigit(int(i+1))+"/task"+"01"+"_se
g"+doubledigit(j+1)+".nii.gz").get_fdata()))
pl.imshow(x[:,:,0])
pl.show()
print("input slice 1 of sample "+str(i+1))
pl.imshow(x[:,:,1])
pl.show()
print("input slice 2 of sample "+str(i+1))
pl.imshow(x[:,:,2])
pl.show()
print("input slice 3 of sample "+str(i+1))
pl.imshow(x[:,:,3])
pl.show()
print("input slice 4 of sample "+str(i+1))
pl.imshow(np.average(yl,axis=0)*255)
pl.show()
print("average of the three expected outputs of sample "+str(i+1))
prediction=np.reshape(m.predict(x.reshape(1,240,240,4)),(240,240))
pl.imshow(prediction*255)
pl.show()
print("neural network ouput of sample "+str(i+1))
pl.imshow(np.ones((240,240))*127+np.average(yl,axis=0)*127-prediction*127)
pl.show()
print("difference in ideal and neural network outputs of sample "+str(i+1))
diceLoss=diceloss(np.average(yl,axis=0),prediction)
print("diceloss is "+str(diceLoss))
averagevalidationdiceloss=averagevalidationdiceloss+diceLoss/4
print("____________________")
print("average training diceloss=",averagetrainingdiceloss)
print("average validation diceloss=",averagevalidationdiceloss)

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 17/93
5/25/2021 brainTumorDownconvolution

colours reprsenting the greyscale


training image 1

input slice 1 of sample 1

input slice 2 of sample 1

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 18/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 1

input slice 4 of sample 1

average of the three expected outputs of sample 1

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 19/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 1

difference in ideal and neural network outputs of sample 1


diceloss is 0.08828572213311192
____________________
training image 2

input slice 1 of sample 2

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 20/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 2

input slice 3 of sample 2

input slice 4 of sample 2

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 21/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 2

neural network ouput of sample 2

difference in ideal and neural network outputs of sample 2


diceloss is 0.09537459067151821
____________________
training image 3

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 22/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 3

input slice 2 of sample 3

input slice 3 of sample 3

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 23/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 3

average of the three expected outputs of sample 3

neural network ouput of sample 3

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 24/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 3


diceloss is 0.0823896957567486
____________________
training image 4

input slice 1 of sample 4

input slice 2 of sample 4

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 25/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 4

input slice 4 of sample 4

average of the three expected outputs of sample 4

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 26/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 4

difference in ideal and neural network outputs of sample 4


diceloss is 0.0831906323169811
____________________
training image 5

input slice 1 of sample 5

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 27/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 5

input slice 3 of sample 5

input slice 4 of sample 5

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 28/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 5

neural network ouput of sample 5

difference in ideal and neural network outputs of sample 5


diceloss is 0.09691303449112443
____________________
training image 6

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 29/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 6

input slice 2 of sample 6

input slice 3 of sample 6

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 30/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 6

average of the three expected outputs of sample 6

neural network ouput of sample 6

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 31/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 6


diceloss is 0.11633914030125947
____________________
training image 7

input slice 1 of sample 7

input slice 2 of sample 7

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 32/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 7

input slice 4 of sample 7

average of the three expected outputs of sample 7

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 33/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 7

difference in ideal and neural network outputs of sample 7


diceloss is 0.08183912780139668
____________________
training image 8

input slice 1 of sample 8

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 34/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 8

input slice 3 of sample 8

input slice 4 of sample 8

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 35/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 8

neural network ouput of sample 8

difference in ideal and neural network outputs of sample 8


diceloss is 0.11736814795792416
____________________
training image 9

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 36/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 9

input slice 2 of sample 9

input slice 3 of sample 9

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 37/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 9

average of the three expected outputs of sample 9

neural network ouput of sample 9

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 38/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 9


diceloss is 0.037652371015034936
____________________
training image 10

input slice 1 of sample 10

input slice 2 of sample 10

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 39/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 10

input slice 4 of sample 10

average of the three expected outputs of sample 10

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 40/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 10

difference in ideal and neural network outputs of sample 10


diceloss is 0.060771938093740485
____________________
training image 11

input slice 1 of sample 11

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 41/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 11

input slice 3 of sample 11

input slice 4 of sample 11

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 42/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 11

neural network ouput of sample 11

difference in ideal and neural network outputs of sample 11


diceloss is 0.15051741408100816
____________________
training image 12

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 43/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 12

input slice 2 of sample 12

input slice 3 of sample 12

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 44/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 12

average of the three expected outputs of sample 12

neural network ouput of sample 12

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 45/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 12


diceloss is 0.055228575065088825
____________________
training image 13

input slice 1 of sample 13

input slice 2 of sample 13

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 46/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 13

input slice 4 of sample 13

average of the three expected outputs of sample 13

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 47/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 13

difference in ideal and neural network outputs of sample 13


diceloss is 0.22618567982761395
____________________
training image 14

input slice 1 of sample 14

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 48/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 14

input slice 3 of sample 14

input slice 4 of sample 14

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 49/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 14

neural network ouput of sample 14

difference in ideal and neural network outputs of sample 14


diceloss is 0.09939497386602336
____________________
training image 15

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 50/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 15

input slice 2 of sample 15

input slice 3 of sample 15

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 51/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 15

average of the three expected outputs of sample 15

neural network ouput of sample 15

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 52/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 15


diceloss is 0.15073966159674446
____________________
training image 16

input slice 1 of sample 16

input slice 2 of sample 16

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 53/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 16

input slice 4 of sample 16

average of the three expected outputs of sample 16

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 54/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 16

difference in ideal and neural network outputs of sample 16


diceloss is 0.05068434903370922
____________________
training image 17

input slice 1 of sample 17

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 55/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 17

input slice 3 of sample 17

input slice 4 of sample 17

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 56/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 17

neural network ouput of sample 17

difference in ideal and neural network outputs of sample 17


diceloss is 0.2302354605780712
____________________
training image 18

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 57/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 18

input slice 2 of sample 18

input slice 3 of sample 18

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 58/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 18

average of the three expected outputs of sample 18

neural network ouput of sample 18

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 59/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 18


diceloss is 0.06492925277444705
____________________
training image 19

input slice 1 of sample 19

input slice 2 of sample 19

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 60/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 19

input slice 4 of sample 19

average of the three expected outputs of sample 19

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 61/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 19

difference in ideal and neural network outputs of sample 19


diceloss is 0.07467207727191605
____________________
training image 20

input slice 1 of sample 20

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 62/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 20

input slice 3 of sample 20

input slice 4 of sample 20

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 63/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 20

neural network ouput of sample 20

difference in ideal and neural network outputs of sample 20


diceloss is 0.0432121213620581
____________________
training image 21

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 64/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 21

input slice 2 of sample 21

input slice 3 of sample 21

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 65/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 21

average of the three expected outputs of sample 21

neural network ouput of sample 21

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 66/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 21


diceloss is 0.0757167711782104
____________________
training image 22

input slice 1 of sample 22

input slice 2 of sample 22

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 67/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 22

input slice 4 of sample 22

average of the three expected outputs of sample 22

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 68/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 22

difference in ideal and neural network outputs of sample 22


diceloss is 0.03163019556757096
____________________
training image 23

input slice 1 of sample 23

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 69/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 23

input slice 3 of sample 23

input slice 4 of sample 23

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 70/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 23

neural network ouput of sample 23

difference in ideal and neural network outputs of sample 23


diceloss is 0.04394094318794206
____________________
training image 24

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 71/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 24

input slice 2 of sample 24

input slice 3 of sample 24

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 72/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 24

average of the three expected outputs of sample 24

neural network ouput of sample 24

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 73/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 24


diceloss is 0.025118429773012485
____________________
training image 25

input slice 1 of sample 25

input slice 2 of sample 25

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 74/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 25

input slice 4 of sample 25

average of the three expected outputs of sample 25

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 75/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 25

difference in ideal and neural network outputs of sample 25


diceloss is 0.1400413694648801
____________________
training image 26

input slice 1 of sample 26

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 76/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 26

input slice 3 of sample 26

input slice 4 of sample 26

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 77/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 26

neural network ouput of sample 26

difference in ideal and neural network outputs of sample 26


diceloss is 0.05349405388841799
____________________
training image 27

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 78/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 27

input slice 2 of sample 27

input slice 3 of sample 27

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 79/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 27

average of the three expected outputs of sample 27

neural network ouput of sample 27

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 80/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 27


diceloss is 0.03497341763838724
____________________
training image 28

input slice 1 of sample 28

input slice 2 of sample 28

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 81/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 28

input slice 4 of sample 28

average of the three expected outputs of sample 28

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 82/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 28

difference in ideal and neural network outputs of sample 28


diceloss is 0.054122466735451735
____________________
validation image 29

input slice 1 of sample 29

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 83/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 29

input slice 3 of sample 29

input slice 4 of sample 29

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 84/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 29

neural network ouput of sample 29

difference in ideal and neural network outputs of sample 29


diceloss is 0.12445711809968407
____________________
validation image 30

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 85/93
5/25/2021 brainTumorDownconvolution

input slice 1 of sample 30

input slice 2 of sample 30

input slice 3 of sample 30

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 86/93
5/25/2021 brainTumorDownconvolution

input slice 4 of sample 30

average of the three expected outputs of sample 30

neural network ouput of sample 30

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 87/93
5/25/2021 brainTumorDownconvolution

difference in ideal and neural network outputs of sample 30


diceloss is 0.08720114556469238
____________________
validation image 31

input slice 1 of sample 31

input slice 2 of sample 31

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 88/93
5/25/2021 brainTumorDownconvolution

input slice 3 of sample 31

input slice 4 of sample 31

average of the three expected outputs of sample 31

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 89/93
5/25/2021 brainTumorDownconvolution

neural network ouput of sample 31

difference in ideal and neural network outputs of sample 31


diceloss is 0.13679978577601237
____________________
validation image 32

input slice 1 of sample 32

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 90/93
5/25/2021 brainTumorDownconvolution

input slice 2 of sample 32

input slice 3 of sample 32

input slice 4 of sample 32

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 91/93
5/25/2021 brainTumorDownconvolution

average of the three expected outputs of sample 32

neural network ouput of sample 32

difference in ideal and neural network outputs of sample 32


diceloss is 0.11567003059460035
____________________
average training diceloss= 0.08803434333676405
average validation diceloss= 0.1160320200087473

Now let us calculate the diceloss in the ideal outputs given by 3 experts with each other.

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 92/93
5/25/2021 brainTumorDownconvolution

In [10]:

diceloss_in_ideal_outputs=0
for j in range(3):
for k in range(j+1,3):
filename="C:/Users/Shardul/Desktop/training_data_v2/brain-tumor/training/case"
for i in range(28):
x=np.asarray(nb.load(filename+doubledigit(int(i+1))+"/task"+"01"+"_seg"+dou
bledigit(j+1)+".nii.gz").get_fdata())
y=np.asarray(nb.load(filename+doubledigit(int(i+1))+"/task"+"01"+"_seg"+dou
bledigit(k+1)+".nii.gz").get_fdata())
diceloss_in_ideal_outputs=diceloss_in_ideal_outputs+diceloss(x,y)/96 #there
are 96 possible pairs we have to average over
filename="C:/Users/Shardul/Desktop/Validation_data_v2/brain-tumor/Validation/ca
se"
for i in range(28,32):
x=np.asarray(nb.load(filename+doubledigit(int(i+1))+"/task"+"01"+"_seg"+dou
bledigit(j+1)+".nii.gz").get_fdata())
y=np.asarray(nb.load(filename+doubledigit(int(i+1))+"/task"+"01"+"_seg"+dou
bledigit(k+1)+".nii.gz").get_fdata())
diceloss_in_ideal_outputs=diceloss_in_ideal_outputs+diceloss(x,y)/96
print("average diceloss in ideal outputs is",diceloss_in_ideal_outputs)

average diceloss in ideal outputs is 0.09081075453674936

Result: As can be seen in the images above and the diceloss values of our neural network and that of the
experts with each other, our neural network is accurate.

Refrence:

nnU-Net for Brain Tumor Segmentation

Fabian Isensee 1 , Paul F. J¨ager 1 , Peter M. Full 1 , Philipp Vollmuth 2 , and Klaus H.Maier-Hein 1 1
Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany 2
Section for Computational Neuroimaging, Department of Neuroradiology, Heidelberg University Hospital,
Heidelberg, Germany [email protected]

In [5]:

m.save("C:/Users/Shardul/Desktop/downconvolution")

http://localhost:8888/nbconvert/html/brainTumorDownconvolution.ipynb?download=false 93/93

You might also like