Преглед изворни кода

Adding deepmedic segmentation configuration

Andrej пре 4 година
родитељ
комит
424827529d

+ 133 - 0
segmentation/model/modelConfig.cfg

@@ -0,0 +1,133 @@
+# -*- coding: utf-8 -*-
+#  Default values are set internally, if the corresponding parameter is not found in the configuration file.
+
+#  [Optional but highly suggested] The name will be used in the filenames when saving the model.
+#  Default: "cnnModel"
+modelName = "model_name"
+
+#  [Required] The main folder that the output will be placed.
+folderForOutput = "../output/"
+
+
+#  ================ MODEL PARAMETERS =================
+
+#  [Required] The number of classes in the task. Including background!
+numberOfOutputClasses = 19 # see C:\Users\DTHUFF\Documents\Research\Projects\semi_sup_segmentation\visercal3\Documentation\radLexIDs.xlsx
+# 0=background
+# 1=liver
+# 2=spleen
+# 3=lung
+# 4=Thyroid
+# 5=kidney
+# 6=Pancreas
+# 7=Gallbladder ##
+# 8=Bladder
+# 9=Aorta
+# 10=Trachea
+# 11=Sternum ##
+# 12=vertebra L1 ##
+# 13=adrenal ##
+# 14=psoas major
+# 15=Rectus
+# 16=Bowel
+# 17=Stomach 
+# 18=Heart ##
+
+#  [Required] The number of input channels, eg number of MRI modalities.
+numberOfInputChannels = 1
+
+#  +++++++++++Normal pathway+++++++++++
+#  [Required] This list should have as many entries as the number of layers I want the normal-pathway to have.
+#  Each entry is an integer that specifies the number of Feature Maps to use in each of the layers.
+numberFMsPerLayerNormal = [30, 30, 40, 40, 40, 40, 50, 50]
+#  [Required] This list should have as many entries as the number of layers in the normal pathway.
+#  Each entry should be a sublist with 3 entries. These should specify the dimensions of the kernel at the corresponding layer.
+kernelDimPerLayerNormal = [[3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3]]
+
+#  [Optional] List with number of layers, at the output of which to make a residual connection with the input of the previous layer. Ala Kaiming He et al, "Deep Residual Learning for Image Recognition".
+#  Note: Numbering starts from 1 for the first layer, which is not an acceptable value (no previous layer).
+#  Example: [4,6,8] will connect (add) to the output of Layer 4 the input of Layer 3. Also, input to 5th will be added to output of 6th, and input of 7th to output of 8th.
+#  Default: [], no residual connections
+layersWithResidualConnNormal = [4,6,8]
+
+#  [Optional] Layers to make of lower rank. Ala Yani Ioannou et al, "Training CNNs with Low-Rank Filters For Efficient Image Classification".
+#  Example: [3,5] will make the 3rd and 5th layers of lower rank.
+#  Default: []
+lowerRankLayersNormal = []
+
+#  +++++++++++Subsampled pathway+++++++++++
+#  [Optional] Specify whether to use a subsampled pathway. If False, all subsampled-related parameters will be read but disregarded in the model-construction.
+#  Default: False
+useSubsampledPathway = True
+
+#  [Optionals] The below parameters specify the subsampled-pathway architecture in a similar way as the normal.
+#  If they are ommitted and useSubsampledPathway is set to True, the subsampled pathway will be made similar to the normal pathway (suggested for easy use).
+#  [WARN] Subsampled pathway MUST have the same size of receptive field as the normal. Limitation in the code. User could easily specify different number of FMs. But care must be given if number of layers is changed. In this case, kernel sizes should also be adjusted to achieve same size of Rec.Field.
+numberFMsPerLayerSubsampled = [30, 30, 40, 40, 40, 40, 50, 50]
+kernelDimPerLayerSubsampled = [[3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3], [3,3,3]]
+
+#  [Optional] How much to downsample the image that the subsampled-pathway processes.
+#  Requires either a) list of 3 integers, or b) list of lists of 3 integers.
+#  Input example a) [3,3,3]   Creates one additional parallel pathway, where input is subsampled by 3 in the x,y,z axis (the 3 elements of the list).
+#  Input example b) [[3,3,3], [5,5,5]]   Creates two additional parallel pathways. One with input subsampled by [3,3,3], and one subsampled by [5,5,5]. If not specified, each path mirrors the previous.
+#  Default: [[3,3,3]]
+subsampleFactor = [[3,3,3], [5,5,5]]
+
+#  [Optional] Residual Connections for subsampled pathway. See corresponding parameter for normal pathway.
+#  Default: mirrors the normal pathway, no residual connections
+layersWithResidualConnSubsampled = [4,6,8]
+
+#  [Optional] Layers to make of lower rank. See corresponding parameter for normal pathway.
+#  Default: Mirrors the normal pathway
+#lowerRankLayersSubsampled = []
+
+#  +++++++++++FC Layers+++++++++++
+#  [Optional] After the last layers of the normal and subsampled pathways are concatenated, additional Fully Connected hidden layers can be added before the final classification layer.
+#  Specify a list, with as many entries as the number of ADDITIONAL FC layers (other than the classification layer) to add. The entries specify the number of Feature Maps to use.
+#  Default: []
+numberFMsPerLayerFC = [250, 250]
+
+#  [Optional] Specify dimensions of the kernel in the first FC layer. This kernel combines the features from multiple scales. Applies to the final Classification layer if no hidden FC layers in network.
+#  Note: convolution with this kernel retains the size of the FMs (input is padded).
+#  Default: [1,1,1]
+kernelDimFor1stFcLayer = [3,3,3]
+
+#  [Optional] Residual Connections for the FC hidden layers. See corresponding parameter for normal pathway.
+#  Default: [], no connections.
+layersWithResidualConnFC = [2]
+
+#  +++++++++++Size of Image Segments+++++++++++
+#  DeepMedic does not process patches of the image, but larger image-segments. Specify their size here.
+
+#  [Required] Size of training segments influence the captured distribution of samples from the different classes (see DeepMedic paper)
+segmentsDimTrain = [37,37,37]
+#  [Optional] The size of segments to use during the validation-on-samples process that is performed throughout training if requested.
+#  Default: equal to receptive field, to validate on patches.
+segmentsDimVal = [17,17,17]
+#  [Optional] Bigger image segments for Inference are safe to use and only speed up the process. Only limitation is the GPU memory.
+#  Default: equal to the training segment.
+segmentsDimInference = [45,45,45]
+
+
+#  [Optionals] Dropout Rates on the input connections of the various layers. Each list should have as many entries as the number of layers in the corresponding pathway.
+#  0 = no dropout. 1= 100% drop of the neurons. Empty list for no dropout.
+#  Default: []
+dropoutRatesNormal = []
+dropoutRatesSubsampled = []
+#  Default: 50% dropout on every Fully Connected layer except for the first one after the concatenation
+#  Note: The list for FC rates should have one additional entry in comparison to "numberFMsPerLayerFC", for the classification layer.
+dropoutRatesFc = [0.0, 0.5, 0.5] # +1 for the classification layer!
+
+#  [Optional] Initialization method for the conv kernel weights.
+#  Options: ["normal", std] for sampling from N(0, std). ["fanIn", scale] for scaling variance with (scale/fanIn). Eg ["fanIn", 2] initializes ala "Delving Deep into Rectifiers".
+#  Default: ["fanIn", 2]
+convWeightsInit = ["fanIn", 2]
+#  [Optional] Activation Function for all convolutional layers. Allowed: "linear", "relu", "prelu", "elu", "selu"
+#  Default: "prelu"
+activationFunction = "prelu"
+
+#  [Optional] Batch Normalization uses a rolling average of the mus and std for inference.
+#  Specify over how many batches (SGD iterations) this moving average should be computed. Value <= 0 disables BN.
+#  Default : 60
+rollAverageForBNOverThatManyBatches = 60
+

