| @@ -66,20 +66,20 @@ namespace Tensorflow | |||||
| /// <summary> | /// <summary> | ||||
| /// Initializer capable of adapting its scale to the shape of weights tensors. | /// Initializer capable of adapting its scale to the shape of weights tensors. | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="scale"></param> | |||||
| /// <param name="factor"></param> | |||||
| /// <param name="mode"></param> | /// <param name="mode"></param> | ||||
| /// <param name="distribution"></param> | /// <param name="distribution"></param> | ||||
| /// <param name="seed"></param> | /// <param name="seed"></param> | ||||
| /// <param name="dtype"></param> | /// <param name="dtype"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public IInitializer variance_scaling_initializer(float scale = 1.0f, | |||||
| string mode = "fan_in", | |||||
| string distribution = "truncated_normal", | |||||
| public IInitializer variance_scaling_initializer(float factor = 1.0f, | |||||
| string mode = "FAN_IN", | |||||
| bool uniform = false, | |||||
| int? seed = null, | int? seed = null, | ||||
| TF_DataType dtype = TF_DataType.TF_FLOAT) => new VarianceScaling( | TF_DataType dtype = TF_DataType.TF_FLOAT) => new VarianceScaling( | ||||
| scale: scale, | |||||
| factor: factor, | |||||
| mode: mode, | mode: mode, | ||||
| distribution: distribution, | |||||
| uniform: uniform, | |||||
| seed: seed, | seed: seed, | ||||
| dtype: dtype); | dtype: dtype); | ||||
| } | } | ||||
| @@ -28,21 +28,21 @@ namespace Tensorflow | |||||
| /// <param name="seed"></param> | /// <param name="seed"></param> | ||||
| /// <param name="name"></param> | /// <param name="name"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public Tensor random_normal(int[] shape, | |||||
| public Tensor random_normal(TensorShape shape, | |||||
| float mean = 0.0f, | float mean = 0.0f, | ||||
| float stddev = 1.0f, | float stddev = 1.0f, | ||||
| TF_DataType dtype = TF_DataType.TF_FLOAT, | TF_DataType dtype = TF_DataType.TF_FLOAT, | ||||
| int? seed = null, | int? seed = null, | ||||
| string name = null) => random_ops.random_normal(shape, mean, stddev, dtype, seed, name); | string name = null) => random_ops.random_normal(shape, mean, stddev, dtype, seed, name); | ||||
| public Tensor random_uniform(int[] shape, | |||||
| public Tensor random_uniform(TensorShape shape, | |||||
| float minval = 0, | float minval = 0, | ||||
| float maxval = 1, | float maxval = 1, | ||||
| TF_DataType dtype = TF_DataType.TF_FLOAT, | TF_DataType dtype = TF_DataType.TF_FLOAT, | ||||
| int? seed = null, | int? seed = null, | ||||
| string name = null) => random_ops.random_uniform(shape, minval, maxval, dtype, seed, name); | string name = null) => random_ops.random_uniform(shape, minval, maxval, dtype, seed, name); | ||||
| public Tensor truncated_normal(int[] shape, | |||||
| public Tensor truncated_normal(TensorShape shape, | |||||
| float mean = 0.0f, | float mean = 0.0f, | ||||
| float stddev = 1.0f, | float stddev = 1.0f, | ||||
| TF_DataType dtype = TF_DataType.TF_FLOAT, | TF_DataType dtype = TF_DataType.TF_FLOAT, | ||||
| @@ -62,5 +62,8 @@ namespace Tensorflow | |||||
| /// </returns> | /// </returns> | ||||
| public Tensor random_shuffle(Tensor value, int? seed = null, string name = null) | public Tensor random_shuffle(Tensor value, int? seed = null, string name = null) | ||||
| => random_ops.random_shuffle(value, seed: seed, name: name); | => random_ops.random_shuffle(value, seed: seed, name: name); | ||||
| public void set_random_seed(int seed) | |||||
| => ops.get_default_graph().seed = seed; | |||||
| } | } | ||||
| } | } | ||||
| @@ -273,6 +273,9 @@ namespace Tensorflow | |||||
| return sum; | return sum; | ||||
| } | } | ||||
| public static double sum(IEnumerable<int> enumerable) | |||||
| => enumerable.Sum(); | |||||
| public static double sum<TKey, TValue>(Dictionary<TKey, TValue> values) | public static double sum<TKey, TValue>(Dictionary<TKey, TValue> values) | ||||
| { | { | ||||
| return sum(values.Keys); | return sum(values.Keys); | ||||
| @@ -1,4 +1,6 @@ | |||||
| namespace Tensorflow.Data | |||||
| using System; | |||||
| namespace Tensorflow.Data | |||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| /// Represents a potentially large set of elements. | /// Represents a potentially large set of elements. | ||||
| @@ -11,5 +13,9 @@ | |||||
| /// </summary> | /// </summary> | ||||
| public class DatasetV2 | public class DatasetV2 | ||||
| { | { | ||||
| public static DatasetV2 from_generator() | |||||
| { | |||||
| throw new NotImplementedException(""); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -107,6 +107,16 @@ namespace Tensorflow | |||||
| public bool building_function; | public bool building_function; | ||||
| int _seed; | |||||
| public int seed | |||||
| { | |||||
| get => _seed; | |||||
| set | |||||
| { | |||||
| _seed = value; | |||||
| } | |||||
| } | |||||
| public Graph() | public Graph() | ||||
| { | { | ||||
| _handle = c_api.TF_NewGraph(); | _handle = c_api.TF_NewGraph(); | ||||
| @@ -27,7 +27,7 @@ namespace Tensorflow.Keras | |||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public IInitializer he_normal(int? seed = null) | public IInitializer he_normal(int? seed = null) | ||||
| { | { | ||||
| return new VarianceScaling(scale: 2.0f, mode: "fan_in", distribution: "truncated_normal", seed: seed); | |||||
| return new VarianceScaling(factor: 2.0f, mode: "fan_in", seed: seed); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -22,7 +22,10 @@ namespace Tensorflow.Operations.Initializers | |||||
| string mode = "fan_avg", | string mode = "fan_avg", | ||||
| string distribution = "uniform", | string distribution = "uniform", | ||||
| int? seed = null, | int? seed = null, | ||||
| TF_DataType dtype = TF_DataType.TF_FLOAT) : base(scale, mode, distribution, seed, dtype) | |||||
| TF_DataType dtype = TF_DataType.TF_FLOAT) : base(factor: scale, | |||||
| mode: mode, | |||||
| seed: seed, | |||||
| dtype: dtype) | |||||
| { | { | ||||
| } | } | ||||
| @@ -31,17 +31,22 @@ namespace Tensorflow.Operations.Initializers | |||||
| protected int? _seed; | protected int? _seed; | ||||
| protected TF_DataType _dtype; | protected TF_DataType _dtype; | ||||
| public VarianceScaling(float scale = 1.0f, | |||||
| string mode = "fan_in", | |||||
| string distribution = "truncated_normal", | |||||
| public VarianceScaling(float factor = 2.0f, | |||||
| string mode = "FAN_IN", | |||||
| bool uniform = false, | |||||
| int? seed = null, | int? seed = null, | ||||
| TF_DataType dtype = TF_DataType.TF_FLOAT) | TF_DataType dtype = TF_DataType.TF_FLOAT) | ||||
| { | { | ||||
| if (scale < 0) | |||||
| if (!dtype.is_floating()) | |||||
| throw new TypeError("Cannot create initializer for non-floating point type."); | |||||
| if (!new string[] { "FAN_IN", "FAN_OUT", "FAN_AVG" }.Contains(mode)) | |||||
| throw new TypeError($"Unknown {mode} %s [FAN_IN, FAN_OUT, FAN_AVG]"); | |||||
| if (factor < 0) | |||||
| throw new ValueError("`scale` must be positive float."); | throw new ValueError("`scale` must be positive float."); | ||||
| _scale = scale; | |||||
| _scale = factor; | |||||
| _mode = mode; | _mode = mode; | ||||
| _distribution = distribution; | |||||
| _seed = seed; | _seed = seed; | ||||
| _dtype = dtype; | _dtype = dtype; | ||||
| } | } | ||||