예제 #1
0
    def train_model(self, trainset, testset, **kwargs):
        chain, model = self.setup_chain_model(**kwargs)

        nepochs = int(kwargs.get("nepochs", 2))
        ent_T = kwargs.get("ent_T", None)
        name = self.get_name(**kwargs)

        reports = [
            'epoch', 'validation/main/branch0accuracy',
            'validation/main/branch1accuracy',
            'validation/main/branch2accuracy',
            'validation/main/branch3accuracy',
            'validation/main/branch4accuracy',
            'validation/main/branch5accuracy',
            'validation/main/branch6accuracy',
            'validation/main/branch7accuracy',
            'validation/main/branch8accuracy', 'validation/main/accuracy',
            'validation/main/communication0', 'validation/main/communication1',
            'validation/main/memory', 'validation/main/ent_T',
            'validation/main/branch0exit', 'validation/main/branch1exit',
            'validation/main/branch2exit'
        ]
        trainer = Trainer('{}/{}'.format(self.folder, name),
                          chain,
                          trainset,
                          testset,
                          batchsize=self.batchsize,
                          nepoch=nepochs,
                          resume=self.resume,
                          reports=reports)
        trainer.run()

        return trainer, model, chain
예제 #2
0
    def train_model(self, trainset, testset, **kwargs):
        chain, model = self.setup_chain_model(**kwargs)

        nepochs = int(kwargs.get("nepochs", 2))
        name = self.get_name(**kwargs)

        reports = [
            'validation/main/branch0accuracy',
            'validation/main/branch1accuracy',
            'validation/main/branch2accuracy',
            'validation/main/branch3accuracy',
            'validation/main/branch4accuracy',
            'validation/main/branch5accuracy',
            'validation/main/branch6accuracy',
            'validation/main/branch7accuracy'
        ]
        trainer = Trainer('{}/{}'.format(self.folder, name),
                          chain,
                          trainset,
                          testset,
                          batchsize=self.batchsize,
                          nepoch=nepochs,
                          resume=self.resume,
                          reports=reports)
        trainer.run()

        return trainer, model
예제 #3
0
    def train_model(self, trainset, testset, **kwargs):
        chain, model = self.setup_chain_model(**kwargs)

        nepochs = int(kwargs.get("nepochs", 2))
        name = self.get_name(**kwargs)

        trainer = Trainer('{}/{}'.format(self.folder,name), chain, trainset,
                          testset, nepoch=nepochs, resume=True)
        trainer.run()

        return trainer, model, chain
예제 #4
0
    def train_model(self, trainset, testset, **kwargs):
        chain, model = self.setup_chain_model(**kwargs)

        nepochs = int(kwargs.get("nepochs", 2))
        ent_T = kwargs.get("ent_T", None)
        name = self.get_name(**kwargs)

        reports = [
            'epoch', 'main/loss', 'main/accuracy', 'validation/main/accuracy',
            'validation/main/memory'
        ]
        trainer = Trainer('{}/{}'.format(self.folder, name),
                          chain,
                          trainset,
                          testset,
                          batchsize=self.batchsize,
                          nepoch=nepochs,
                          resume=True,
                          reports=reports)
        trainer.run()

        return trainer, model, chain
예제 #5
0
    def train_model(self, trainset, testset, **kwargs):
        chain, model = self.setup_chain_model(**kwargs)

        nepochs = int(kwargs.get("nepochs", 2))
        pretrain_nepochs = int(kwargs.get("pretrain_nepochs", 20))
        name = self.get_name(**kwargs)

        # Train stage 0
        trainer = Trainer('{}/{}'.format(self.folder,"pretrained_" + name), chain, trainset,
                          testset, nepoch=pretrain_nepochs, resume=True)
        model.set_current_stage(0)
        trainer.run()
        
        # Load from stage 0 iinstead since optimize might keep some stages
        # Train stage 1
        chain.cleargrads()
        lr = kwargs.get("lr", 0.001)
        chain.setup_optimizers('adam', lr)
        trainer = Trainer('{}/{}'.format(self.folder,name), chain, trainset,
                          testset, nepoch=nepochs, resume=True)
        model.set_current_stage(1)
        trainer.run()
        return trainer, model
예제 #6
0
chain = Chain(branchweight =branchweight )
chain.add_sequence(model)
chain.setup_optimizers('adam', lr)

#for i in xrange(100):
#	y = chain(x)
#	loss = F.mean_squared_error(x, y)
#	chain.backprop(loss)
#	print float(loss.data)
#
#chain.save("model")


trainset, testset = chainer.datasets.get_mnist(ndim=3)

trainer = Trainer('{}/{}'.format(folder,name), chain, trainset, testset, nepoch=nepochs, resume=True)
trainer.run()

#y = Variable(chain)
#y = chain(x)


#g = c.build_computational_graph(chain)
#with open('graph.dot', 'w') as o:
#    o.write(g.dump())

#with open('graph.dot', 'w') as o:
#        g = computational_graph.build_computational_graph((y, ))
#        o.write(g.dump())