Skip to content

Commit

Permalink
bugfix: logger, don't import numpy unless required
Browse files Browse the repository at this point in the history
  • Loading branch information
torzdf committed Mar 21, 2024
1 parent 9ddc838 commit aaa63ff
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from datetime import datetime

import numpy as np


# TODO - Remove this monkey patch when TF autograph fixed to handle newer logging lib
def _patched_format(self, record):
Expand Down Expand Up @@ -561,10 +559,16 @@ def _process_value(value: T.Any) -> T.Any:
"""
if isinstance(value, str):
return f'"{value}"'
if isinstance(value, np.ndarray) and np.prod(value.shape) > 10:
return f'[type: "{type(value).__name__}" shape: {value.shape}, dtype: "{value.dtype}"]'
if isinstance(value, (list, tuple, set)) and len(value) > 10:
return f'[type: "{type(value).__name__}" len: {len(value)}'

try:
import numpy as np
except ImportError:
return value

if isinstance(value, np.ndarray) and np.prod(value.shape) > 10:
return f'[type: "{type(value).__name__}" shape: {value.shape}, dtype: "{value.dtype}"]'
return value


Expand Down

0 comments on commit aaa63ff

Please sign in to comment.