Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions python/paddle/hapi/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import sys
import time
import numpy as np
import struct
from collections import namedtuple

__all__ = []
Expand Down Expand Up @@ -79,6 +80,19 @@ def start(self):
def update(self, current_num, values={}):
now = time.time()

def convert_uint16_to_float(in_list):
in_list = np.asarray(in_list)
out = np.vectorize(
lambda x: struct.unpack('<f', struct.pack('<I', x << 16))[0],
otypes=[np.float32])(in_list.flat)
return np.reshape(out, in_list.shape)

for i, (k, val) in enumerate(values):
if k == "loss":
val = val if isinstance(val, list) else [val]
if isinstance(val[0], np.uint16):
values[i] = ("loss", list(convert_uint16_to_float(val)))

if current_num:
time_per_unit = (now - self._start) / current_num
else:
Expand Down
1 change: 1 addition & 0 deletions python/paddle/tests/test_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def prog_bar(self, num, epoch, width, verbose=1):
progbar.update(1, [['loss', 1e-4]])
progbar.update(1, [['loss', np.array([1.])]])
progbar.update(1, [['loss', np.array([1e-4])]])
progbar.update(1, [['loss', np.array([1]).astype(np.uint16)]])
progbar.start()

progbar.update(0, values)
Expand Down