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.

tf.init.cs 4.4 kB

6 years ago
4 years ago
5 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*****************************************************************************
  2. Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ******************************************************************************/
  13. using Tensorflow.Operations.Initializers;
  14. namespace Tensorflow
  15. {
  16. public partial class tensorflow
  17. {
  18. public InitializersImpl initializers { get; } = new InitializersImpl();
  19. public IInitializer constant_initializer<T>(T value, TF_DataType dtype = TF_DataType.TF_FLOAT, bool verify_shape = false)
  20. => new Constant<T>(value, dtype: dtype, verify_shape: verify_shape);
  21. public IInitializer zeros_initializer => new Zeros();
  22. public IInitializer ones_initializer => new Ones();
  23. public IInitializer glorot_uniform_initializer => new GlorotUniform();
  24. public IInitializer random_uniform_initializer => new RandomUniform();
  25. public IInitializer orthogonal_initializer => new Orthogonal();
  26. public variable_scope variable_scope(string name,
  27. string default_name = null,
  28. Tensor[] values = null,
  29. bool? reuse = null,
  30. bool auxiliary_name_scope = true) => new variable_scope(name,
  31. default_name,
  32. values,
  33. reuse: reuse,
  34. auxiliary_name_scope: auxiliary_name_scope);
  35. public variable_scope variable_scope(VariableScope scope,
  36. string default_name = null,
  37. Tensor[] values = null,
  38. bool? reuse = null,
  39. bool auxiliary_name_scope = true) => new variable_scope(scope,
  40. default_name,
  41. values,
  42. reuse: reuse,
  43. auxiliary_name_scope: auxiliary_name_scope);
  44. public IInitializer truncated_normal_initializer(float mean = 0.0f,
  45. float stddev = 1.0f,
  46. int? seed = null,
  47. TF_DataType dtype = TF_DataType.DtInvalid) => new TruncatedNormal(mean: mean,
  48. stddev: stddev,
  49. seed: seed,
  50. dtype: dtype);
  51. public IInitializer random_normal_initializer(float mean = 0.0f,
  52. float stddev = 1.0f,
  53. int? seed = null,
  54. TF_DataType dtype = TF_DataType.DtInvalid) => new RandomNormal(mean: mean,
  55. stddev: stddev,
  56. seed: seed,
  57. dtype: dtype);
  58. /// <summary>
  59. /// Initializer capable of adapting its scale to the shape of weights tensors.
  60. /// </summary>
  61. /// <param name="factor"></param>
  62. /// <param name="mode"></param>
  63. /// <param name="uniform"></param>
  64. /// <param name="seed"></param>
  65. /// <param name="dtype"></param>
  66. /// <returns></returns>
  67. public IInitializer variance_scaling_initializer(float factor = 1.0f,
  68. string mode = "fan_in",
  69. string distribution = "truncated_normal",
  70. int? seed = null,
  71. TF_DataType dtype = TF_DataType.TF_FLOAT) => new VarianceScaling(
  72. scale: factor,
  73. mode: mode,
  74. distribution: distribution,
  75. seed: seed,
  76. dtype: dtype);
  77. public class InitializersImpl
  78. {
  79. public IInitializer random_normal_initializer(float mean = 0.0f,
  80. float stddev = 0.05f,
  81. int? seed = null,
  82. TF_DataType dtype = TF_DataType.TF_FLOAT) => new RandomNormal(mean: mean,
  83. stddev: stddev,
  84. seed: seed,
  85. dtype: dtype);
  86. public IInitializer zeros_initializer(Shape shape = null,
  87. TF_DataType dtype = TF_DataType.TF_FLOAT) => new Zeros(shape: shape,
  88. dtype: dtype);
  89. }
  90. }
  91. }