Ejemplo n.º 1
0
    def createNetwork(self, networkName, folderName, cnnLayers, kernel_Shapes,
                      intermediate_ConnectedLayers, n_classes,
                      sampleSize_Train, sampleSize_Test, batch_Size,
                      applyBatchNorm, numberEpochToApplyBatchNorm,
                      activationType, dropout_Rates, pooling_Params,
                      weights_Initialization_CNN, weights_Initialization_FCN,
                      weightsFolderName, weightsTrainedIdx, softmax_Temp):

        # ============= Model Parameters Passed as arguments ================
        # Assign parameters:
        self.networkName = networkName
        self.folderName = folderName
        self.cnnLayers = cnnLayers
        self.n_classes = n_classes
        self.kernel_Shapes = kernel_Shapes
        self.intermediate_ConnectedLayers = intermediate_ConnectedLayers
        self.pooling_scales = pooling_Params
        self.dropout_Rates = dropout_Rates
        self.activationType = activationType
        self.weight_Initialization_CNN = weights_Initialization_CNN
        self.weight_Initialization_FCN = weights_Initialization_FCN
        self.weightsFolderName = weightsFolderName
        self.weightsTrainedIdx = weightsTrainedIdx
        self.batch_Size = batch_Size
        self.sampleSize_Train = sampleSize_Train
        self.sampleSize_Test = sampleSize_Test
        self.applyBatchNorm = applyBatchNorm
        self.numberEpochToApplyBatchNorm = numberEpochToApplyBatchNorm
        self.softmax_Temp = softmax_Temp

        # Compute the CNN receptive field
        stride = 1
        self.receptiveField = computeReceptiveField(self.kernel_Shapes, stride)

        # --- Size of Image samples ---
        self.sampleSize_Train = sampleSize_Train
        self.sampleSize_Test = sampleSize_Test

        ## --- Batch Size ---
        self.batch_Size = batch_Size

        # ======== Calculated Attributes =========
        self.centralVoxelsTrain = getCentralVoxels(self.sampleSize_Train,
                                                   self.receptiveField)
        self.centralVoxelsTest = getCentralVoxels(self.sampleSize_Test,
                                                  self.receptiveField)

        #==============================
        rng = numpy.random.RandomState(23455)

        # Transfer to LIVIA NET
        self.sampleSize_Train = sampleSize_Train
        self.sampleSize_Test = sampleSize_Test

        # --------- Now we build the model -------- #

        print("...[STATUS]: Building the Network model...")

        # Define the symbolic variables used as input of the CNN
        # start-snippet-1
        # Define tensor5
        tensor5 = T.TensorType(dtype='float32',
                               broadcastable=(False, False, False, False,
                                              False))
        self.inputNetwork_Train = tensor5()
        self.inputNetwork_Test = tensor5()

        # Define input shapes to the netwrok
        inputSampleShape_Train = (self.batch_Size, 1, self.sampleSize_Train[0],
                                  self.sampleSize_Train[1],
                                  self.sampleSize_Train[2])
        inputSampleShape_Test = (self.batch_Size, 1, self.sampleSize_Test[0],
                                 self.sampleSize_Test[1],
                                 self.sampleSize_Test[2])

        print(" - Shape of input subvolume (Training): {}".format(
            inputSampleShape_Train))
        print(" - Shape of input subvolume (Testing): {}".format(
            inputSampleShape_Test))

        inputSample_Train = self.inputNetwork_Train
        inputSample_Test = self.inputNetwork_Test

        # TODO change cnnLayers name by networkLayers
        self.generateNetworkLayers(cnnLayers, kernel_Shapes,
                                   self.pooling_scales, inputSampleShape_Train,
                                   inputSampleShape_Test, inputSample_Train,
                                   inputSample_Test,
                                   intermediate_ConnectedLayers)
