예제 #1
0
    def __init__(self):
        print("Model define Start ! ")

        folder = "models/"

        nfilters_embeded = int(64)
        nlayers_embeded = int(4)
        nfilters_cloud = int(64)
        nlayers_cloud = int(4)
        branchweight = float(0.1)
        lr = numpy.float64(0.001)
        nepochs = int(80)
        ent_T = numpy.float64(0.4)
        name = str("cifar10_64f_4l")

        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))

        branch = Sequential()
        branch.add(BinaryLinearBNSoftmax(None, 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, output_dims))
        model.build()

        chain = Chain(branchweight=branchweight, ent_T=ent_T)
        chain.add_sequence(model)
        chain.setup_optimizers('adam', lr)

        print("Model define Over ! ")

        ##################################Skip the training ##################################################

        ##################################Load the model after training by other code #########################

        print("Loading model Start ! ")
        #name = self.get_name(**kwargs)
        #path = '{}/{}'.format(self.folder,name)
        #epoch = int(kwargs.get("nepochs",2))
        #fn = "{}/chain_snapshot_epoch_{:06}".format(path,epoch)
        #cf = os.path.dirname(os.path.abspath(__file__))
        fn = "models/test_cifar10/cifar10_64f_4l/epoch_000080"
        #ph = cf + fn
        #print "path %s" % (ph)
        S.load_npz(fn, chain)
        self.chain = chain
        print("Loading model Over ! ")
예제 #2
0
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, output_dims))
model.build()

chain = Chain(branchweight=branchweight, ent_T=ent_T)
chain.add_sequence(model)
chain.setup_optimizers('adam', lr)

print("Model define Over ! ")

##################################Skip the training ##################################################

##################################Load the model after training by other code #########################

print("Loading model Start ! ")
#name = self.get_name(**kwargs)
#path = '{}/{}'.format(self.folder,name)
#epoch = int(kwargs.get("nepochs",2))
#fn = "{}/chain_snapshot_epoch_{:06}".format(path,epoch)
fn = "models/test_cifar10/cifar10_64f_4l/chain_snapshot_epoch_000080"

S.load_npz(fn, chain)