Skip to content

Commit

Permalink
Enrich program desscriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng-Lin-Li committed Aug 3, 2018
1 parent 8982050 commit deff070
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Pre-trained weights include in 'data/saved_models/segcapsr3/split-0_batch-1_shuf
9. Add 'bce_dice' loss function as binary cross entropy + soft dice coefficient.
10. Revise 'train', 'test', 'manip' flags from 0 or 1 to flags show up or not to indicate the behavior of main program.
11. Add new webcam integration program for video stream segmentation.

12. Accept any size of images and program automatically convert to 512 X 512 resolutions.
## Procedures

### 1. Download this repo to your own folder
Expand Down
4 changes: 0 additions & 4 deletions gen_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
@version: 1.2
@create: June 27, 2018
@updated: July 06, 2018
Tasks:
The program implementation will classify input image by a trained model and generate mask image as
Expand Down
31 changes: 31 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,37 @@
This is the main file for the project. From here you can train, test, and manipulate the SegCaps of models.
Please see the README for detailed instructions for this project.
==============
This is the entry point of the package to train UNet, tiramisu, Capsule Nets (capsbasic) or SegCaps(segcapsr1 or segcapsr3).
@author: Cheng-Lin Li a.k.a. Clark
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Tasks:
The program load parameters for training, testing, manipulation for all models.
Data:
MS COCO 2017 or LUNA 2016 were tested on this package.
You can leverage your own data set but the mask images should follow the format of MS COCO or with background color = 0 on each channel.
Enhancement:
1. The program was modified to support python 3.6 on Ubuntu 18.04 and Windows 10.
2. Support not only 3D computed tomography scan images but also 2D Microsoft Common Objects in COntext (MS COCO) dataset images.
3. Add Kfold parameter for users to customize the cross validation task. K = 1 will force model to perform overfit.
4. Add retrain parameter to enable users to reload pre-trained weights and retrain the model.
5. Add initial learning rate for users to adjust.
6. Add steps per epoch for users to adjust.
7. Add number of patience for early stop of training to users.
8. Add 'bce_dice' loss function as binary cross entropy + soft dice coefficient.
9. Revise 'train', 'test', 'manip' flags from 0 or 1 to flags show up or not to indicate the behavior of main program.
'''

from __future__ import print_function
Expand Down
25 changes: 25 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
If you have any questions, please email me at lalonde@knights.ucf.edu.
This file is used for testing models. Please see the README for details about testing.
==============
This is the entry point of the test procedure for UNet, tiramisu, Capsule Nets (capsbasic) or SegCaps(segcapsr1 or segcapsr3).
@author: Cheng-Lin Li a.k.a. Clark
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Tasks:
The program based on parameters from main.py to perform testing tasks on all models.
Data:
MS COCO 2017 or LUNA 2016 were tested on this package.
You can leverage your own data set but the mask images should follow the format of MS COCO or with background color = 0 on each channel.
Enhancement:
1. Integrated with MS COCO 2017 dataset.
'''

from __future__ import print_function
Expand Down
24 changes: 23 additions & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@
This file is used for training models. Please see the README for details about training.
Enhancement: Integrated with MS COCO dataset.
==============
This is the entry point of the train procedure for UNet, tiramisu, Capsule Nets (capsbasic) or SegCaps(segcapsr1 or segcapsr3).
@author: Cheng-Lin Li a.k.a. Clark
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Tasks:
The program based on parameters from main.py to perform training tasks on all models.
Data:
MS COCO 2017 or LUNA 2016 were tested on this package.
You can leverage your own data set but the mask images should follow the format of MS COCO or with background color = 0 on each channel.
Enhancement:
1. Integrated with MS COCO 2017 dataset.
'''

from __future__ import print_function
Expand Down
21 changes: 21 additions & 0 deletions utils/custom_data_aug.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@
If you have any questions, please email me at lalonde@knights.ucf.edu.
This file contains the custom data augmentation functions.
=====
This program includes all data augmentation functions UNet, tiramisu, Capsule Nets (capsbasic) or SegCaps(segcapsr1 or segcapsr3).
@author: Cheng-Lin Li a.k.a. Clark
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Enhancement:
1. add image2float_array
2. add image_resize2square: Convert any size of image file to 512 X 512 resolutions
3. add image_enhance function to sifht image color space includes background color
4. add process_image to wrap image color shifting and resize the resolutions
5. add change_background_color to change mask background color of MS COCO files to black
6. add convert_mask_data function to resize and change mask color to black
7. add convert_img_data function to wrap process_image, normalized data, reshape to require dimension 3 or 4
'''

