Skip to content

Commit

Permalink
Add loss conversion from uint16 to float in progressbar class
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrekobi committed Jan 25, 2022
1 parent 2bf9b84 commit 059e84c
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 059e84c

Please sign in to comment.