Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eafc7b6
Initial Commit
MikStap Oct 4, 2022
987d6ef
Creation of Files and Instructions added to README
MikStap Oct 4, 2022
04efe94
Updated Gitignore
MikStap Oct 15, 2022
e75007f
End UNet
MikStap Oct 15, 2022
afa251c
Changed File name
MikStap Oct 15, 2022
600d662
DataSet
MikStap Oct 15, 2022
a17e779
dataset image display
MikStap Oct 15, 2022
86096c8
Added Pickle to speed up module testing
MikStap Oct 16, 2022
ff23326
Updates .gitignore w/ pickle files
MikStap Oct 16, 2022
473dadf
End VQVAE
MikStap Oct 18, 2022
df4a7e6
Load in image/mask pair
MikStap Oct 18, 2022
3527f14
convert mask to 2D array of labels
MikStap Oct 18, 2022
5a5431b
Functional DataLoader
MikStap Oct 18, 2022
6f8478a
Note to Marker
MikStap Oct 20, 2022
4a0e280
Create Convolution Blocks & Tidy Dataset
MikStap Oct 20, 2022
aa2dd1e
Create Unet
MikStap Oct 20, 2022
fa08e7a
Training process created
MikStap Oct 20, 2022
1f57e85
Training Excess Removed
MikStap Oct 20, 2022
8d340ed
Input shape fixed
MikStap Oct 20, 2022
e81c877
Images and Epochs fixed
MikStap Oct 20, 2022
3321413
Fixed Train+Test
MikStap Oct 20, 2022
0571496
Producing Labels
MikStap Oct 20, 2022
c0a2dd6
Labels corrected
MikStap Oct 20, 2022
26742c6
Updated loss and tweaked metrics
MikStap Oct 20, 2022
bb0653e
Fixed the tweaking
MikStap Oct 20, 2022
522b0c4
Corrected loss
MikStap Oct 20, 2022
8f4fc9e
Finalised Code
MikStap Oct 21, 2022
2c7ad04
Comments and ReadMe
MikStap Oct 21, 2022
2940abd
Attempt to solve image Display error
MikStap Oct 21, 2022
539fa1b
Fixed ReadMe Image display Issues
MikStap Oct 21, 2022
34d7c28
Final Image Fixed
MikStap Oct 21, 2022
c72a0a5
Merge branch 'topic-recognition' into topic-recognition
MikStap Nov 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ __pycache__/
*.py[cod]
*$py.class

#DataSets
**DataSets/

# C extensions
*.so
.idea
Expand Down Expand Up @@ -132,4 +135,4 @@ dmypy.json
.idea/

# no tracking mypy config file
mypy.ini
mypy.ini
125 changes: 38 additions & 87 deletions recognition/ISICs_UNet/README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,52 @@
# Segment the ISICs data set with the U-net
# Segmenting ISICs with U-Net

## Project Overview
This project aim to solve the segmentation of skin lesian (ISIC2018 data set) using the U-net, with all labels having a minimum Dice similarity coefficient of 0.7 on the test set[Task 3].
COMP3710 Report recognition problem 3 (Segmenting ISICs data set with U-Net) solved in TensorFlow

## ISIC2018
![ISIC example](imgs/example.jpg)
Created by Christopher Bailey (45576430)

Skin Lesion Analysis towards Melanoma Detection
## The problem and algorithm
The problem solved by this program is binary segmentation of the ISICs skin lesion data set. Segmentation is a way to label pixels in an image according to some grouping, in this case lesion or non-lesion. This translates images of skin to masks representing areas of concern for skin lesions.

Task found in https://challenge2018.isic-archive.com/
U-Net is a form of autoencoder where the downsampling path is expected to learn the features of the image and the upsampling path learns how to recreate the masks. Long skip connections between downpooling and upsampling layers are utilised to overcome the bottleneck in traditional autoencoders allowing feature representations to be recreated.

## How it works
A four layer padded U-Net is used, preserving skin features and mask resolution. The implementation utilises Adam as the optimizer and implements Dice distance as the loss function as this appeared to give quicker convergence than other methods (eg. binary cross-entropy).

