예제 #1
0
def update_training_scores_history(perf_scores_history, model, loss, epoch,
                                   num_best_scores):
    """ Update the list of top training scores achieved so far, and log the best scores so far"""

    model_sparsity, _, params_nnz_cnt = distiller.model_params_stats(model)
    perf_scores_history.append(
        distiller.MutableNamedTuple({
            'params_nnz_cnt': -params_nnz_cnt,
            'sparsity': model_sparsity,
            'loss': loss,
            'epoch': epoch
        }))

    # Keep perf_scores_history sorted from best to worst
    # Sort by sparsity as main sort key, then sort by top1, top5 and epoch

    def key(entry):
        return (
            entry['params_nnz_cnt'],
            -entry['loss'],
            entry['epoch'],
        )

    perf_scores_history.sort(key=key, reverse=True)
    for score in perf_scores_history[:num_best_scores]:
        msglogger.info(
            '==> Best [Loss: %.3f   Sparsity:%.2f   Params: %d on epoch: %d]',
            score.loss, score.sparsity, -score.params_nnz_cnt, score.epoch)
예제 #2
0
def update_training_scores_history(perf_scores_history, model, top1, top5, epoch, num_best_scores):
    """ Update the list of top training scores achieved so far, and log the best scores so far"""

    model_sparsity, _, params_nnz_cnt = distiller.model_params_stats(model)
    perf_scores_history.append(distiller.MutableNamedTuple({'params_nnz_cnt': -params_nnz_cnt,
                                                            'sparsity': model_sparsity,
                                                            'top1': top1, 'top5': top5, 'epoch': epoch}))
    # Keep perf_scores_history sorted from best to worst
    # Sort by sparsity as main sort key, then sort by top1, top5 and epoch
    perf_scores_history.sort(key=operator.attrgetter('params_nnz_cnt', 'top1', 'top5', 'epoch'), reverse=True)
    for score in perf_scores_history[:num_best_scores]:
        msglogger.info('==> Best [Top1: %.3f   Top5: %.3f   Sparsity:%.2f   Params: %d on epoch: %d]',
                       score.top1, score.top5, score.sparsity, -score.params_nnz_cnt, score.epoch)
 def step(self, model, epoch, **kwargs):
     assert all(score in kwargs.keys() for score in ('top1', 'top5'))
     model_sparsity, _, params_nnz_cnt = distiller.model_params_stats(model)
     self.perf_scores_history.append(distiller.MutableNamedTuple({
         'params_nnz_cnt': -params_nnz_cnt,
         'sparsity': model_sparsity,
         'top1': kwargs['top1'],
         'top5': kwargs['top5'],
         'epoch': epoch}))
     # Keep perf_scores_history sorted from best to worst
     self.perf_scores_history.sort(
         key=operator.attrgetter('top1', 'top5', 'params_nnz_cnt', 'epoch'),
         reverse=True)