| @@ -115,8 +115,8 @@ namespace Tensorflow | |||||
| public Tensor relu(Tensor features, string name = null) => gen_nn_ops.relu(features, name); | public Tensor relu(Tensor features, string name = null) => gen_nn_ops.relu(features, name); | ||||
| public Tensor[] fused_batch_norm(Tensor x, | public Tensor[] fused_batch_norm(Tensor x, | ||||
| RefVariable scale, | |||||
| RefVariable offset, | |||||
| VariableV1 scale, | |||||
| VariableV1 offset, | |||||
| Tensor mean = null, | Tensor mean = null, | ||||
| Tensor variance = null, | Tensor variance = null, | ||||
| float epsilon = 0.001f, | float epsilon = 0.001f, | ||||
| @@ -37,8 +37,8 @@ namespace Tensorflow.Keras.Layers | |||||
| private IInitializer gamma_initializer; | private IInitializer gamma_initializer; | ||||
| private IInitializer moving_mean_initializer; | private IInitializer moving_mean_initializer; | ||||
| private IInitializer moving_variance_initializer; | private IInitializer moving_variance_initializer; | ||||
| private RefVariable gamma; | |||||
| private RefVariable beta; | |||||
| private VariableV1 gamma; | |||||
| private VariableV1 beta; | |||||
| private RefVariable moving_mean; | private RefVariable moving_mean; | ||||
| private RefVariable moving_variance; | private RefVariable moving_variance; | ||||
| @@ -95,7 +95,7 @@ namespace Tensorflow.Keras.Layers | |||||
| var param_shape = new int[] { input_shape.dims[axis[0]] }; | var param_shape = new int[] { input_shape.dims[axis[0]] }; | ||||
| if (scale) | if (scale) | ||||
| gamma = (RefVariable)add_weight("gamma", | |||||
| gamma = add_weight("gamma", | |||||
| param_shape, | param_shape, | ||||
| dtype: param_dtype, | dtype: param_dtype, | ||||
| initializer: gamma_initializer, | initializer: gamma_initializer, | ||||
| @@ -104,7 +104,7 @@ namespace Tensorflow.Keras.Layers | |||||
| throw new NotImplementedException("add_weight gamma"); | throw new NotImplementedException("add_weight gamma"); | ||||
| if (center) | if (center) | ||||
| beta = (RefVariable)add_weight("beta", | |||||
| beta = add_weight("beta", | |||||
| param_shape, | param_shape, | ||||
| dtype: param_dtype, | dtype: param_dtype, | ||||
| initializer: beta_initializer, | initializer: beta_initializer, | ||||
| @@ -32,36 +32,21 @@ namespace Tensorflow.Keras.Utils | |||||
| /// <param name="initializer"></param> | /// <param name="initializer"></param> | ||||
| /// <param name="trainable"></param> | /// <param name="trainable"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public static RefVariable make_variable(string name, | |||||
| public static VariableV1 make_variable(string name, | |||||
| int[] shape, | int[] shape, | ||||
| TF_DataType dtype = TF_DataType.TF_FLOAT, | TF_DataType dtype = TF_DataType.TF_FLOAT, | ||||
| IInitializer initializer = null, | IInitializer initializer = null, | ||||
| bool trainable = true) => make_variable(name, shape, dtype, initializer, trainable, true); | |||||
| /// <summary> | |||||
| /// Adds a new variable to the layer. | |||||
| /// </summary> | |||||
| /// <param name="name"></param> | |||||
| /// <param name="shape"></param> | |||||
| /// <param name="dtype"></param> | |||||
| /// <param name="initializer"></param> | |||||
| /// <param name="trainable"></param> | |||||
| /// <returns></returns> | |||||
| public static RefVariable make_variable(string name, | |||||
| int[] shape, | |||||
| TF_DataType dtype = TF_DataType.TF_FLOAT, | |||||
| IInitializer initializer = null, | |||||
| bool trainable = true, | |||||
| bool use_resource = true) | |||||
| bool trainable = true) | |||||
| { | { | ||||
| var initializing_from_value = false; | var initializing_from_value = false; | ||||
| bool use_resource = true; | |||||
| ops.init_scope(); | ops.init_scope(); | ||||
| Func<Tensor> init_val = () => initializer.call(new TensorShape(shape), dtype: dtype); | Func<Tensor> init_val = () => initializer.call(new TensorShape(shape), dtype: dtype); | ||||
| var variable_dtype = dtype.as_base_dtype(); | var variable_dtype = dtype.as_base_dtype(); | ||||
| var v = tf.Variable(init_val); | |||||
| var v = tf.VariableV1(init_val); | |||||
| return v; | return v; | ||||
| } | } | ||||
| @@ -97,9 +97,9 @@ namespace Tensorflow | |||||
| /// <param name="is_training"></param> | /// <param name="is_training"></param> | ||||
| /// <param name="name"></param> | /// <param name="name"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public static Tensor[] fused_batch_norm(Tensor x, | |||||
| RefVariable scale, | |||||
| RefVariable offset, | |||||
| public static Tensor[] fused_batch_norm(Tensor x, | |||||
| VariableV1 scale, | |||||
| VariableV1 offset, | |||||
| Tensor mean, | Tensor mean, | ||||
| Tensor variance, | Tensor variance, | ||||
| float epsilon = 0.001f, | float epsilon = 0.001f, | ||||
| @@ -58,6 +58,21 @@ namespace Tensorflow | |||||
| dtype: dtype); | dtype: dtype); | ||||
| } | } | ||||
| public VariableV1 VariableV1<T>(T data, | |||||
| bool trainable = true, | |||||
| bool validate_shape = true, | |||||
| string name = null, | |||||
| TF_DataType dtype = TF_DataType.DtInvalid, | |||||
| bool use_resource = false) | |||||
| { | |||||
| return Tensorflow.variable_scope.default_variable_creator(data, | |||||
| trainable: trainable, | |||||
| validate_shape: validate_shape, | |||||
| name: name, | |||||
| dtype: dtype, | |||||
| use_resource: use_resource); | |||||
| } | |||||
| public unsafe Tensor placeholder(TF_DataType dtype, TensorShape shape = null, string name = null) | public unsafe Tensor placeholder(TF_DataType dtype, TensorShape shape = null, string name = null) | ||||
| { | { | ||||
| return gen_array_ops.placeholder(dtype, shape, name); | return gen_array_ops.placeholder(dtype, shape, name); | ||||