| 69 | self._start = time.time() |
| 70 | |
| 71 | def update(self, current_num, values={}): |
| 72 | now = time.time() |
| 73 | |
| 74 | def convert_uint16_to_float(in_list): |
| 75 | in_list = np.asarray(in_list) |
| 76 | out = np.vectorize( |
| 77 | lambda x: struct.unpack('<f', struct.pack('<I', x << 16))[0], |
| 78 | otypes=[np.float32], |
| 79 | )(in_list.flat) |
| 80 | return np.reshape(out, in_list.shape) |
| 81 | |
| 82 | for i, (k, val) in enumerate(values): |
| 83 | if k == "loss": |
| 84 | if isinstance(val, list): |
| 85 | scalar_val = val[0] |
| 86 | else: |
| 87 | scalar_val = val |
| 88 | if isinstance(scalar_val, np.uint16): |
| 89 | values[i] = ("loss", list(convert_uint16_to_float(val))) |
| 90 | |
| 91 | if current_num: |
| 92 | time_per_unit = (now - self._start) / current_num |
| 93 | else: |
| 94 | time_per_unit = 0 |
| 95 | |
| 96 | if time_per_unit >= 1 or time_per_unit == 0: |
| 97 | fps = f' - {time_per_unit:.0f}s/{self.name}' |
| 98 | elif time_per_unit >= 1e-3: |
| 99 | fps = f' - {time_per_unit * 1e3:.0f}ms/{self.name}' |
| 100 | else: |
| 101 | fps = f' - {time_per_unit * 1e6:.0f}us/{self.name}' |
| 102 | |
| 103 | info = '' |
| 104 | if self._verbose == 1: |
| 105 | prev_total_width = self._total_width |
| 106 | |
| 107 | if self._dynamic_display: |
| 108 | sys.stdout.write('\b' * prev_total_width) |
| 109 | sys.stdout.write('\r') |
| 110 | else: |
| 111 | sys.stdout.write('\n') |
| 112 | |
| 113 | if self._num is not None: |
| 114 | numdigits = int(np.log10(self._num)) + 1 |
| 115 | |
| 116 | bar_chars = (self.name + ' %' + str(numdigits) + 'd/%d [') % ( |
| 117 | current_num, |
| 118 | self._num, |
| 119 | ) |
| 120 | prog = float(current_num) / self._num |
| 121 | prog_width = int(self._width * prog) |
| 122 | |
| 123 | if prog_width > 0: |
| 124 | bar_chars += '=' * (prog_width - 1) |
| 125 | if current_num < self._num: |
| 126 | bar_chars += '>' |
| 127 | else: |
| 128 | bar_chars += '=' |