Exemplo n.º 1
0
 def initFromConfig(self, cfg, sectionKey):
     super(PoolLayerParams, self).initFromConfig(cfg, sectionKey)
     self._inputDim = readCfgIntNoneListParam(cfg, sectionKey, 'inputDim',
                                              self._inputDim)
     self._poolType = readCfgIntParam(cfg, sectionKey, 'poolType',
                                      self._poolType)
     self._poolsize = readCfgIntNoneListParam(cfg, sectionKey, 'poolsize',
                                              self._poolsize)
     self.update()
Exemplo n.º 2
0
    def initFromConfig(self,cfg,networkKey='net'):
        #typeID,nChan=3,wIn=64,hIn=64,batchSize=128,nOut=3
        #self.readCfgIntParam(cfg, 'net', 'type', default=0)
        layerDef = readCfgParam(cfg, networkKey, 'layers', '')
        
        self._inputDim = readCfgIntNoneListParam(cfg, networkKey, 'inputDim', self._inputDim)
        if self._inputDim is not None:
            self.batch_size = self._inputDim[0]
        else:
            self.batch_size = None
        
        lastLayerOutputDim = self._inputDim 
        
        layerDef = layerDef.strip()
        if layerDef == '':
            raise ValueError("Cannot create a SimpleFFNetwork without a 'layers' definition")
        
        self.layerCfgs = [] 

        layerNames = layerDef.split(',')
        
        for layerName in layerNames:
            layerName = layerName.strip()
            if not cfg.has_section(layerName):
                raise ValueError("There is no definition for layer '{}' in the config".format(layerName))
            
            typeName = readCfgParam(cfg, layerName, 'layerType', '')
            LayerParamsClass = self.getLayerParamsClassFromTypeName(typeName)
            layerParams = LayerParamsClass(inputDim = lastLayerOutputDim) 
            layerParams.initFromConfig(cfg,layerName)
            self.layerCfgs.append(layerParams)
            
            lastLayerOutputDim = layerParams.outputDim
            
        self.outputDim = lastLayerOutputDim
Exemplo n.º 3
0
 def initFromConfig(self,cfg,sectionKey):
     super(LCNLayerParams,self).initFromConfig(cfg,sectionKey)
     
     self._inputDim = readCfgIntNoneListParam(cfg,sectionKey,'inputDim',self._inputDim)
     #self._sigma1 = readCfgFloatParam(cfg,sectionKey,'sigma1',self._sigma1)
     #self._sigma2 = readCfgFloatParam(cfg,sectionKey,'sigma2',self._sigma2)
     self._radius = readCfgFloatParam(cfg,sectionKey,'radius',self._radius)
     self.update()
Exemplo n.º 4
0
    def initFromConfig(self, cfg, sectionKey):
        super(ConvLayerParams, self).initFromConfig(cfg, sectionKey)

        self._inputDim = readCfgIntNoneListParam(cfg, sectionKey, 'inputDim',
                                                 self._inputDim)
        self._nFilters = readCfgIntParam(cfg, sectionKey, 'nFilters',
                                         self._nFilters)
        self._filterDim = readCfgIntNoneListParam(cfg, sectionKey, 'filterDim',
                                                  self._filterDim)
        #self._filter_shape = filter_shape
        #self._image_shape = image_shape
        #self._outputDim = readCfgIntNoneListParam(cfg,sectionKey,'outputDim',self._outputDim)
        self._wInitMode = readCfgIntParam(cfg, sectionKey, 'wInitMode',
                                          self._wInitMode)
        self._wInitOrthogonal = readCfgBooleanParam(cfg, sectionKey,
                                                    'wInitOrthogonal',
                                                    self._wInitOrthogonal)
        self.update()
Exemplo n.º 5
0
    def initFromConfig(self, cfg, sectionKey):
        super(ConvPoolLayerParams, self).initFromConfig(cfg, sectionKey)

        self._inputDim = readCfgIntNoneListParam(cfg, sectionKey, 'inputDim',
                                                 self._inputDim)
        self._nFilters = readCfgIntParam(cfg, sectionKey, 'nFilters',
                                         self._nFilters)
        self._filterDim = readCfgIntNoneListParam(cfg, sectionKey, 'filterDim',
                                                  self._filterDim)
        self._wInitMode = readCfgIntParam(cfg, sectionKey, 'wInitMode',
                                          self._wInitMode)
        self._wInitOrthogonal = readCfgBooleanParam(cfg, sectionKey,
                                                    'wInitOrthogonal',
                                                    self._wInitOrthogonal)
        self._poolType = readCfgIntParam(cfg, sectionKey, 'poolType',
                                         self._poolType)
        self._poolsize = readCfgIntNoneListParam(cfg, sectionKey, 'poolsize',
                                                 self._poolsize)
        self.update()