## U-net
![UNet](imgs/uent.png)
The utilised metric is a Dice coefficient implementation. My initial implementation appeared faulty and was replaced with a 3rd party implementation which appears correct. 3 epochs was observed to be generally sufficient to observe Dice coefficients of 0.8+ on test datasets but occasional non-convergence was observed and could be curbed by increasing the number of epochs. Visualisation of predictions is also implemented and shows reasonable correspondence. Orange bandaids represent an interesting challenge for the implementation as presented.

U-net is one of the popular image segmentation architectures used mostly in biomedical purposes. The name UNet is because it’s architecture contains a compressive path and an expansive path which can be viewed as a U shape. This architecture is built in such a way that it could generate better results even for a less number of training data sets.
### Training, validation and testing split
Training, validation and testing uses a respective 60:20:20 split, a commonly assumed starting point suggested by course staff. U-Net in particular was developed to work "with very few training images" (Ronneberger et al, 2015) The input data for this problem consists of 2594 images and masks. This split appears to provide satisfactory results.

## Data Set Structure
## Using the model
### Dependencies required
* Python3 (tested with 3.8)
* TensorFlow 2.x (tested with 2.3)
* glob (used to load filenames)
* matplotlib (used for visualisations, tested with 3.3)

data set folder need to be stored in same directory with structure same as below
```bash
ISIC2018
|_ ISIC2018_Task1-2_Training_Input_x2
|_ ISIC_0000000
|_ ISIC_0000001
|_ ...
|_ ISIC2018_Task1_Training_GroundTruth_x2
|_ ISIC_0000000_segmentation
|_ ISIC_0000001_segmentation
|_ ...
```
### Parameter tuning
The model was developed on a GTX 1660 TI (6GB VRAM) and certain values (notably batch size and image resolution) were set lower than might otherwise be ideal on more capable hardware. This is commented in the relevant code.

## Dice Coefficient
### Running the model
The model is executed via the main.py script.

The Sørensen–Dice coefficient is a statistic used to gauge the similarity of two samples.
### Example output
Given a batch size of 1 and 3 epochs the following output was observed on a single run:
Era | Loss | Dice coefficient
--- | ---- | ----------------
Epoch 1 | 0.7433 | 0.2567
Epoch 2 | 0.3197 | 0.6803
Epoch 3 | 0.2657 | 0.7343
Testing | 0.1820 | 0.8180

Further information in https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient

## Dependencies
### Figure 1 - example visualisation plot
Skin images in left column, true mask middle, predicted mask right column
![Visualisation of predictions](visual.png)

- python 3
- tensorflow 2.1.0
- pandas 1.1.4
- numpy 1.19.2
- matplotlib 3.3.2
- scikit-learn 0.23.2
- pillow 8.0.1


## Usages

- Run `train.py` for training the UNet on ISIC data.
- Run `evaluation.py` for evaluation and case present.

## Advance

- Modify `setting.py` for custom setting, such as different batch size.
- Modify `unet.py` for custom UNet, such as different kernel size.

## Algorithm

- data set:
- The data set we used is the training set of ISIC 2018 challenge data which has segmentation labels.
- Training: Validation: Test = 1660: 415: 519 = 0.64: 0.16 : 0.2 (Training: Test = 4: 1 and in Training, further split 4: 1 for Training: Validation)
- Training data augmentations: rescale, rotate, shift, zoom, grayscale
- model:
- Original UNet with padding which can keep the shape of input and output same.
- The first convolutional layers has 16 output channels.
- The activation function of all convolutional layers is ELU.
- Without batch normalization layers.
- The inputs is (384, 512, 1)
- The output is (384, 512, 1) after sigmoid activation.
- Optimizer: Adam, lr = 1e-4
- Loss: dice coefficient loss
- Metrics: accuracy & dice coefficient

## Results

Evaluation dice coefficient is 0.805256724357605.

plot of train/valid Dice coefficient:

![img](imgs/train_and_valid_dice_coef.png)

case present:

![case](imgs/case%20present.png)

## Reference
Manna, S. (2020). K-Fold Cross Validation for Deep Learning using Keras. [online] Medium. Available at: https://medium.com/the-owl/k-fold-cross-validation-in-keras-3ec4a3a00538 [Accessed 24 Nov. 2020].

zhixuhao (2020). zhixuhao/unet. [online] GitHub. Available at: https://github.com/zhixuhao/unet.

