You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Layer.Apply.cs 2.2 kB

4 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Threading;
  2. using Tensorflow.Common.Types;
  3. using static Tensorflow.Binding;
  4. namespace Tensorflow.Keras.Engine
  5. {
  6. public partial class Layer
  7. {
  8. /// <summary>
  9. /// Wraps `call`, applying pre- and post-processing steps.
  10. /// </summary>
  11. /// <param name="inputs"></param>
  12. /// <param name="state"></param>
  13. /// <param name="training"></param>
  14. /// <returns></returns>
  15. public virtual Tensors Apply(Tensors inputs, Tensors states = null, bool training = false, IOptionalArgs? optional_args = null)
  16. {
  17. if (callContext.Value == null)
  18. callContext.Value = new CallContext();
  19. if (_in_functional_construction_mode(inputs))
  20. return FunctionalConstructionCall(inputs);
  21. var eager = tf.executing_eagerly();
  22. using var ctxManager = CallContext.enter(build_graph: false);
  23. string nameScope = eager ? name : _name_scope();
  24. var scope = ops.name_scope(nameScope);
  25. scope.__enter__();
  26. if (!built)
  27. MaybeBuild(inputs);
  28. <<<<<<< HEAD
  29. <<<<<<< HEAD
  30. var outputs = Call(inputs, state: states, training: training);
  31. =======
  32. var outputs = Call(inputs, initial_state: state, training: training);
  33. >>>>>>> master
  34. =======
  35. var outputs = Call(inputs, state: states, training: training);
  36. >>>>>>> 90a65d7d98b92f26574ac32392ed802a57d4d2c8
  37. // memory leak
  38. // _set_connectivity_metadata_(inputs, outputs);
  39. _handle_activity_regularization(inputs, outputs);
  40. _set_mask_metadata(inputs, outputs, null);
  41. scope.__exit__();
  42. return outputs;
  43. }
  44. // TODO(Rinne): remove it and completely fix issue 1084
  45. [Obsolete]
  46. private bool _enforce_layer_construction = false;
  47. [Obsolete]
  48. internal void enforce_layer_construction()
  49. {
  50. _enforce_layer_construction = true;
  51. }
  52. [Obsolete]
  53. internal void unset_layer_construction()
  54. {
  55. _enforce_layer_construction = false;
  56. }
  57. }
  58. }