brainstorm/training/trainer.py
def train(self, net, training_data_iter, **named_data_iters):
        """
        Train a network using a data iterator and further named data
        iterators.
        """
        if self.verbose:
            print('\n\n', 10 * '- ', "Before Training", 10 * ' -')
        assert set(training_data_iter.data_shapes.keys()) == set(
            net.buffer.Input.outputs.keys()), \
            "The data names provided by the training data iterator {} do not "\
            "map to the network input names {}".format(
                training_data_iter.data_shapes.keys(),
                net.buffer.Input.outputs.keys())
        self.stepper.start(net)
        named_data_iters['training_data_iter'] = training_data_iter
        self._start_hooks(net, named_data_iters)
        if self._emit_hooks(net, 'update') or self._emit_hooks(net, 'epoch'):
            return

        should_stop = False
        while not should_stop:
            self.current_epoch_nr += 1
            sys.stdout.flush()
            train_scores = {s.__name__: [] for s in self.train_scorers}
            train_scores.update({n: [] for n in net.get_loss_values()})

            if self.verbose:
                print('\n\n', 12 * '- ', "Epoch", self.current_epoch_nr,
                      12 * ' -')
            iterator = training_data_iter(handler=net.handler)
            for _ in run_network(net, iterator):
                self.current_update_nr += 1
                self.stepper.run()
                gather_losses_and_scores(net, self.train_scorers, train_scores)
                net.apply_weight_modifiers()
                if self._emit_hooks(net, 'update'):
                    should_stop = True
                    break

            self._add_log('rolling_training',
                          aggregate_losses_and_scores(train_scores, net,
                                                      self.train_scorers))

            should_stop |= self._emit_hooks(net, 'epoch')

        Train a network using a data iterator and further named data
        iterators.
        
Train a network using a data iterator and further named data
iterators.
Train a network using a data iterator and further named data iterators .
def train(self, net, training_data_iter, **named_data_iters):
        if self.verbose:
            print('\n\n', 10 * '- ', "Before Training", 10 * ' -')
        assert set(training_data_iter.data_shapes.keys()) == set(
            net.buffer.Input.outputs.keys()), \
            "The data names provided by the training data iterator {} do not "\
            "map to the network input names {}".format(
                training_data_iter.data_shapes.keys(),
                net.buffer.Input.outputs.keys())
        self.stepper.start(net)
        named_data_iters['training_data_iter'] = training_data_iter
        self._start_hooks(net, named_data_iters)
        if self._emit_hooks(net, 'update') or self._emit_hooks(net, 'epoch'):
            return
        should_stop = False
        while not should_stop:
            self.current_epoch_nr += 1
            sys.stdout.flush()
            train_scores = {s.__name__: [] for s in self.train_scorers}
            train_scores.update({n: [] for n in net.get_loss_values()})
            if self.verbose:
                print('\n\n', 12 * '- ', "Epoch", self.current_epoch_nr,
                      12 * ' -')
            iterator = training_data_iter(handler=net.handler)
            for _ in run_network(net, iterator):
                self.current_update_nr += 1
                self.stepper.run()
                gather_losses_and_scores(net, self.train_scorers, train_scores)
                net.apply_weight_modifiers()
                if self._emit_hooks(net, 'update'):
                    should_stop = True
                    break
            self._add_log('rolling_training',
                          aggregate_losses_and_scores(train_scores, net,
                                                      self.train_scorers))
            should_stop |= self._emit_hooks(net, 'epoch')
def train ( self , net , training_data_iter , ** named_data_iters ) : if self . verbose : print ( '\n\n' , 10 * '- ' , "Before Training" , 10 * ' -' ) assert set ( training_data_iter . data_shapes . keys ( ) ) == set ( net . buffer . Input . outputs . keys ( ) ) , "The data names provided by the training data iterator {} do not " "map to the network input names {}" . format ( training_data_iter . data_shapes . keys ( ) , net . buffer . Input . outputs . keys ( ) ) self . stepper . start ( net ) named_data_iters [ 'training_data_iter' ] = training_data_iter self . _start_hooks ( net , named_data_iters ) if self . _emit_hooks ( net , 'update' ) or self . _emit_hooks ( net , 'epoch' ) : return should_stop = False while not should_stop : self . current_epoch_nr += 1 sys . stdout . flush ( ) train_scores = { s . __name__ : [ ] for s in self . train_scorers } train_scores . update ( { n : [ ] for n in net . get_loss_values ( ) } ) if self . verbose : print ( '\n\n' , 12 * '- ' , "Epoch" , self . current_epoch_nr , 12 * ' -' ) iterator = training_data_iter ( handler = net . handler ) for _ in run_network ( net , iterator ) : self . current_update_nr += 1 self . stepper . run ( ) gather_losses_and_scores ( net , self . train_scorers , train_scores ) net . apply_weight_modifiers ( ) if self . _emit_hooks ( net , 'update' ) : should_stop = True break self . _add_log ( 'rolling_training' , aggregate_losses_and_scores ( train_scores , net , self . train_scorers ) ) should_stop |= self . _emit_hooks ( net , 'epoch' )
Train a network using a data iterator and further named data
iterators.
Train a network using a data iterator and further named data iterators .
"""
        Train a network using a data iterator and further named data
        iterators.
        """
self
net
training_data_iter