Exemple #1
0
    def generate_model(self, **kwargs):
        nfilters_embeded_last = int(kwargs.get("nfilters_embeded_last", 1))
        nfilters_embeded = int(kwargs.get("nfilters_embeded", 1))
        nlayers_embeded = int(kwargs.get("nlayers_embeded", 1))

        input_model = Sequential()
        for i in range(nlayers_embeded):
            if i == 0:
                nfilters = self.input_dims
                input_model.add(
                    ConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1,
                                  1))
            elif i == nlayers_embeded - 1:
                nfilters = nfilters_embeded
                input_model.add(
                    BinaryConvPoolBNBST(nfilters, nfilters_embeded_last, 3, 1,
                                        1, 3, 1, 1))
            else:
                nfilters = nfilters_embeded
                input_model.add(
                    BinaryConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3,
                                        1, 1))
        input_model.add(BinaryLinearBNSoftmax(None, self.output_dims))

        input_model.build()
        return input_model
Exemple #2
0
    def generate_model(self, **kwargs):
        nfilters_embeded = int(kwargs.get("nfilters_embeded", 1))
        nlayers_embeded = int(kwargs.get("nlayers_embeded", 1))

        model = Sequential()
        for i in range(nlayers_embeded):
            if i == 0:
                nfilters = self.input_dims
            else:
                nfilters = nfilters_embeded
            model.add(Convolution2D(nfilters, nfilters_embeded, 3, 1, 1))
            model.add(max_pooling_2d(3, 1, 1))
            model.add(BatchNormalization(nfilters_embeded))
            model.add(Activation('bst'))

        model.add(Linear(None, self.output_dims))

        model.build()
        return model
    def generate_model(self, **kwargs):
        nfilters_embeded = int(kwargs.get("nfilters_embeded", 1))
        nlayers_embeded = int(kwargs.get("nlayers_embeded", 1))
        nfilters_cloud = int(kwargs.get("nfilters_cloud", 1))
        nlayers_cloud = int(kwargs.get("nlayers_cloud", 1))

        for key, value in kwargs.iteritems():
            print key, value

        input_model = Sequential()
        for i in range(nlayers_embeded):
            if i == 0:
                nfilters = self.input_dims
                input_model.add(
                    ConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1,
                                  1))
            else:
                nfilters = nfilters_embeded
                input_model.add(
                    BinaryConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3,
                                        1, 1))
        branch = Sequential()
        branch.add(BinaryLinearBNSoftmax(None, self.output_dims))
        input_model.add(branch)

        model = MultiInputSequential(self.ninputs)
        for i in range(self.ninputs):
            model.add_input(input_model)

        # float branch
        for i in range(nlayers_cloud):
            if i == 0:
                nfilters = self.ninputs * nfilters_embeded
            else:
                nfilters = nfilters_cloud
            model.add(Convolution2D(nfilters, nfilters_cloud, 3, 1, 1))
            model.add(max_pooling_2d(3, 1, 1))
            model.add(BatchNormalization(nfilters_cloud))
            model.add(Activation('bst'))
            # Note: should we move pool to before batch norm like in binary?
        model.add(Linear(None, self.output_dims))
        model.add(BatchNormalization(self.output_dims))

        model.build()
        return model
Exemple #4
0
    def generate_model(self, **kwargs):
        nfilters_embeded = int(kwargs.get("nfilters_embeded", 1))
        nlayers_embeded = int(kwargs.get("nlayers_embeded", 1))
        #print('test print kwargs.get(nfilters_embeded) ',nfilters_embeded)
        #print('test print kwargs.get(nlayers_embeded) ',nlayers_embeded)
        model = Sequential()
        for i in range(nlayers_embeded):
            if i == 0:
                nfilters = self.input_dims
                model.add(
                    ConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1,
                                  1))
                # model.add(ConvBNBST(nfilters, nfilters_embeded, 3, 1, 1))
            else:
                nfilters = nfilters_embeded
                model.add(
                    BinaryConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3,
                                        1, 1))
                # model.add(BinaryConvBNBST(nfilters, nfilters_embeded, 3, 1, 1))

        model.add(BinaryLinearBNSoftmax(None, self.output_dims))
        model.build()
        return model
