Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 7 additions & 6 deletions smdebug/core/reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ def get_basic_numpy_reduction(reduction_name, numpy_data):
return getattr(np, reduction_name)(numpy_data)
elif reduction_name in ALLOWED_NORMS:
if reduction_name in ["l1", "l2"]:
ord = int(reduction_name[1])
order = int(reduction_name[1])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed this variable, since ord conflicts with the python built-in

else:
ord = None
order = None

if abs:
rv = np.linalg.norm(np.absolute(numpy_data), ord=ord)
else:
rv = np.linalg.norm(numpy_data, ord=ord)
if np.isscalar(numpy_data):
# np.linalg.norm expects array-like inputs
# but numpy_data can sometimes be a scalar value
numpy_data = [numpy_data]
rv = np.linalg.norm(numpy_data, ord=order)
return rv
return None

Expand Down
2 changes: 2 additions & 0 deletions smdebug/tensorflow/base_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ def _make_numpy_array(tensor_value):

@staticmethod
def _get_reduction_of_data(reduction_name, tensor_value, tensor_name, abs):
if hasattr(tensor_value, "numpy"):
tensor_value = tensor_value.numpy()
return get_numpy_reduction(reduction_name, tensor_value, abs)

def add_to_collection(self, collection_name, variable):
Expand Down