Ejemplo n.º 2
0
    def createNetwork(self,
                      networkName, 
                      folderName,
                      cnnLayers,
                      kernel_Shapes,
                      intermediate_ConnectedLayers,
                      n_classes,
                      sampleSize_Train,
                      sampleSize_Test,
                      batch_Size,
                      applyBatchNorm,
                      numberEpochToApplyBatchNorm,
                      activationType,
                      dropout_Rates,
                      pooling_Params,
                      weights_Initialization_CNN,
                      weights_Initialization_FCN,
                      weightsFolderName,
                      weightsTrainedIdx,
                      softmax_Temp
                      ):

        # ============= Model Parameters Passed as arguments ================
        # Assign parameters:
        self.networkName = networkName
        self.folderName = folderName
        self.cnnLayers = cnnLayers
        self.n_classes = n_classes
        self.kernel_Shapes = kernel_Shapes
        self.intermediate_ConnectedLayers = intermediate_ConnectedLayers
        self.pooling_scales = pooling_Params
        self.dropout_Rates = dropout_Rates
        self.activationType = activationType
        self.weight_Initialization_CNN = weights_Initialization_CNN
        self.weight_Initialization_FCN = weights_Initialization_FCN
        self.weightsFolderName = weightsFolderName
        self.weightsTrainedIdx = weightsTrainedIdx
        self.batch_Size = batch_Size
        self.sampleSize_Train = sampleSize_Train
        self.sampleSize_Test = sampleSize_Test
        self.applyBatchNorm = applyBatchNorm
        self.numberEpochToApplyBatchNorm = numberEpochToApplyBatchNorm
        self.softmax_Temp = softmax_Temp

        # Compute the CNN receptive field
        stride = 1;
        self.receptiveField = computeReceptiveField(self.kernel_Shapes, stride)

        # --- Size of Image samples ---
        self.sampleSize_Train = sampleSize_Train
        self.sampleSize_Test = sampleSize_Test
        
        ## --- Batch Size ---
        self.batch_Size = batch_Size

        # ======== Calculated Attributes =========
        self.centralVoxelsTrain = getCentralVoxels(self.sampleSize_Train, self.receptiveField) 
        self.centralVoxelsTest = getCentralVoxels(self.sampleSize_Test, self.receptiveField) 
        
        #==============================
        rng = numpy.random.RandomState(23455)

        # Transfer to LIVIA NET
        self.sampleSize_Train = sampleSize_Train
        self.sampleSize_Test = sampleSize_Test
        
        # --------- Now we build the model -------- #

        print("...[STATUS]: Building the Network model...")
        
        # Define the symbolic variables used as input of the CNN
        # start-snippet-1
        # Define tensor5
        tensor5 = T.TensorType(dtype='float32', broadcastable=(False, False, False, False, False))
        self.inputNetwork_Train = tensor5() 
        self.inputNetwork_Test = tensor5()
        self.inputNetwork_Train_Bottom = tensor5() 
        self.inputNetwork_Test_Bottom = tensor5()
        
        # Define input shapes to the netwrok
        inputSampleShape_Train = (self.batch_Size, 1, self.sampleSize_Train[0], self.sampleSize_Train[1], self.sampleSize_Train[2])
        inputSampleShape_Test = (self.batch_Size, 1, self.sampleSize_Test[0], self.sampleSize_Test[1], self.sampleSize_Test[2])

        print (" - Shape of input subvolume (Training): {}".format(inputSampleShape_Train))
        print (" - Shape of input subvolume (Testing): {}".format(inputSampleShape_Test))

        inputSample_Train = self.inputNetwork_Train
        inputSample_Test = self.inputNetwork_Test

        inputSample_Train_Bottom = self.inputNetwork_Train_Bottom
        inputSample_Test_Bottom = self.inputNetwork_Test_Bottom
        
        # TODO change cnnLayers name by networkLayers
        self.generateNetworkLayers(cnnLayers,
                                   kernel_Shapes,
                                   self.pooling_scales,
                                   inputSampleShape_Train,
                                   inputSampleShape_Test,
                                   inputSample_Train,
                                   inputSample_Train_Bottom,
                                   inputSample_Test,
                                   inputSample_Test_Bottom,
                                   intermediate_ConnectedLayers)