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.

utils.cs 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using Tensorflow.Keras.Engine;
  4. namespace Tensorflow.Keras.Saving.SavedModel;
  5. public partial class KerasSavedModelUtils
  6. {
  7. public static bool ShouldHaveTraces { get; internal set; } = true;
  8. public static SaveOptionsContext keras_option_scope(bool save_traces)
  9. {
  10. var res = new SaveOptionsContext(ShouldHaveTraces);
  11. ShouldHaveTraces = save_traces;
  12. return res;
  13. }
  14. public static IEnumerable<ILayer> list_all_layers(Layer layer)
  15. {
  16. if(layer is Model)
  17. {
  18. return (layer as Model).Layers;
  19. }
  20. else
  21. {
  22. return new List<ILayer>(layer._flatten_layers(false, false));
  23. }
  24. }
  25. }
  26. /// <summary>
  27. /// Implementation of this class is different with that of python.
  28. /// But it could be used with `using` the same as `with` of python.
  29. /// </summary>
  30. public class SaveOptionsContext: IDisposable
  31. {
  32. public bool _old_value;
  33. public SaveOptionsContext(bool old_value)
  34. {
  35. _old_value = old_value;
  36. }
  37. public void Dispose()
  38. {
  39. KerasSavedModelUtils.ShouldHaveTraces = _old_value;
  40. }
  41. }