GitHub. (n.d.). NifTK/NiftyNet. [online] Available at: https://github.com/NifTK/NiftyNet/blob/a383ba342e3e38a7ad7eed7538bfb34960f80c8d/niftynet/layer/loss_segmentation.py [Accessed 24 Nov. 2020].

Team, K. (n.d.). Keras documentation: Losses. [online] keras.io. Available at: https://keras.io/api/losses/#creating-custom-losses [Accessed 24 Nov. 2020].

262588213843476 (n.d.). unet.py. [online] Gist. Available at: https://gist.github.com/abhinavsagar/fe0c900133cafe93194c069fe655ef6e [Accessed 24 Nov. 2020].

Stack Overflow. (n.d.). python - Disable Tensorflow debugging information. [online] Available at: https://stackoverflow.com/questions/35911252/disable-tensorflow-debugging-information [Accessed 24 Nov. 2020].
## References
Segments of code in this assignment were used from or based on the following sources:
1. COMP3710-demo-code.ipynb from Guest Lecture
1. https://www.tensorflow.org/tutorials/load_data/images
1. https://www.tensorflow.org/guide/gpu
1. Karan Jakhar (2019) https://medium.com/@karan_jakhar/100-days-of-code-day-7-84e4918cb72c
46 changes: 46 additions & 0 deletions recognition/XUE4645768/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,52 @@ python gcn.py

Warning: Please pay attention to whether the data path is correct when you run the gcn.py.

# Training

Learning rate= 0.01
Weight dacay =0.005

For 200 epoches:
```Epoch 000: Loss 0.2894, TrainAcc 0.9126, ValAcc 0.8954
Epoch 001: Loss 0.2880, TrainAcc 0.9126, ValAcc 0.895
Epoch 002: Loss 0.2866, TrainAcc 0.9126, ValAcc 0.8961
Epoch 003: Loss 0.2853, TrainAcc 0.9132, ValAcc 0.8961
Epoch 004: Loss 0.2839, TrainAcc 0.9137, ValAcc 0.8961
Epoch 005: Loss 0.2826, TrainAcc 0.9141, ValAcc 0.8963
Epoch 006: Loss 0.2813, TrainAcc 0.9146, ValAcc 0.8956
Epoch 007: Loss 0.2800, TrainAcc 0.9146, ValAcc 0.8956
Epoch 008: Loss 0.2788, TrainAcc 0.9146, ValAcc 0.8959
Epoch 009: Loss 0.2775, TrainAcc 0.9146, ValAcc 0.8970
Epoch 010: Loss 0.2763, TrainAcc 0.915, ValAcc 0.8974
Epoch 011: Loss 0.2751, TrainAcc 0.915, ValAcc 0.8972
Epoch 012: Loss 0.2739, TrainAcc 0.915, ValAcc 0.8976
Epoch 013: Loss 0.2727, TrainAcc 0.9157, ValAcc 0.8979
Epoch 014: Loss 0.2716, TrainAcc 0.9157, ValAcc 0.8983
Epoch 015: Loss 0.2704, TrainAcc 0.9161, ValAcc 0.8990
Epoch 016: Loss 0.2693, TrainAcc 0.9168, ValAcc 0.8988
Epoch 017: Loss 0.2682, TrainAcc 0.9181, ValAcc 0.8990
Epoch 018: Loss 0.2671, TrainAcc 0.9179, ValAcc 0.8990
Epoch 019: Loss 0.2660, TrainAcc 0.9179, ValAcc 0.8992
Epoch 020: Loss 0.2650, TrainAcc 0.9188, ValAcc 0.8996
......
Epoch 190: Loss 0.1623, TrainAcc 0.9553, ValAcc 0.9134
Epoch 191: Loss 0.1619, TrainAcc 0.9555, ValAcc 0.9134
Epoch 192: Loss 0.1615, TrainAcc 0.9555, ValAcc 0.9132
Epoch 193: Loss 0.1611, TrainAcc 0.9557, ValAcc 0.9130
Epoch 194: Loss 0.1607, TrainAcc 0.9562, ValAcc 0.9130
Epoch 195: Loss 0.1603, TrainAcc 0.9559, ValAcc 0.9130
Epoch 196: Loss 0.1599, TrainAcc 0.9562, ValAcc 0.9126
Epoch 197: Loss 0.1595, TrainAcc 0.9562, ValAcc 0.9123
Epoch 198: Loss 0.1591, TrainAcc 0.9562, ValAcc 0.9123
Epoch 199: Loss 0.1587, TrainAcc 0.9562, ValAcc 0.9123```