import numpy as np
Expand Down
16 changes: 16 additions & 0 deletions utils/custom_losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
If you have any questions, please email me at lalonde@knights.ucf.edu.
This file contains the definitions of custom loss functions not present in the default Keras.
=====
This program includes all custom loss functions UNet, tiramisu, Capsule Nets (capsbasic) or SegCaps(segcapsr1 or segcapsr3).
@author: Cheng-Lin Li a.k.a. Clark
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Enhancement:
1. Revise default loss_type to jaccard on dice_soft function.
2. add bce_dice_loss for future usage.
'''

import tensorflow as tf
Expand Down
13 changes: 12 additions & 1 deletion utils/data_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
'''
This program is a helper to separate the codes of 2D and 3D image processing.
@author: Cheng-Lin Li a.k.a. Clark
This is a helper file for choosing which dataset functions to create.
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Tasks:
The program is a helper to separate the codes of 2D and 3D image processing.
This is a helper file for choosing which dataset functions to create.
'''
import logging
import utils.load_3D_data as ld3D
Expand Down
41 changes: 27 additions & 14 deletions utils/load_2D_data.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
'''
Capsules for Object Segmentation (SegCaps)
Original Paper by Rodney LaLonde and Ulas Bagci (https://arxiv.org/abs/1804.04241)
Code written by: Rodney LaLonde
If you use significant portions of this code or the ideas from our paper, please cite it :)
If you have any questions, please email me at lalonde@knights.ucf.edu.
This file is used for loading training, validation, and testing data into the models.
It is specifically designed to handle 3D single-channel medical data.
Modifications will be needed to train/test on normal 3-channel images.
Enhancement:
0. Porting to Python version 3.6
1. Add image_resize2square to accept any size of images and change to 512 X 512 resolutions.
2.
This program includes all functions of 2D color image processing for UNet, tiramisu, Capsule Nets (capsbasic) or SegCaps(segcapsr1 or segcapsr3).
@author: Cheng-Lin Li a.k.a. Clark
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Tasks:
The program based on parameters from main.py to load 2D color image files from folders.
The program will convert all image files into numpy format then store training/testing images into
./data/np_files and training (and testing) file lists under ./data/split_list folders.
You need to remove these two folders every time if you want to replace your training image and mask files.
The program will only read data from np_files folders.
Data:
MS COCO 2017 or LUNA 2016 were tested on this package.
You can leverage your own data set but the mask images should follow the format of MS COCO or with background color = 0 on each channel.
Features:
1. Integrated with MS COCO 2017 dataset.
2. Use PILLOW library instead of SimpleITK for better support on RasberryPi
3. add new generate_test_image function to process single image frame for video stream
'''

from __future__ import print_function
Expand Down
39 changes: 27 additions & 12 deletions utils/load_3D_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,49 @@
It is specifically designed to handle 3D single-channel medical data.
Modifications will be needed to train/test on normal 3-channel images.
=====
This program includes all functions of 3D image processing for UNet, tiramisu, Capsule Nets (capsbasic) or SegCaps(segcapsr1 or segcapsr3).
@author: Cheng-Lin Li a.k.a. Clark
@copyright: 2018 Cheng-Lin Li@Insight AI. All rights reserved.
@license: Licensed under the Apache License v2.0. http://www.apache.org/licenses/
@contact: clark.cl.li@gmail.com
Tasks:
The program based on parameters from main.py to load 3D image files from folders.
The program will convert all image files into numpy format then store training/testing images into
./data/np_files and training (and testing) file lists under ./data/split_list folders.
You need to remove these two folders every time if you want to replace your training image and mask files.
The program will only read data from np_files folders.
Data:
MS COCO 2017 or LUNA 2016 were tested on this package.
You can leverage your own data set but the mask images should follow the format of MS COCO or with background color = 0 on each channel.
Enhancement:
0. Porting to Python version 3.6
1. Add image_resize2square to accept any size of images and change to 512 X 512 resolutions.
2.
1. Porting to Python version 3.6
2. Remove program code cleaning
'''

from __future__ import print_function

import logging
from os.path import join, basename
from os import makedirs
# from glob import glob
# import csv
# from sklearn.model_selection import KFold

import numpy as np
from numpy.random import rand, shuffle
import SimpleITK as sitk
# from sklearn.model_selection import train_test_split
# from tqdm import tqdm #Progress bar

# import matplotlib
# matplotlib.use('Agg')
import matplotlib.pyplot as plt
# import cv2

plt.ioff()

# from keras.preprocessing.image import *
from utils.custom_data_aug import augmentImages
from utils.threadsafe import threadsafe_generator

Expand Down

0 comments on commit deff070

Please sign in to comment.