Exemple #5
0
    def generate_model(self, **kwargs):
        nfilters_embeded_last = int(kwargs.get("nfilters_embeded_last", 1))
        nfilters_embeded = int(kwargs.get("nfilters_embeded", 1))
        nlayers_embeded = int(kwargs.get("nlayers_embeded", 1))
        nfilters_cloud = int(kwargs.get("nfilters_cloud", 1))
        nlayers_cloud = int(kwargs.get("nlayers_cloud", 1))
        nfilters_edge = int(kwargs.get("nfilters_edge", 1))
        nlayers_edge = int(kwargs.get("nlayers_edge", 1))

        input_model = Sequential()
        if nlayers_embeded == 1:
            nfilters_embeded_last = nfilters_embeded
        for i in range(nlayers_embeded):
            if i == 0:
                nfilters = self.input_dims
                input_model.add(
                    ConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 2,
                                  1))
            elif i == nlayers_embeded - 1:
                nfilters = nfilters_embeded
                input_model.add(
                    BinaryConvPoolBNBST(nfilters, nfilters_embeded_last, 3, 1,
                                        1, 3, 2, 1))
            else:
                nfilters = nfilters_embeded
                input_model.add(
                    BinaryConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3,
                                        2, 1))
        branch = Sequential()
        branch.add(BinaryLinearBNSoftmax(None, self.output_dims))
        input_model.add(branch)

        model = MultiInputSequential(self.ninputs,
                                     merge_function=self.merge_function)
        for i in range(self.ninputs):
            model.add_input(input_model)

        # Local branch
        local_branch = Sequential()
        #local_branch.add(Linear(None, self.output_dims))
        #local_branch.add(BatchNormalization(self.output_dims))
        if self.merge_function in [
                'concat', 'concat_avg_pool', 'concat_max_pool'
        ]:
            local_branch.add(BinaryLinearBNSoftmax(None, self.output_dims))
        model.add_local(local_branch)

        # Edge branches
        #for i in range(nlayers_edge):
        #    if i == 0:
        #        if 'concat' in self.merge_function:
        #            nfilters = self.ninputs*nfilters_embeded_last
        #        else:
        #            nfilters = nfilters_embeded_last
        #    else:
        #        nfilters = nfilters_edge
        #    model.add(BinaryConvPoolBNBST(nfilters, nfilters_edge, 3, 1, 1, 3, 1, 1))
        #
        #    #model.add(Convolution2D(nfilters, nfilters_edge, 3, 1, 1))
        #    #model.add(Activation('relu'))
        #    #model.add(max_pooling_2d(3,1,1))
        #    #model.add(BatchNormalization(nfilters_edge))
        #    #model.add(Activation('relu'))
        #    # Note: should we move pool to before batch norm like in binary?
        #
        #edge_branch = Sequential()
        ##edge_branch.add(Linear(None, self.output_dims))
        ##edge_branch.add(BatchNormalization(self.output_dims))
        #edge_branch.add(BinaryLinearBNSoftmax(None, self.output_dims))
        #model.add(edge_branch)

        # Cloud branches
        for i in range(nlayers_cloud):
            if i == 0:
                if self.merge_function in [
                        'concat', 'avg_pool_concat', 'max_pool_concat'
                ]:
                    nfilters = self.ninputs * nfilters_embeded_last
                else:
                    nfilters = nfilters_embeded_last
            else:
                nfilters = nfilters_cloud
            model.add(
                BinaryConvPoolBNBST(nfilters, nfilters_cloud, 3, 1, 1, 3, 1,
                                    1))

            #model.add(Convolution2D(nfilters, nfilters_cloud, 3, 1, 1))
            #model.add(Activation('relu'))
            #model.add(max_pooling_2d(3,1,1))
            #model.add(BatchNormalization(nfilters_cloud))
            #model.add(Activation('relu'))
            # Note: should we move pool to before batch norm like in binary?
        #model.add(Linear(None, self.output_dims))
        #model.add(BatchNormalization(self.output_dims))
        model.add(BinaryLinearBNSoftmax(None, self.output_dims))

        model.build()
        return model
#nlayers_cloud = int(2)
branchweight = numpy.float64(0.1)
ent_T = numpy.int64(100)
lr = numpy.float64(0.001)
nepochs = int(60)
name = str("cifar10_10f_end")

input_dims = 3
output_dims = 10

model = Sequential()

for i in range(nlayers_embeded):
    if i == 0:
        nfilters = input_dims
        model.add(ConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1, 1))
    else:
        nfilters = nfilters_embeded
        model.add(
            BinaryConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1, 1))

model.add(BinaryLinearBNSoftmax(None, output_dims))

# float branch
#for i in range(nlayers_cloud):
#    if i == 0:
#        nfilters = nfilters_embeded
#    else:
#        nfilters = nfilters_cloud
#    model.add(Convolution2D(nfilters, nfilters_cloud, 3, 1, 1))
#    model.add(max_pooling_2d(3,1,1))
Exemple #7
0
# seq.add(function.Activation("relu"))
# seq.add(link.Deconvolution2D(32, 16, ksize=4, stride=2, pad=paddings.pop(0), use_weightnorm=True))
# seq.add(link.BatchNormalization(16))
# seq.add(function.Activation("relu"))
# seq.add(link.Deconvolution2D(16, 3, ksize=4, stride=2, pad=paddings.pop(0), use_weightnorm=True))
# seq.build()