For test accuracy:around 0.9

# TSNE
For the test:iteration=500, with lower dimension to 2

<img src="https://github.com/eliasxue/3710-pattern-flow/blob/main/tsne%20.png?raw=true">


```python

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions recognition/s46413587_Improved_Unet_on_ISIC/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Improved U-Net applied to the 2017 International Skin Imaging Collaboration (ISIC) Dataset with Segmentation

## Why use U-Net on ISIC?
The ISIC is an annual challenge that serves as a part of an international effort to use computer vision to improve melanoma diagnosis based on images of skin legions.
A U-Net is a type of convolutional neural network that has been specifically developed for biomedical image segmentation, and is a collection of modifications made to a fully convolutional network with the intention of improving segmentation accuracy on smaller training sets.
By utilizing an improved U-Net algorithm, this project works to identify regions of a given image in which there is significant discolouration, based on training with images and corresponding segmentation mask images, to analyse each pixel of an image to determine whether or not the area is a different colour to the natural skin, identifying potential melanomas.

## How an Improved U-Net works
An Improved U-Net works in 8 main sections, each comprised of two convolutional layers. These 8 sections are split into two parts - condensing and upsampling. The condensing part has 4 of these two part layers, where in the data goes through the standard convolutional layers, but at the end of each 'part' (or, every two layers), a snapshot of the state of the network layer is taken and stored for later use. Then, the network goes through 4 corresponding 'upsampling' layers, which replace the standard pooling layers by instead upscaling the previous layer and concatenating with the appropriate 'snapshot' from the convolutional layers.
I have followed the concepts and principals as explained the paper [Brain Tumor Segmentation and Radiomics Survival Prediction: Contribution to the BRATS 2017 Challenge](https://arxiv.org/pdf/1802.10508v1.pdf). This paper also provides this diagram, which provides a clearer visualization of how these layers interact.

![1](Images/unet.png)

I have also taken inspiration and advice from [This Kaggel U-Net implementation](https://www.kaggle.com/code/mukulkr/camvid-segmentation-using-unet/notebook) which segments an images into 32 different possible categories.

## Results
The U-Net I have implemented has been very successful, getting these sound results on a test set after only 15 epochs:

![2](Images/evaluation.png)

Which can be visualised:

![3](Images/good.png)
![4](Images/good1.png)
![5](Images/good3.png)
![6](Images/good5.png)


I have also created a plot of loss, Accuracy, and Dice Similarity (for more details on this metric, please read the paper above).

![7](Images/loss.png)
![8](Images/acc.png)
![9](Images/dsc.png)

## Reproducibility
These results were attained by running the code on google colab, with random seed set to 909, and all packages at their most current version as at 20/10/22. Note that due to computing and time constraints, it was run using only the 'training' set from the ISIC data, and was downloaded and split with the following code:
```
dataset_url = "https://isic-challenge-data.s3.amazonaws.com/2017/ISIC-2017_Training_Data.zip"
maskset_url = "https://isic-challenge-data.s3.amazonaws.com/2017/ISIC-2017_Training_Part1_GroundTruth.zip"
data_dir = keras.utils.get_file(origin=dataset_url, extract=True)
mask_dir = keras.utils.get_file(origin=maskset_url, extract=True)

im_root = "/root/.keras/datasets/ISIC-2017_Training_Data"
lb_root = "/root/.keras/datasets/ISIC-2017_Training_Part1_GroundTruth"
data = Path(im_root)
mask = Path(lb_root)

base_imgs = list((data).glob("*.jpg"))

train_imgs, val_imgs, test_imgs = np.split(base_imgs, [int(len(base_imgs)*0.7), int(len(base_imgs)*0.9)])

train_pair = make_pair(train_imgs, mask)
test_pair = make_pair(test_imgs, mask)
val_pair = make_pair(val_imgs, mask)
```

The split of 7:2:1 was chosen in accordance with the standard split, though the testing set is somewhat smaller than standard to ensure there was sufficient data for training on the smaller set.
Loading