Example #1
0
    def forwardSize(self, inputsize):
        # [size1, size2, size3], size: (32,1,28,28)
        # print("conv2d.size: {}, {}, {}".format(inputsize,self.mapMulti, self.inputFeature))
        isize = inputsize[0]

        if len(isize) != 4:
            raise IndexError
        if self.mapMulti is None and isize[1] != self.inputFeature:
            raise IndexError

        if self.mapMulti is not None:
            self.inputFeature = isize[1]
            self.outputFeature = int(self.inputFeature * self.mapMulti)

        weightIniter = winit.XavierInit()
        initweight = weightIniter.initialize(
            (self.outputFeature, self.inputFeature, *self.filterSize))
        initbias = np.zeros((self.outputFeature, ))
        self.w = theano.shared(initweight, borrow=True)
        self.b = theano.shared(initbias, borrow=True)

        retSize = None
        if self.border == 'half':
            retSize = [(isize[0], self.outputFeature,
                        int(isize[2] / self.subsample[0]),
                        int(isize[3] / self.subsample[1]))]
        else:
            raise NotImplementedError

        return retSize
Example #2
0
    def forwardSize(self, inputsize):
        isize = inputsize[0]

        if len(isize) != 4:
            raise AssertionError('Conv input size should has a lenght of 4')
        if self.inputFeature is not None and isize[1] != self.inputFeature:
            raise AssertionError('Conv put feature map size does not match')

        if self.outputFeature is not None:
            self.inputFeature = isize[1]
            self.mapMulti = self.outputFeature / self.inputFeature
        elif self.mapMulti is not None:
            self.inputFeature = isize[1]
            self.outputFeature = int(self.inputFeature * self.mapMulti)

        weightIniter = winit.XavierInit()
        initweight = weightIniter.initialize(
            (self.outputFeature, self.inputFeature, *self.filterSize))
        initbias = floatX(np.zeros((self.outputFeature, )))
        self.w = theano.shared(initweight, borrow=True)
        self.b = theano.shared(initbias, borrow=True)

        retSize = None
        if self.border == 'half':
            retSize = [(isize[0], self.outputFeature,
                        int(isize[2] / self.subsample[0]),
                        int(isize[3] / self.subsample[1]))]
        else:
            raise NotImplementedError

        return retSize
    def forwardSize(self, inputsize):

        #print(inputsize)
        #print(self.inputFeature)
        isize = inputsize[0]

        if len(isize) != 2:
            raise IndexError('Expect input dimension 2, get ' +
                             str(len(isize)))
        if self.inputFeature is not None and isize[1] != self.inputFeature:
            raise IndexError('Input size: ' + str(isize[1]) +
                             ' is not equal to given input feature dim: ' +
                             str(self.inputFeature))

        if self.inputFeature is None:
            self.inputFeature = isize[1]

        if self.outputFeature is None:
            self.outputFeature = self.inputFeature * self.mapMulti

        weightIniter = winit.XavierInit()
        initweight = weightIniter.initialize(
            (self.inputFeature, self.outputFeature))
        self.w = theano.shared(initweight, borrow=True)
        initbias = np.zeros((self.outputFeature, ))
        self.b = theano.shared(initbias, borrow=True)

        return [(
            isize[0],
            self.outputFeature,
        )]
Example #4
0
    def __init__(self, times=None, output=None, input_feature=None, output_feature=None):
        super(FullConn, self).__init__()
        if times is not None:
            self.times = times
        if output is not None:
            self.output = output

        weightIniter = winit.XavierInit()
        initweight = weightIniter.initialize((input_feature, output_feature))
        self.w = theano.shared(initweight, borrow=True)

        self.inputFeature = input_feature
        self.outputFeature = output_feature
        
        self.times = -1
        self.output = -1