@@ -38,7 +38,7 @@ public InputLayer(InputLayerArgs args) :
3838 {
3939 this . args = args ;
4040 built = true ;
41- this . SupportsMasking = true ;
41+ SupportsMasking = true ;
4242
4343 if ( BatchInputShape != null )
4444 {
@@ -58,6 +58,9 @@ public InputLayer(InputLayerArgs args) :
5858 args . DType = args . InputTensor == null ? tf . float32 : args . InputTensor . dtype ;
5959 }
6060
61+ // In graph mode, create a graph placeholder to call the layer on.
62+ tf . Context . graph_mode ( ) ;
63+
6164 if ( args . InputTensor == null )
6265 {
6366 if ( args . InputShape != null )
@@ -71,15 +74,13 @@ public InputLayer(InputLayerArgs args) :
7174 args . BatchInputShape = null ;
7275 }
7376
74- // In graph mode, create a graph placeholder to call the layer on.
75- tf . Context . graph_mode ( ) ;
7677 args . InputTensor = tf . keras . backend . placeholder (
77- shape : BatchInputShape ,
78- dtype : DType ,
79- name : Name ,
80- sparse : args . Sparse ,
81- ragged : args . Ragged ) ;
82- tf . Context . eager_mode ( ) ;
78+ shape : BatchInputShape ,
79+ dtype : DType ,
80+ name : Name ,
81+ sparse : args . Sparse ,
82+ ragged : args . Ragged ) ;
83+
8384
8485 isPlaceholder = true ;
8586 }
@@ -97,6 +98,8 @@ public InputLayer(InputLayerArgs args) :
9798 typeSpec = new TensorSpec ( args . InputTensor . TensorShape ,
9899 dtype : args . InputTensor . dtype ,
99100 name : Name ) ;
101+
102+ tf . Context . restore_mode ( ) ;
100103 }
101104 }
102105}
0 commit comments