# y = seq(x)
# print y.data.shape

# train test
x = np.random.normal(scale=1, size=(128, 28 * 28)).astype(np.float32)
x = Variable(x)

seq = Sequential(weight_initializer="GlorotNormal", weight_init_std=0.05)
seq.add(Linear(28 * 28, 500, use_weightnorm=True))
seq.add(BatchNormalization(500))
seq.add(Activation("relu"))
seq.add(Linear(None, 500, use_weightnorm=True))
seq.add(BatchNormalization(500))
seq.add(Activation("relu"))
seq.add(Linear(500, 28 * 28, use_weightnorm=True))
seq.build()

chain = Chain()
chain.add_sequence(seq)
chain.setup_optimizers("adam",
                       0.001,
                       momentum=0.9,
                       weight_decay=0.000001,
                       gradient_clipping=10)
Exemple #8
0
    def generate_model(self, **kwargs):
        nfilters_embeded = int(kwargs.get("nfilters_embeded", 1))
        nlayers_embeded = int(kwargs.get("nlayers_embeded", 1))
        nfilters_cloud = int(kwargs.get("nfilters_cloud", 1))
        nlayers_cloud = int(kwargs.get("nlayers_cloud", 1))

        model = Sequential()
        for i in range(nlayers_embeded):
            if i == 0:
                nfilters = self.input_dims
            else:
                nfilters = nfilters_embeded
            model.add(Convolution2D(nfilters, nfilters_embeded, 3, 1, 1))
            model.add(max_pooling_2d(3, 1, 1))
            model.add(BatchNormalization(nfilters_embeded))
            model.add(Activation('bst'))

        branch = Sequential()
        branch.add(Linear(None, self.output_dims))
        branch.add(BatchNormalization(self.output_dims))

        model.add(branch)

        # float branch
        for i in range(nlayers_cloud):
            if i == 0:
                nfilters = nfilters_embeded
            else:
                nfilters = nfilters_cloud
            model.add(Convolution2D(nfilters, nfilters_cloud, 3, 1, 1))
            model.add(max_pooling_2d(3, 1, 1))
            model.add(BatchNormalization(nfilters_cloud))
            model.add(Activation('bst'))
            # Note: should we move pool to before batch norm like in binary?
        model.add(Linear(None, self.output_dims))
        model.add(BatchNormalization(self.output_dims))

        model.build()
        return model
Exemple #9
0
folder = "_models/test_seq"

nfilters_embeded = int(2)
nlayers_embeded = int(1)
nfilters_cloud = int(2)
nlayers_cloud = int(1)
branchweight = int(3)
lr = numpy.float64(0.001)
nepochs = int(10)
name = str("_lr_0.001_nfilters_embeded_2_nlayers_embeded_1.0")

model = Sequential()

nfilters = 1
model.add(ConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1, 1))
#model.add(ConvBNBST(nfilters, nfilters_embeded, 3, 1, 1))
nfilters = nfilters_embeded
model.add(BinaryConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1, 1))
#model.add(BinaryConvBNBST(nfilters, nfilters_embeded, 3, 1, 1))


branch = Sequential()
branch.add(BinaryLinearBNSoftmax(None, 10))
model.add(branch)

############################ Embeded network ##############################

nfilters = nfilters_embeded
model.add(Convolution2D(nfilters, nfilters_embeded, 3, 1, 1))
model.add(BatchNormalization(nfilters_embeded))
Exemple #10
0
    def generate_model(self, **kwargs):
        nfilters_embeded = int(kwargs.get("nfilters_embeded", 1))
        nlayers_embeded = int(kwargs.get("nlayers_embeded", 1))
        nfilters_cloud = int(kwargs.get("nfilters_cloud", 1))
        nlayers_cloud = int(kwargs.get("nlayers_cloud", 1))

        model = Sequential()
        for i in range(nlayers_embeded):
            if i == 0:
                nfilters = self.input_dims
                model.add(
                    ConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3, 1,
                                  1))
            else:
                nfilters = nfilters_embeded
                model.add(
                    BinaryConvPoolBNBST(nfilters, nfilters_embeded, 3, 1, 1, 3,
                                        1, 1))

        branch = Sequential()
        branch.add(BinaryLinearBNSoftmax(None, self.output_dims))
        model.add(branch)

        for i in range(nlayers_cloud):
            if i == 0:
                nfilters = nfilters_embeded
            else:
                nfilters = nfilters_cloud
            model.add(Convolution2D(nfilters, nfilters_cloud, 3, 1, 1))
            model.add(BatchNormalization(nfilters_cloud))
            model.add(Activation('relu'))
            model.add(max_pooling_2d(3, 1, 1))
        model.add(Linear(None, self.output_dims))
        model.build()
        return model