BIN
segmentation/saved_models/DM_defaults.DM_train_VISCERAL16_Fold1.final.2019-10-01.07.46.19.932616.model.ckpt.data-00000-of-00001


BIN
segmentation/saved_models/DM_defaults.DM_train_VISCERAL16_Fold1.final.2019-10-01.07.46.19.932616.model.ckpt.index


BIN
segmentation/saved_models/DM_defaults.DM_train_qtii_LABELMASKS4.final.2020-10-31.05.59.36.425298.model.ckpt.data-00000-of-00001


BIN
segmentation/saved_models/DM_defaults.DM_train_qtii_LABELMASKS4.final.2020-10-31.05.59.36.425298.model.ckpt.index


+ 6 - 0
segmentation/saved_models/INFO_ABOUT_MODELS.txt

@@ -0,0 +1,6 @@
+Retrained on more patients, improved thyroid performance, only for 4 organs, labels are changed to 1-4!
+DM_defaults.DM_train_qtii_LABELMASKS4.final.2020-10-31.05.59.36.425298.model.ckpt
+
+Old model on which all results are obtained, labels 1-16, poor thyroid performance.
+DM_defaults.DM_train_VISCERAL16_Fold1.final.2019-10-01.07.46.19.932616.model.ckpt
+

+ 2 - 0
segmentation/test/testChannels_CT.cfg

