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.Layers.cs 1.5 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Tensorflow.Keras.Engine
  5. {
  6. public partial class Layer
  7. {
  8. public virtual List<ILayer> Layers => _self_tracked_trackables;
  9. protected void StackLayers(params ILayer[] layers)
  10. {
  11. _self_tracked_trackables.AddRange(layers);
  12. }
  13. public virtual Shape ComputeOutputShape(Shape input_shape)
  14. => throw new NotImplementedException("");
  15. protected List<IVariableV1> _gather_children_variables(bool include_trainable = false, bool include_non_trainable = false)
  16. {
  17. List<IVariableV1> res = new();
  18. var nested_layers = _flatten_layers(false, false);
  19. foreach (var layer in nested_layers)
  20. {
  21. if (layer is Layer l)
  22. {
  23. if (include_trainable == true && include_non_trainable == true)
  24. {
  25. res.AddRange(l.Variables);
  26. }
  27. else if (include_trainable == true && include_non_trainable == false)
  28. {
  29. res.AddRange(l.TrainableVariables);
  30. }
  31. else if(include_trainable == false && include_non_trainable == true)
  32. {
  33. res.AddRange(l.NonTrainableVariables);
  34. }
  35. }
  36. }
  37. return res;
  38. }
  39. }
  40. }