Exemplo n.º 1
0
    loss_cache = 10
    for epoch in xrange(1, total_epoch + 1):
        print 'Epoch: {}/{}'.format(epoch, total_epoch)

        # Training (Mini-batch)
        now = time.time()
        data.shuffle()
        bar = Bar(max_value=n)
        bar.cursor.clear_lines(2)  # Make some room
        bar.cursor.save()  # Mark starting line
        for _ in xrange(data.batch_run()):
            net.input(data.next_batch())
            net.forward()
            net.backward(lr, beta_1, beta_2, epoch)
            bar.cursor.restore()  # Return cursor to start
            bar.draw(value=data.get_count())
        t = time.time() - now
        acc, loss = net.get_record()
        loss_avg = np.array(loss).mean()
        loss_diff = loss_avg - loss_cache
        loss_cache = loss_avg
        print 'Acc:    ', np.array(acc).mean()
        print 'Loss:   ', loss_avg
        print 'Time:   ', t
        f, b = net.get_profile()
        net.clear_record()

        bar_t = Bar(max_value=nt)
        bar_t.cursor.clear_lines(2)  # Make some room
        bar_t.cursor.save()  # Mark starting line
        for _ in xrange(data.batch_run_test()):