diff --git a/tensorflow/python/framework/indexed_slices.py b/tensorflow/python/framework/indexed_slices.py index 45f6e254b0e..b1e1e20fc2e 100644 --- a/tensorflow/python/framework/indexed_slices.py +++ b/tensorflow/python/framework/indexed_slices.py @@ -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) diff --git a/tensorflow/python/kernel_tests/resource_variable_ops_test.py b/tensorflow/python/kernel_tests/resource_variable_ops_test.py index 9a927b86d0b..83fdfc7a33b 100644 --- a/tensorflow/python/kernel_tests/resource_variable_ops_test.py +++ b/tensorflow/python/kernel_tests/resource_variable_ops_test.py @@ -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):