Don't produce sparse to dense conversion warning for VariableShape dense shapes.

Also update a test for constant_value.

PiperOrigin-RevId: 328746670
Change-Id: Id596988df2b49e01654ea25b9184c5457ffa2c8c
This commit is contained in:
A. Unique TensorFlower 2020-08-27 09:00:25 -07:00 committed by TensorFlower Gardener
parent 99372b6016
commit 0d14b76790
2 changed files with 10 additions and 5 deletions
tensorflow/python

View File

@ -429,9 +429,12 @@ def _indexed_slices_to_tensor(value, dtype=None, name=None, as_ref=False):
"elements. This may consume a large amount of memory." %
num_elements)
else:
warnings.warn(
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
"This may consume a large amount of memory.")
if value.dense_shape.op.type != "VariableShape":
# VariableShape may hide static shapes behind a resource handle
# producing a warning that isn't that useful to users.
warnings.warn(
"Converting sparse IndexedSlices(%s) to a dense Tensor of unknown "
"shape. This may consume a large amount of memory." % value)
return math_ops.unsorted_segment_sum(
value.values, value.indices, value.dense_shape[0], name=name)

View File

@ -169,10 +169,12 @@ class ResourceVariableOpsTest(test_util.TensorFlowTestCase,
@test_util.run_in_graph_and_eager_modes
def testVariableShape(self):
v = resource_variable_ops.ResourceVariable([1., 1.])
vshape = resource_variable_ops.variable_shape(v.handle)
self.assertAllEqual(
tensor_util.constant_value(
resource_variable_ops.variable_shape(v.handle)),
tensor_util.constant_value(vshape),
[2])
if not context.executing_eagerly():
self.assertEqual("Const", vshape.op.type)
@test_util.run_deprecated_v1
def testDifferentAssignGraph(self):