diff --git a/src/TensorFlowNET.Core/TensorFlow.Binding.csproj b/src/TensorFlowNET.Core/TensorFlow.Binding.csproj index 712e4aed..39279808 100644 --- a/src/TensorFlowNET.Core/TensorFlow.Binding.csproj +++ b/src/TensorFlowNET.Core/TensorFlow.Binding.csproj @@ -67,7 +67,6 @@ https://tensorflownet.readthedocs.io - diff --git a/src/TensorFlowNET.Core/Train/AdamOptimizer.cs b/src/TensorFlowNET.Core/Training/AdamOptimizer.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/AdamOptimizer.cs rename to src/TensorFlowNET.Core/Training/AdamOptimizer.cs diff --git a/src/TensorFlowNET.Core/Train/AutoTrackable.cs b/src/TensorFlowNET.Core/Training/AutoTrackable.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/AutoTrackable.cs rename to src/TensorFlowNET.Core/Training/AutoTrackable.cs diff --git a/src/TensorFlowNET.Core/Train/Checkpointable/CheckpointableBase.cs b/src/TensorFlowNET.Core/Training/Checkpointable/CheckpointableBase.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Checkpointable/CheckpointableBase.cs rename to src/TensorFlowNET.Core/Training/Checkpointable/CheckpointableBase.cs diff --git a/src/TensorFlowNET.Core/Training/Coordinator.cs b/src/TensorFlowNET.Core/Training/Coordinator.cs new file mode 100644 index 00000000..33c787b4 --- /dev/null +++ b/src/TensorFlowNET.Core/Training/Coordinator.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tensorflow.Training +{ + /// + /// A coordinator for threads + /// + public class Coordinator + { + } +} diff --git a/src/TensorFlowNET.Core/Train/Distribute.cs b/src/TensorFlowNET.Core/Training/Distribute.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Distribute.cs rename to src/TensorFlowNET.Core/Training/Distribute.cs diff --git a/src/TensorFlowNET.Core/Train/ExponentialMovingAverage.cs b/src/TensorFlowNET.Core/Training/ExponentialMovingAverage.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/ExponentialMovingAverage.cs rename to src/TensorFlowNET.Core/Training/ExponentialMovingAverage.cs diff --git a/src/TensorFlowNET.Core/Train/GateGradientType.cs b/src/TensorFlowNET.Core/Training/GateGradientType.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/GateGradientType.cs rename to src/TensorFlowNET.Core/Training/GateGradientType.cs diff --git a/src/TensorFlowNET.Core/Train/GradientDescentOptimizer.cs b/src/TensorFlowNET.Core/Training/GradientDescentOptimizer.cs similarity index 99% rename from src/TensorFlowNET.Core/Train/GradientDescentOptimizer.cs rename to src/TensorFlowNET.Core/Training/GradientDescentOptimizer.cs index d4682066..73359c4b 100644 --- a/src/TensorFlowNET.Core/Train/GradientDescentOptimizer.cs +++ b/src/TensorFlowNET.Core/Training/GradientDescentOptimizer.cs @@ -1,26 +1,26 @@ -/***************************************************************************** - Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +/***************************************************************************** + Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. ******************************************************************************/ namespace Tensorflow.Train { - /// - /// Optimizer that implements the gradient descent algorithm. + /// + /// Optimizer that implements the gradient descent algorithm. /// public class GradientDescentOptimizer : Optimizer - { + { /// /// Construct a new gradient descent optimizer. /// @@ -41,9 +41,9 @@ namespace Tensorflow.Train { _lr = learning_rate; _useTensor = false; - } - - public GradientDescentOptimizer(Tensor learning_rate, bool use_locking = false, string name = "GradientDescent") + } + + public GradientDescentOptimizer(Tensor learning_rate, bool use_locking = false, string name = "GradientDescent") : base(learning_rate, use_locking, name) { _lr_t = learning_rate; @@ -52,10 +52,10 @@ namespace Tensorflow.Train public override void _prepare() { - if(!_useTensor) - { - var lr = _call_if_callable(_lr); - _lr_t = ops.convert_to_tensor(lr, name: "learning_rate"); + if(!_useTensor) + { + var lr = _call_if_callable(_lr); + _lr_t = ops.convert_to_tensor(lr, name: "learning_rate"); } } diff --git a/src/TensorFlowNET.Core/Train/Optimizer.cs b/src/TensorFlowNET.Core/Training/Optimizer.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Optimizer.cs rename to src/TensorFlowNET.Core/Training/Optimizer.cs diff --git a/src/TensorFlowNET.Core/Train/QueueRunner.cs b/src/TensorFlowNET.Core/Training/QueueRunner.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/QueueRunner.cs rename to src/TensorFlowNET.Core/Training/QueueRunner.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs b/src/TensorFlowNET.Core/Training/Saving/BaseSaverBuilder.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs rename to src/TensorFlowNET.Core/Training/Saving/BaseSaverBuilder.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/BulkSaverBuilder.cs b/src/TensorFlowNET.Core/Training/Saving/BulkSaverBuilder.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/BulkSaverBuilder.cs rename to src/TensorFlowNET.Core/Training/Saving/BulkSaverBuilder.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/ISaverBuilder.cs b/src/TensorFlowNET.Core/Training/Saving/ISaverBuilder.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/ISaverBuilder.cs rename to src/TensorFlowNET.Core/Training/Saving/ISaverBuilder.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/ReferenceVariableSaveable.cs b/src/TensorFlowNET.Core/Training/Saving/ReferenceVariableSaveable.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/ReferenceVariableSaveable.cs rename to src/TensorFlowNET.Core/Training/Saving/ReferenceVariableSaveable.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/ResourceVariableSaveable.cs b/src/TensorFlowNET.Core/Training/Saving/ResourceVariableSaveable.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/ResourceVariableSaveable.cs rename to src/TensorFlowNET.Core/Training/Saving/ResourceVariableSaveable.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/SaveSpec.cs b/src/TensorFlowNET.Core/Training/Saving/SaveSpec.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/SaveSpec.cs rename to src/TensorFlowNET.Core/Training/Saving/SaveSpec.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/SaveableObject.cs b/src/TensorFlowNET.Core/Training/Saving/SaveableObject.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/SaveableObject.cs rename to src/TensorFlowNET.Core/Training/Saving/SaveableObject.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/Saver.cs b/src/TensorFlowNET.Core/Training/Saving/Saver.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/Saver.cs rename to src/TensorFlowNET.Core/Training/Saving/Saver.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/checkpoint_management.py.cs b/src/TensorFlowNET.Core/Training/Saving/checkpoint_management.py.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/checkpoint_management.py.cs rename to src/TensorFlowNET.Core/Training/Saving/checkpoint_management.py.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs b/src/TensorFlowNET.Core/Training/Saving/saveable_object_util.py.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs rename to src/TensorFlowNET.Core/Training/Saving/saveable_object_util.py.cs diff --git a/src/TensorFlowNET.Core/Train/Saving/saver.py.cs b/src/TensorFlowNET.Core/Training/Saving/saver.py.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Saving/saver.py.cs rename to src/TensorFlowNET.Core/Training/Saving/saver.py.cs diff --git a/src/TensorFlowNET.Core/Training/SecondOrStepTimer.cs b/src/TensorFlowNET.Core/Training/SecondOrStepTimer.cs new file mode 100644 index 00000000..fe13405f --- /dev/null +++ b/src/TensorFlowNET.Core/Training/SecondOrStepTimer.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tensorflow.Training +{ + public class SecondOrStepTimer : _HookTimer + { + int _every_secs = 60; + int _every_steps = 0; + int _last_triggered_step = 0; + int _last_triggered_time = 0; + + public SecondOrStepTimer(int every_secs, int every_steps) + { + _every_secs = every_secs; + _every_steps = every_steps; + } + + public override void reset() + { + _last_triggered_step = 0; + _last_triggered_time = 0; + } + + public override int last_triggered_step() + { + return _last_triggered_step; + } + + public override bool should_trigger_for_step(int step) + { + throw new NotImplementedException(); + } + + public override void update_last_triggered_step(int step) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Core/Train/SessionRunArgs.cs b/src/TensorFlowNET.Core/Training/SessionRunArgs.cs similarity index 79% rename from src/TensorFlowNET.Core/Train/SessionRunArgs.cs rename to src/TensorFlowNET.Core/Training/SessionRunArgs.cs index 00d473e1..7c089634 100644 --- a/src/TensorFlowNET.Core/Train/SessionRunArgs.cs +++ b/src/TensorFlowNET.Core/Training/SessionRunArgs.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Tensorflow.Train +namespace Tensorflow.Training { public class SessionRunArgs { diff --git a/src/TensorFlowNET.Core/Train/SessionRunContext.cs b/src/TensorFlowNET.Core/Training/SessionRunContext.cs similarity index 95% rename from src/TensorFlowNET.Core/Train/SessionRunContext.cs rename to src/TensorFlowNET.Core/Training/SessionRunContext.cs index cf8bdc05..6c119593 100644 --- a/src/TensorFlowNET.Core/Train/SessionRunContext.cs +++ b/src/TensorFlowNET.Core/Training/SessionRunContext.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Tensorflow.Train +namespace Tensorflow.Training { public class SessionRunContext { diff --git a/src/TensorFlowNET.Core/Training/SessionRunHook.cs b/src/TensorFlowNET.Core/Training/SessionRunHook.cs new file mode 100644 index 00000000..ce3a2200 --- /dev/null +++ b/src/TensorFlowNET.Core/Training/SessionRunHook.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tensorflow.Training +{ + /// + /// Hook to extend calls to MonitoredSession.run(). + /// + public abstract class SessionRunHook + { + /// + /// Called once before using the session. + /// + public virtual void begin() + { + } + + /// + /// Called when new TensorFlow session is created. + /// + /// + /// + public virtual void after_create_session(Session session, Coordinator coord) + { + } + + /// + /// Called before each call to run(). + /// + /// + public virtual void before_run(SessionRunContext run_context) + { + } + + /// + /// Called after each call to run(). + /// + public virtual void after_run(SessionRunContext run_context, SessionRunValues run_values) + { + } + + /// + /// Called at the end of session. + /// + public virtual void end(Session session) + { + } + } +} diff --git a/src/TensorFlowNET.Core/Train/SessionRunValues.cs b/src/TensorFlowNET.Core/Training/SessionRunValues.cs similarity index 80% rename from src/TensorFlowNET.Core/Train/SessionRunValues.cs rename to src/TensorFlowNET.Core/Training/SessionRunValues.cs index 655c3310..d93e8347 100644 --- a/src/TensorFlowNET.Core/Train/SessionRunValues.cs +++ b/src/TensorFlowNET.Core/Training/SessionRunValues.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Tensorflow.Train +namespace Tensorflow.Training { public class SessionRunValues { diff --git a/src/TensorFlowNET.Core/Train/SlotCreator.cs b/src/TensorFlowNET.Core/Training/SlotCreator.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/SlotCreator.cs rename to src/TensorFlowNET.Core/Training/SlotCreator.cs diff --git a/src/TensorFlowNET.Core/Train/Trackable.cs b/src/TensorFlowNET.Core/Training/Trackable.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/Trackable.cs rename to src/TensorFlowNET.Core/Training/Trackable.cs diff --git a/src/TensorFlowNET.Core/Train/TrainingUtil.cs b/src/TensorFlowNET.Core/Training/TrainingUtil.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/TrainingUtil.cs rename to src/TensorFlowNET.Core/Training/TrainingUtil.cs diff --git a/src/TensorFlowNET.Core/Train/VariableAggregationType.cs b/src/TensorFlowNET.Core/Training/VariableAggregationType.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/VariableAggregationType.cs rename to src/TensorFlowNET.Core/Training/VariableAggregationType.cs diff --git a/src/TensorFlowNET.Core/Training/_HookTimer.cs b/src/TensorFlowNET.Core/Training/_HookTimer.cs new file mode 100644 index 00000000..295de165 --- /dev/null +++ b/src/TensorFlowNET.Core/Training/_HookTimer.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tensorflow.Training +{ + /// + /// Base timer for determining when Hooks should trigger. + /// + public abstract class _HookTimer + { + /// + /// Resets the timer. + /// + public abstract void reset(); + + /// + /// Return true if the timer should trigger for the specified step. + /// + /// + /// + public abstract bool should_trigger_for_step(int step); + + /// + /// Update the last triggered time and step number. + /// + /// + public abstract void update_last_triggered_step(int step); + + /// + /// Returns the last triggered time step or None if never triggered. + /// + /// + public abstract int last_triggered_step(); + } +} diff --git a/src/TensorFlowNET.Core/Train/_MonitoredSession.cs b/src/TensorFlowNET.Core/Training/_MonitoredSession.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/_MonitoredSession.cs rename to src/TensorFlowNET.Core/Training/_MonitoredSession.cs diff --git a/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs b/src/TensorFlowNET.Core/Training/_OptimizableVariable.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/_OptimizableVariable.cs rename to src/TensorFlowNET.Core/Training/_OptimizableVariable.cs diff --git a/src/TensorFlowNET.Core/Train/gen_training_ops.py.cs b/src/TensorFlowNET.Core/Training/gen_training_ops.py.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/gen_training_ops.py.cs rename to src/TensorFlowNET.Core/Training/gen_training_ops.py.cs diff --git a/src/TensorFlowNET.Core/Train/moving_averages.cs b/src/TensorFlowNET.Core/Training/moving_averages.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/moving_averages.cs rename to src/TensorFlowNET.Core/Training/moving_averages.cs diff --git a/src/TensorFlowNET.Core/Train/optimizer.py.cs b/src/TensorFlowNET.Core/Training/optimizer.py.cs similarity index 100% rename from src/TensorFlowNET.Core/Train/optimizer.py.cs rename to src/TensorFlowNET.Core/Training/optimizer.py.cs