progress_bar.py 1.1 KB
Newer Older
A
Amirsina Torfi 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
import sys


def print_progress(progress, epoch_num, loss):
    """
    This function draw an active progress bar.
    :param progress: Where we are:
                       type: float
                       value: [0,1]
    :param epoch_num: number of epochs for training
    :param loss: The loss for the specific batch in training phase.

    :return: Progressing bar
    """

    # Define the length of bar
    barLength = 30

    # Ceck the input!
    assert type(progress) is float, "id is not a float: %r" % id
    assert 0 <= progress <= 1, "variable should be between zero and one!"

    # Empty status while processing.
    status = ""

    # This part is to make a new line when the process is finished.
    if progress >= 1:
        progress = 1
        status = "\r\n"

    # Where we are in the progress!
    indicator = int(round(barLength*progress))

    # Print the appropriate progress phase!
    list = [str(epoch_num), "#"*indicator , "-"*(barLength-indicator), progress*100, loss, status]
    text = "\rEpoch {0[0]} {0[1]} {0[2]} %{0[3]:.2f} loss={0[4]:.3f} {0[5]}".format(list)
    sys.stdout.write(text)
    sys.stdout.flush()