Layers bind to a graph when first called, not at __init__.
authorA. Unique TensorFlower <gardener@tensorflow.org>
Tue, 6 Mar 2018 20:04:06 +0000 (12:04 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Tue, 6 Mar 2018 20:08:30 +0000 (12:08 -0800)
PiperOrigin-RevId: 188059096

tensorflow/python/layers/base_test.py

index 91b8988..1ee9ec7 100644 (file)
@@ -643,6 +643,16 @@ class BaseLayerTest(test.TestCase):
     self.assertEqual(len(layer.get_losses_for([intermediate_inputs])), 1)
     self.assertEqual(len(layer.get_losses_for([outputs])), 0)
 
+  def testLayerGraphSetInFirstApply(self):
+    with ops.Graph().as_default():
+      layer = core_layers.Dense(1)  # Graph at construction time is ignored
+    with ops.Graph().as_default():
+      layer.apply(constant_op.constant([[1]]))
+      # layer is now bound to second Graph
+    with ops.Graph().as_default(), self.assertRaisesRegexp(
+        ValueError, 'Input graph and Layer graph are not the same'):
+      layer.apply(constant_op.constant([[1]]))
+
 
 if __name__ == '__main__':
   test.main()