Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy deprecation warnings #3768

Merged
merged 1 commit into from
Jun 30, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def _serve_greetings(self, request):
raise werkzeug.exceptions.BadRequest("Must specify run and tag")
try:
data = [
np.asscalar(
tensor_util.make_ndarray(event.tensor_proto)
).decode("utf-8")
tensor_util.make_ndarray(event.tensor_proto)
.item()
.decode("utf-8")
for event in self._multiplexer.Tensors(run, tag)
]
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion tensorboard/plugins/custom_scalar/custom_scalars_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def layout_impl(self):
string_array = tensor_util.make_ndarray(
tensor_events[0].tensor_proto
)
content = np.asscalar(string_array)
content = string_array.item()
layout_proto = layout_pb2.Layout()
layout_proto.ParseFromString(tf.compat.as_bytes(content))

Expand Down
2 changes: 1 addition & 1 deletion tensorboard/plugins/custom_scalar/summary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def testSetLayout(self):

# Parse the data.
string_array = tensor_util.make_ndarray(tensor_events[0].tensor_proto)
content = np.asscalar(string_array)
content = string_array.item()
layout_proto_from_disk = layout_pb2.Layout()
layout_proto_from_disk.ParseFromString(tf.compat.as_bytes(content))

Expand Down
2 changes: 1 addition & 1 deletion tensorboard/plugins/text/text_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def text_array_to_html(text_arr):
"""
if not text_arr.shape:
# It is a scalar. No need to put it in a table, just apply markdown
return plugin_util.markdown_to_safe_html(np.asscalar(text_arr))
return plugin_util.markdown_to_safe_html(text_arr.item())
warning = ""
if len(text_arr.shape) > 2:
warning = plugin_util.markdown_to_safe_html(
Expand Down
30 changes: 16 additions & 14 deletions tensorboard/util/tensor_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def ExtractBitsFromFloat16(x):
return np.asscalar(np.asarray(x, dtype=np.float16).view(np.uint16))
return np.asarray(x, dtype=np.float16).view(np.uint16).item()


def SlowAppendFloat16ArrayToTensorProto(tensor_proto, proto_values):
Expand All @@ -35,8 +35,10 @@ def SlowAppendFloat16ArrayToTensorProto(tensor_proto, proto_values):


def ExtractBitsFromBFloat16(x):
return np.asscalar(
np.asarray(x, dtype=dtypes.bfloat16.as_numpy_dtype).view(np.uint16)
return (
np.asarray(x, dtype=dtypes.bfloat16.as_numpy_dtype)
.view(np.uint16)
.item()
)


Expand All @@ -47,42 +49,42 @@ def SlowAppendBFloat16ArrayToTensorProto(tensor_proto, proto_values):


def SlowAppendFloat32ArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.float_val.extend([np.asscalar(x) for x in proto_values])
tensor_proto.float_val.extend([x.item() for x in proto_values])


def SlowAppendFloat64ArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.double_val.extend([np.asscalar(x) for x in proto_values])
tensor_proto.double_val.extend([x.item() for x in proto_values])


def SlowAppendIntArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.int_val.extend([np.asscalar(x) for x in proto_values])
tensor_proto.int_val.extend([x.item() for x in proto_values])


def SlowAppendInt64ArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.int64_val.extend([np.asscalar(x) for x in proto_values])
tensor_proto.int64_val.extend([x.item() for x in proto_values])


def SlowAppendQIntArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.int_val.extend([np.asscalar(x[0]) for x in proto_values])
tensor_proto.int_val.extend([x[0].item() for x in proto_values])


def SlowAppendUInt32ArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.uint32_val.extend([np.asscalar(x) for x in proto_values])
tensor_proto.uint32_val.extend([x.item() for x in proto_values])


def SlowAppendUInt64ArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.uint64_val.extend([np.asscalar(x) for x in proto_values])
tensor_proto.uint64_val.extend([x.item() for x in proto_values])


def SlowAppendComplex64ArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.scomplex_val.extend(
[np.asscalar(v) for x in proto_values for v in [x.real, x.imag]]
[v.item() for x in proto_values for v in [x.real, x.imag]]
)


def SlowAppendComplex128ArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.dcomplex_val.extend(
[np.asscalar(v) for x in proto_values for v in [x.real, x.imag]]
[v.item() for x in proto_values for v in [x.real, x.imag]]
)


Expand All @@ -91,7 +93,7 @@ def SlowAppendObjectArrayToTensorProto(tensor_proto, proto_values):


def SlowAppendBoolArrayToTensorProto(tensor_proto, proto_values):
tensor_proto.bool_val.extend([np.asscalar(x) for x in proto_values])
tensor_proto.bool_val.extend([x.item() for x in proto_values])


_NP_TO_APPEND_FN = {
Expand Down Expand Up @@ -455,7 +457,7 @@ def make_tensor_proto(values, dtype=None, shape=None, verify_shape=False):
raise ValueError(
"Cannot create a tensor proto whose content is larger than 2GB."
)
tensor_proto.tensor_content = nparray.tostring()
tensor_proto.tensor_content = nparray.tobytes()
return tensor_proto

# If we were not given values as a numpy array, compute the proto_values
Expand Down