@@ -75,7 +75,7 @@ public static Tensor convert_to_tensor(object value, TF_DataType dtype = TF_Data
7575 return val ;
7676 default :
7777 var nd = tensor_util . convert_to_numpy_ndarray ( value ) ;
78- return constant_op . Constant ( nd , name ) ;
78+ return constant_op . constant ( nd , name ) ;
7979 }
8080 }
8181
@@ -240,12 +240,34 @@ private static void _colocate_with_for_gradient(Operation op, int? gradient_uid,
240240 /// of numpy ndarrays that each correspond to the respective element in
241241 /// "tensors".
242242 /// </returns>
243- public static NDArray [ ] _eval_using_default_session ( Tensor [ ] tensors , dynamic feed_dict , Graph graph , Session session = null )
243+ public static NDArray _eval_using_default_session ( Tensor tensor , Dictionary < Tensor , NDArray > feed_dict , Graph graph , Session session = null )
244244 {
245245 if ( session == null )
246+ {
246247 session = get_default_session ( ) ;
247248
248- return null ;
249+ if ( session == null )
250+ throw new ValueError ( "Cannot evaluate tensor using `eval()`: No default " +
251+ "session is registered. Use `with " +
252+ "sess.as_default()` or pass an explicit session to " +
253+ "`eval(session=sess)`" ) ;
254+
255+ if ( session . graph != graph )
256+ throw new ValueError ( "Cannot use the default session to evaluate tensor: " +
257+ "the tensor's graph is different from the session's " +
258+ "graph. Pass an explicit session to " +
259+ "`eval(session=sess)`." ) ;
260+ }
261+ else
262+ {
263+ if ( session . graph != graph )
264+ throw new ValueError ( "Cannot use the default session to evaluate tensor: " +
265+ "the tensor's graph is different from the session's " +
266+ "graph. Pass an explicit session to " +
267+ "`eval(session=sess)`." ) ;
268+ }
269+
270+ return session . run ( tensor , feed_dict ) ;
249271 }
250272
251273 /// <summary>
@@ -254,7 +276,7 @@ public static NDArray[] _eval_using_default_session(Tensor[] tensors, dynamic fe
254276 /// <returns>The default `Session` being used in the current thread.</returns>
255277 public static Session get_default_session ( )
256278 {
257- return null ;
279+ return tf . Session ( ) ;
258280 }
259281 }
260282}
0 commit comments