Browse Source

change "bool training" => "bool? training"

the bool to tensor has a bug, if in init the training is False, the program not start.
tags/v0.110.4-Transformer-Model
dogvane 2 years ago
parent
commit
fa213eb54c
5 changed files with 10 additions and 6 deletions
  1. +1
    -1
      src/TensorFlowNET.Core/Keras/Layers/ILayer.cs
  2. +1
    -1
      src/TensorFlowNET.Core/Operations/NnOps/RNNCell.cs
  3. +1
    -1
      src/TensorFlowNET.Keras/Engine/Layer.Apply.cs
  4. +6
    -2
      src/TensorFlowNET.Keras/Engine/Model.Fit.cs
  5. +1
    -1
      src/TensorFlowNET.Keras/Layers/Rnn/RNN.cs

+ 1
- 1
src/TensorFlowNET.Core/Keras/Layers/ILayer.cs View File

@@ -15,7 +15,7 @@ namespace Tensorflow.Keras
List<ILayer> Layers { get; }
List<INode> InboundNodes { get; }
List<INode> OutboundNodes { get; }
Tensors Apply(Tensors inputs, Tensors states = null, bool training = false, IOptionalArgs? optional_args = null);
Tensors Apply(Tensors inputs, Tensors states = null, bool? training = false, IOptionalArgs? optional_args = null);
List<IVariableV1> TrainableVariables { get; }
List<IVariableV1> TrainableWeights { get; }
List<IVariableV1> NonTrainableWeights { get; }


+ 1
- 1
src/TensorFlowNET.Core/Operations/NnOps/RNNCell.cs View File

@@ -145,7 +145,7 @@ namespace Tensorflow
throw new NotImplementedException("_zero_state_tensors");
}

public Tensors Apply(Tensors inputs, Tensors state = null, bool is_training = false, IOptionalArgs? optional_args = null)
public Tensors Apply(Tensors inputs, Tensors state = null, bool? is_training = false, IOptionalArgs? optional_args = null)
{
throw new NotImplementedException();
}


+ 1
- 1
src/TensorFlowNET.Keras/Engine/Layer.Apply.cs View File

@@ -13,7 +13,7 @@ namespace Tensorflow.Keras.Engine
/// <param name="state"></param>
/// <param name="training"></param>
/// <returns></returns>
public virtual Tensors Apply(Tensors inputs, Tensors states = null, bool training = false, IOptionalArgs? optional_args = null)
public virtual Tensors Apply(Tensors inputs, Tensors states = null, bool? training = false, IOptionalArgs? optional_args = null)
{
if (callContext.Value == null)
callContext.Value = new CallContext();


+ 6
- 2
src/TensorFlowNET.Keras/Engine/Model.Fit.cs View File

@@ -142,6 +142,7 @@ namespace Tensorflow.Keras.Engine
int verbose = 1,
List<ICallback> callbacks = null,
IDatasetV2 validation_data = null,
int validation_step = 10, // 间隔多少次会进行一次验证
bool shuffle = true,
int initial_epoch = 0,
int max_queue_size = 10,
@@ -164,11 +165,11 @@ namespace Tensorflow.Keras.Engine
});


return FitInternal(data_handler, epochs, verbose, callbacks, validation_data: validation_data,
return FitInternal(data_handler, epochs, validation_step, verbose, callbacks, validation_data: validation_data,
train_step_func: train_step_function);
}

History FitInternal(DataHandler data_handler, int epochs, int verbose, List<ICallback> callbackList, IDatasetV2 validation_data,
History FitInternal(DataHandler data_handler, int epochs, int validation_step, int verbose, List<ICallback> callbackList, IDatasetV2 validation_data,
Func<DataHandler, OwnedIterator, Dictionary<string, float>> train_step_func)
{
stop_training = false;
@@ -207,6 +208,9 @@ namespace Tensorflow.Keras.Engine

if (validation_data != null)
{
if (validation_step > 0 && epoch ==0 || (epoch) % validation_step != 0)
continue;

var val_logs = evaluate(validation_data);
foreach(var log in val_logs)
{


+ 1
- 1
src/TensorFlowNET.Keras/Layers/Rnn/RNN.cs View File

@@ -393,7 +393,7 @@ namespace Tensorflow.Keras.Layers.Rnn
}
}

public override Tensors Apply(Tensors inputs, Tensors initial_states = null, bool training = false, IOptionalArgs? optional_args = null)
public override Tensors Apply(Tensors inputs, Tensors initial_states = null, bool? training = false, IOptionalArgs? optional_args = null)
{
RnnOptionalArgs? rnn_optional_args = optional_args as RnnOptionalArgs;
if (optional_args is not null && rnn_optional_args is null)


Loading…
Cancel
Save