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:
parent
99372b6016
commit
0d14b76790
tensorflow/python
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user