Ejemplo n.º 1
0
        trainer.step(batch_size)
        acc_mtc.update(labels, outputs)
        loss_mtc.update(0, losses)

        if (it % opt.save_frequency) == 0:
            _, train_loss = loss_mtc.get()
            train_metric_name, train_acc = acc_mtc.get()
            toc = time.time()

            logger.info(
                '\nEpoch[%d] Batch[%d]\tSpeed: %f samples/sec\t%s=%f\tlr=%f train loss: %.6f'
                % (epoch, it, batch_size * opt.save_frequency /
                   (toc - tic), train_metric_name, train_acc,
                   trainer.learning_rate, train_loss))

            acc_list = validate(logger, net, ctx, val_datas, targets, epoch,
                                it)

            # save flags
            do_save = False
            is_highest = False
            # check if save or not
            if len(acc_list) > 0:
                score = sum(acc_list)
                if acc_list[-1] >= highest_acc[-1]:
                    if acc_list[-1] > highest_acc[-1]:
                        is_highest = True
                    else:
                        if score >= highest_acc[0]:
                            is_highest = True
                            highest_acc[0] = score
                    highest_acc[-1] = acc_list[-1]
Ejemplo n.º 2
0
        for l in losses:
            ag.backward(l)

        trainer.step(batch_size)
        acc_mtc.update(labels, outputs)
        loss_mtc.update(0, losses)

        if (it % save_period) == 0 and it != 0:
            _, train_loss = loss_mtc.get()
            _, train_acc = acc_mtc.get()
            toc = time.time()
            logger.info(
                '\n[epoch % 2d] [it % 3d] train loss: %.6f, train_acc: %.6f | '
                'speed: %.2f samples/s, time: %.6f' %
                (epoch, it, train_loss, train_acc, batch_size /
                 (toc - btic), toc - tic))
            logger.info("Radius {}".format(
                loss.R.data(ctx=mx.gpu(0)).asscalar()))
            results = validate(net, ctx, val_datas, targets)
            for result in results:
                logger.info('{}'.format(result))
            loss_mtc.reset()
            acc_mtc.reset()
            tic = time.time()
            net.save_parameters(
                "../../models/mobilefacenet-ring-it-%d.params" % it)
        btic = time.time()
        it += 1
    epoch += 1
    dali_iter.reset()