Skip to content

Commit 1781121

Browse files
authored
Merge pull request #483 from OjasChaudhari23/topic-recognition
Topic recognition
2 parents 4ddb292 + 0df95f6 commit 1781121

11 files changed

Lines changed: 1174 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<h2> Name: Ojas Madhusudan Chaudhari </h2>
2+
3+
<h2> Student Number: 46941893 </h2>
4+
5+
<h2>Student Email: o.chaudhari@uqconnect.edu.au </h2>
6+
7+
<h2>Project: Segmentation using UNet </h2>
8+
9+
10+
<h1> Segmentation of ISIC data with improved UNet </h1>
11+
12+
This project develops a solution to the ISIC challenge using UNet. The objective of the project is to train convolutional neural network to segment the ISIC images using improved UNet. The architecture of improved UNet has been referred from F. Isensee, P. Kickingereder, W. Wick, M. Bendszus, and K. H. Maier-Hein’s “Brain Tumor Segmentation and Radiomics Survival Prediction: Contribution to the BRATS 2017 Challenge,” research paper. This paper gives the architecture of improved UNet. It consists of two parts: -
13+
* Downsampling
14+
* Upsampling
15+
16+
Following diagram exactly depicts the architecture
17+
![Improved UNet](https://github.com/OjasChaudhari23/PatternFlow/blob/topic-recognition/recognition/s4694189_UNET/improvedunet.png)
18+
19+
The neural network starts with giving an input layer of 256*256*3. The actual size of the images are 128*128. The images are then resized, normalized and given as array to the network. The neural network starts with contraction at start. It starts with 16 layers and increases in each step. Each step consists of two equal features. After it reaches to 256, Expansion starts. In this project Transposecv has been used for the expansion. In this code I have used dropout(0.1) as it was giving me a good result but it can be changed.
20+
21+
The program starts with importing the data and making the appropriate pre-processing. The Unet structure takes the input in size 256*256*3. In downsampling part, the depth increases to 256 while in upsampling part, the model outputs the image in the same dimension as that of input. Maxpooling is used after each depth to half the size of image in downsampling part. The model has been trained on the whole training data, it is then validated with validation data and the results are observed on test data. Training data has not been split into train-validation-test data.
22+
23+
<h2>Running the program: </h2>
24+
Please download the modules.ipynb file to run the program or alternatively download modules.py, dataset.py, train.py and predict.py files and run train and predict files. The modules.ipynb has all the result data with the merged code and all other files have been created according to their functionality.
25+
26+
<h2> File structure </h2>
27+
* <b> dataset.py </b>:- This file loads the dataset and give the x and y array values with the pre-processing of images.
28+
* <b> module.py </b>:- This file has UNET neural network defined in it and it returns the model
29+
* <b> train.py </b> :- This file trains the model and plots the result. The model uses dice similarity measure to evaluate the model's performance.
30+
* <b> predict.py </b> :- This file evaluates the performance on test data.
31+
32+
<h2> Plots and visualizations</h2>
33+
34+
After building the model. coefficient loss of training and validation data has been visualized with respect to epochs
35+
36+
![Loss](https://github.com/OjasChaudhari23/PatternFlow/blob/topic-recognition/recognition/s4694189_UNET/loss_picture.jpg)
37+
38+
Similarly dice coefficient values have been visualized
39+
![Dice](https://github.com/OjasChaudhari23/PatternFlow/blob/topic-recognition/recognition/s4694189_UNET/dice_coefficient.jpg)
40+
41+
In this project 3 data files which have been given in 2017 ISIC Challenge have been used. Train, validation and test images with their masks have been used for the study. Also the result on test data is quite good and it is more than 0.8
42+
![evaluation](https://github.com/OjasChaudhari23/PatternFlow/blob/topic-recognition/recognition/s4694189_UNET/prediction.jpg)
43+
44+
After visualizing the truth images with predicted images it is quite evident that the improved UNet has performed realy well on the test images.
45+
![Truth_vs_prediction](https://github.com/OjasChaudhari23/PatternFlow/blob/topic-recognition/recognition/s4694189_UNET/truth_vs_prediction.jpg)
46+
47+
This project uses tensorflow version 2.1 version and cv2 for image processing operations. Also Improved Unet has given better image segmentation result that Unet with greater than 80% dice similarity on the test set.
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ## Import the libraries
2+
from keras.utils import normalize
3+
import os
4+
import glob
5+
import cv2
6+
import numpy as np
7+
import matplotlib.pyplot as plt
8+
9+
10+
# ## Loading the images
11+
12+
#Import the images and perform transformation on images
13+
14+
transformed_X = 256
15+
transformed_Y = 256
16+
def load_images(path):
17+
image_list = []
18+
for fi in os.listdir(path):
19+
#print(fi)
20+
if fi.endswith(".csv") or "superpixels" in fi:
21+
continue
22+
img = cv2.imread(os.path.join(path, fi),cv2.IMREAD_COLOR)
23+
img = cv2.resize(img,(transformed_Y,transformed_X))
24+
img = img / 255.0
25+
img = img.astype(np.float32)
26+
image_list.append(img)
27+
image_list = np.array(image_list)
28+
return image_list
29+
30+
31+
# ## Load mask images
32+
33+
#Import the mask dataset
34+
def load_masks(path):
35+
masks_list = []
36+
for fi in os.listdir(path):
37+
#print(fi)
38+
if fi.endswith(".csv") or "superpixels" in fi:
39+
continue
40+
mask = cv2.imread(os.path.join(path, fi),cv2.IMREAD_GRAYSCALE)
41+
mask = cv2.resize(mask,(transformed_Y,transformed_X),interpolation = cv2.INTER_NEAREST)
42+
mask = mask / 255.0
43+
mask = mask.astype(np.float32)
44+
masks_list.append(mask)
45+
masks_list = np.array(masks_list)
46+
return masks_list
47+
48+
49+
# ## Training data
50+
51+
X_train = load_images("ISIC-2017_Training_Data/")
52+
masks_train_images = load_masks("ISIC-2017_Training_Part1_GroundTruth/")
53+
54+
55+
# ## Validation data
56+
x_validate = load_images("ISIC-2017_Validation_Data/")
57+
masks_valid_images = load_masks("ISIC-2017_Validation_Part1_GroundTruth")
58+
59+
60+
x_test = load_images("ISIC-2017_Test_v2_Data/")
61+
masks_test_images = load_images("ISIC-2017_Test_v2_Part1_GroundTruth")
62+
18.6 KB
Loading
94.1 KB
Loading
29.7 KB
Loading
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
from tensorflow.keras.layers import Conv2D, BatchNormalization, Activation, MaxPooling2D
3+
from tensorflow.keras.models import Model
4+
from tensorflow.keras.layers import Input, Conv2D, UpSampling2D, concatenate, Conv2DTranspose, Dropout
5+
from dataset import *
6+
7+
def unet_model():
8+
inputs = Input((256, 256, 3))
9+
x = inputs
10+
# Contraction starts
11+
## 1st downsampled network
12+
conv1 = Conv2D(16,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(x)
13+
conv1 = Dropout(0.1)(conv1)
14+
conv1 = Conv2D(16,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv1)
15+
pool1 = MaxPooling2D((2,2))(conv1)
16+
17+
## 2nd downsampled network
18+
conv2 = Conv2D(32,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(pool1)
19+
conv2 = Dropout(0.1)(conv2)
20+
conv2 = Conv2D(32,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv2)
21+
pool2 = MaxPooling2D((2,2))(conv2)
22+
23+
## 3rd downsampled network
24+
conv3 = Conv2D(64,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(pool2)
25+
conv3 = Dropout(0.1)(conv3)
26+
conv3 = Conv2D(64,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv3)
27+
pool3 = MaxPooling2D((2,2))(conv3)
28+
29+
## 4th downsampled network
30+
conv4 = Conv2D(128,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(pool3)
31+
conv4 = Dropout(0.1)(conv4)
32+
conv4 = Conv2D(128,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv4)
33+
pool4 = MaxPooling2D((2,2))(conv4)
34+
35+
## 5th downsampled network
36+
conv5 = Conv2D(256,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(pool4)
37+
conv5 = Dropout(0.1)(conv5)
38+
conv5 = Conv2D(256,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv5)
39+
pool5 = MaxPooling2D((2,2))(conv5)
40+
41+
##xpansion starts
42+
## 1st upsampled network
43+
upconv6 = Conv2DTranspose(128,(2,2),strides = (2,2),padding="same")(conv5)
44+
upconv6 = concatenate([upconv6, conv4])
45+
conv6 = Conv2D(128,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(upconv6)
46+
conv6 = Dropout(0.1)(conv6)
47+
conv6 = Conv2D(128,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv6)
48+
49+
## 2nd upsampled network
50+
upconv7 = Conv2DTranspose(64,(2,2),strides = (2,2),padding="same")(conv6)
51+
upconv7 = concatenate([upconv7, conv3])
52+
conv7 = Conv2D(64,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(upconv7)
53+
conv7 = Dropout(0.1)(conv7)
54+
conv7 = Conv2D(64,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv7)
55+
56+
## 3rd upsampled network
57+
upconv8 = Conv2DTranspose(32,(2,2),strides = (2,2),padding="same")(conv7)
58+
upconv8 = concatenate([upconv8, conv2])
59+
conv8 = Conv2D(32,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(upconv8)
60+
conv8 = Dropout(0.1)(conv8)
61+
conv8 = Conv2D(32,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv8)
62+
63+
## 4th upsampled network
64+
upconv9 = Conv2DTranspose(16,(2,2),strides = (2,2),padding="same")(conv8)
65+
upconv9 = concatenate([upconv9, conv1],axis=3)
66+
conv9 = Conv2D(16,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(upconv9)
67+
conv9 = Dropout(0.1)(conv9)
68+
conv9 = Conv2D(16,(3,3), padding="same", activation="relu", kernel_initializer="he_normal")(conv9)
69+
70+
##Output layer
71+
outputs = Conv2D(1,(1,1),activation="sigmoid")(conv9)
72+
73+
cnn_model = Model(inputs = [inputs], outputs=[outputs])
74+
return cnn_model
75+
76+
77+
78+
79+

0 commit comments

Comments
 (0)