@@ -0,0 +1,2 @@
+D:\PhD\IPNU\PROSPECTIVE\1160_00\VISIT_0\Processed\_CT_0mean1std_notCropped_2mmVoxel.nii
+D:\PhD\IPNU\PROSPECTIVE\1160_00\VISIT_1\Processed\_CT_0mean1std_notCropped_2mmVoxel.nii

+ 58 - 0
segmentation/test/testConfig.cfg

@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+#  Default values are set internally, if the corresponding parameter is not found in the configuration file.
+
+#  [Optional but highly suggested] The name will be used for naming folders to save the results in.
+#  Default: "testSession"
+sessionName = "currentSession"
+
+#  [Required] The main folder that the output will be placed.
+folderForOutput = "../output/"
+
+#  [Optional] Path to a saved model, to load parameters from in the beginning of the session. If one is also specified using the command line, the latter will be used.
+cnnModelFilePath = "../saved_models/DM_defaults.DM_train_VISCERAL16_Fold1.final.2019-10-01.07.46.19.932616.model.ckpt"
+
+#  +++++++++++ Input +++++++++++
+#  [Required] A list that should contain as many entries as the channels of the input image (eg multi-modal MRI). The entries should be paths to files. Those files should be listing the paths to the corresponding channels for each test-case. (see example files).
+channels = ["./testChannels_CT.cfg"]
+
+#  [Required] The path to a file, which should list names to give to the results for each testing case. (see example file).
+namesForPredictionsPerCase = "./testNamesOfPredictions.cfg"
+
+#  [Optional] The path to a file, which should list paths to the Region-Of-Interest masks for each testing case.
+#  If ROI masks are provided, inference will only be performed in within it (faster). If not specified, inference will be performed in whole volume.
+roiMasks = "./testRoiMasks.cfg"
+
+#  [Optional] The path to a file which should list paths to the Ground Truth labels of each testing case. If provided, DSC metrics will be reported. Otherwise comment out this entry.
+# gtLabels = "./testGtLabels_retmel.cfg"
+
+# [Optional] Batch size. Default: 10
+batchsize = 1
+
+#  +++++++++++Predictions+++++++++++
+#  [Optional] Specify whether to save segmentation map. Default: True
+saveSegmentation = True
+#  [Optional] Specify a list with as many entries as the task's classes. True/False to save/not the probability map for the corresponding class. Default: [True,True...for all classes]
+saveProbMapsForEachClass = [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
+
+# overlap=1 is lots of overlap (no step, gets stuck), overlap=0 is no overlap
+overlap = 0.0
+#  +++++++++++Feature Maps+++++++++++
+#  [Optionals] Specify whether to save the feature maps in separate files and/or all together in a 4D image. Default: False for both cases.
+#saveIndividualFms = True
+#saveAllFmsIn4DimImage = False
+
+#  [Optionals] A model may have too many feature maps, and some may not be needed. For this, we allow specifying which FMs to save. 
+#  Specify for each type of pathway (normal/subsampled/FC), a list with as many sublists as the layers of the pathway.
+#  Each sublist (one for each layer), should have 2 numbers. These are the minimum (inclusive) and maximum (exclusive) indices of the Feature Maps that we wish to save from the layer.
+#  The preset example saves the Feature Maps from index 0 (first FM) to 150 of the last hidden FC layer, before the classification layer.
+#  Default: [] for all.
+#minMaxIndicesOfFmsToSaveFromEachLayerOfNormalPathway = []
+#minMaxIndicesOfFmsToSaveFromEachLayerOfSubsampledPathway = [[],[],[],[],[],[],[],[]]
+#minMaxIndicesOfFmsToSaveFromEachLayerOfFullyConnectedPathway = [[],[0,150],[]]
+
+
+#  ==========Generic=============
+#  [Optional] Pad images to fully convolve. Default: True
+padInputImagesBool = True
+
+

+ 2 - 0
segmentation/test/testNamesOfPredictions.cfg

@@ -0,0 +1,2 @@
+1160_00-VISIT_0.nii
+1160_00-VISIT_1.nii

+ 2 - 0
segmentation/test/testRoiMasks.cfg

@@ -0,0 +1,2 @@
+D:\PhD\IPNU\PROSPECTIVE\1160_00\VISIT_0\Processed\_patientmask_notCropped_2mmVoxel.nii.gz
+D:\PhD\IPNU\PROSPECTIVE\1160_00\VISIT_1\Processed\_patientmask_notCropped_2mmVoxel.nii.gz