Exemplo n.º 6
0
    def initFromConfig(self, cfg, sectionKey):
        super(ActivationFunctionLayerParams,
              self).initFromConfig(cfg, sectionKey)

        self._inputDim = readCfgIntNoneListParam(cfg, sectionKey, 'inputDim',
                                                 self._inputDim)

        self._alpha = readCfgFloatParam(cfg, sectionKey, 'alpha', 0.05)
        self._actfStr = readCfgParam(cfg, sectionKey, 'function', '')
        if self._actfs.has_key(self._actfStr):
            self._activation = self._actfs[self._actfStr]

        self.update()
Exemplo n.º 7
0
    def initFromConfig(self, cfg, networkKey='net'):

        self._inputDim = readCfgIntNoneListParam(cfg, networkKey, 'inputDim',
                                                 self._inputDim)

        inputDims = self._inputDim
        if (inputDims is not None) and (not isinstance(inputDims[0],
                                                       collections.Iterable)):
            # single list of dimensions; only one input -> make it a list for easier checking later
            inputDims = [inputDims]

        if inputDims is not None:
            self.batch_size = inputDims[0][0]
        else:
            self.batch_size = None
        #print("DAGNET initFromConfig: batch_size = {}".format(self.batch_size))

        layerNames = readCfgStrListParam(cfg, networkKey, 'layers', [])
        if len(layerNames) == 0:
            raise ValueError(
                "Cannot create a DAGNetwork without a 'layers' definition")

        self.layerCfgs = []
        self.layerCfgsDict = dict()

        for layerName in layerNames:
            layerName = layerName.strip()
            if not cfg.has_section(layerName):
                raise ValueError(
                    "There is no definition for layer '{}' in the config".
                    format(layerName))

            typeName = readCfgParam(cfg, layerName, 'layerType', '')
            LayerParamsClass = self.getLayerParamsClassFromTypeName(typeName)

            # assemble input dims
            layerInputNames = readCfgStrListParam(cfg, layerName, 'inputs', [])
            assert layerInputNames, "No inputs given for layer {}".format(
                layerName)
            for iln in layerInputNames:
                m = re.match("input\[(\d+)\]", iln)
                if m is not None:
                    # input is an input variable of the network
                    inputVarNum = int(m.group(1))
                    if inputVarNum < len(inputDims):
                        inputDim = inputDims[inputVarNum]
                    else:
                        print(
                            "We have no input dim for input var {} (layer {})".
                            format(inputVarNum, layerName))
                else:
                    # input is the output of (a) different layer(s)
                    # check if they are all available
                    assert all(
                        [ln in self.layerCfgsDict for ln in layerInputNames]
                    ), "ERROR: not all input layers in dictionary {} (layer '{}')".format(
                        layerInputNames, layerName)
                    inputDim = [
                        self.layerCfgsDict[iln].outputDim
                        for iln in layerInputNames
                    ]
                    if len(inputDim) == 1:
                        inputDim = inputDim[0]

            print('Layer {} - inputDim = {}'.format(layerName, inputDim))
            layerParams = LayerParamsClass(inputDim=inputDim)
            layerParams.initFromConfig(cfg, layerName)
            self.layerCfgs.append(layerParams)

            self.layerCfgsDict[layerName] = layerParams

        inputLayersNames = readCfgStrListParam(cfg, networkKey, 'inputLayers',
                                               [])
        assert all([iln in self.layerCfgsDict for iln in inputLayersNames
                    ]), "Unknown input layer names {}".format(inputLayersNames)
        self.inputLayerCfgs = [
            self.layerCfgsDict[iln] for iln in inputLayersNames
        ]
        print self.inputLayerCfgs
        assert self.inputLayerCfgs, "ERROR: no input layers defined in DAGNetwork config"

        outputLayerName = readCfgParam(cfg, networkKey, 'outputLayer', '')
        assert outputLayerName in self.layerCfgsDict, "ERROR: Unknown output layer: '{}'".format(
            outputLayerName)
        self.outputLayerCfg = self.layerCfgsDict[outputLayerName]
Exemplo n.º 8
0
 def initFromConfig(self,cfg,sectionKey):
     super(CatLayerParams,self).initFromConfig(cfg,sectionKey)
     self._inputDim = readCfgIntNoneListParam(cfg,sectionKey,'inputDim',self._inputDim)
     self._axis = readCfgIntParam(cfg,sectionKey,'axis',self._axis)
     self.update()