Browse Source

tensorflow.estimator

tags/v0.12
Oceania2018 6 years ago
parent
commit
bbd76d5840
19 changed files with 244 additions and 68 deletions
  1. +39
    -0
      src/TensorFlowNET.Core/APIs/tf.estimator.cs
  2. +0
    -36
      src/TensorFlowNET.Core/Estimator/EstimatorV2.cs
  3. +0
    -7
      src/TensorFlowNET.Core/Estimator/IEstimator.cs
  4. +0
    -15
      src/TensorFlowNET.Core/Estimator/TrainingExecutor.cs
  5. +41
    -0
      src/TensorFlowNET.Core/Estimators/Estimator.cs
  6. +1
    -1
      src/TensorFlowNET.Core/Estimators/HyperParams.cs
  7. +3
    -2
      src/TensorFlowNET.Core/Estimators/README.md
  8. +12
    -0
      src/TensorFlowNET.Core/Estimators/RunConfig.cs
  9. +15
    -0
      src/TensorFlowNET.Core/Estimators/Training.cs
  10. +26
    -0
      src/TensorFlowNET.Core/Estimators/_TrainingExecutor.cs
  11. +1
    -0
      src/TensorFlowNET.Core/TensorFlowNET.Core.csproj
  12. +21
    -0
      src/TensorFlowNET.Models/ObjectDetection/ModelLib.cs
  13. +68
    -0
      test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection/Main.cs
  14. +12
    -0
      test/TensorFlowNET.Examples/ImageProcessing/YOLO/Main.cs
  15. +1
    -0
      test/TensorFlowNET.Examples/TensorFlowNET.Examples.GPU.csproj
  16. +1
    -4
      test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj
  17. +1
    -1
      test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs
  18. +1
    -1
      test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs
  19. +1
    -1
      test/TensorFlowNET.Examples/Utility/CoNLLDataset.cs

+ 39
- 0
src/TensorFlowNET.Core/APIs/tf.estimator.cs View File

@@ -0,0 +1,39 @@
/*****************************************************************************
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.
******************************************************************************/

using System;
using static Tensorflow.Binding;
using Tensorflow.Estimators;

namespace Tensorflow
{
public partial class tensorflow
{
public Estimator_Internal estimator { get; } = new Estimator_Internal();

public class Estimator_Internal
{
public Estimator Estimator(RunConfig config)
=> new Estimator(config: config);

public RunConfig RunConfig(string model_dir)
=> new RunConfig(model_dir: model_dir);

public void train_and_evaluate()
=> Training.train_and_evaluate();
}
}
}

+ 0
- 36
src/TensorFlowNET.Core/Estimator/EstimatorV2.cs View File

@@ -1,36 +0,0 @@
using System;
using Tensorflow.Data;

namespace Tensorflow.Estimator
{
/// <summary>
/// Estimator class to train and evaluate TensorFlow models.
/// <see cref="tensorflow_estimator\python\estimator\estimator.py"/>
/// </summary>
public class EstimatorV2 : IEstimator
{
public EstimatorV2(string model_dir = null)
{

}

/// <summary>
/// Calls the input function.
/// </summary>
/// <param name="mode"></param>
public void call_input_fn(string mode = null)
{

}

public void train_model_default(Func<string, string, HyperParams, bool, DatasetV1Adapter> input_fn)
{

}

public void get_features_and_labels_from_input_fn()
{

}
}
}

+ 0
- 7
src/TensorFlowNET.Core/Estimator/IEstimator.cs View File

@@ -1,7 +0,0 @@
namespace Tensorflow.Estimator
{
public interface IEstimator
{

}
}

+ 0
- 15
src/TensorFlowNET.Core/Estimator/TrainingExecutor.cs View File

@@ -1,15 +0,0 @@
namespace Tensorflow.Estimator
{
/// <summary>
/// The executor to run `Estimator` training and evaluation.
/// <see cref="tensorflow_estimator\python\estimator\training.py"/>
/// </summary>
public class TrainingExecutor
{
private IEstimator _estimator;
public TrainingExecutor(IEstimator estimator)
{
_estimator = estimator;
}
}
}

+ 41
- 0
src/TensorFlowNET.Core/Estimators/Estimator.cs View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Estimators
{
public class Estimator : IObjectLife
{
public RunConfig config;

public Estimator(RunConfig config)
{
this.config = config;
}

public void __init__()
{
throw new NotImplementedException();
}

public void __enter__()
{
throw new NotImplementedException();
}

public void __del__()
{
throw new NotImplementedException();
}

public void __exit__()
{
throw new NotImplementedException();
}

public void Dispose()
{
throw new NotImplementedException();
}
}
}

src/TensorFlowNET.Core/Estimator/HyperParams.cs → src/TensorFlowNET.Core/Estimators/HyperParams.cs View File

@@ -1,6 +1,6 @@
using System.IO;

namespace Tensorflow.Estimator
namespace Tensorflow.Estimators
{
public class HyperParams
{

src/TensorFlowNET.Core/Estimator/README.md → src/TensorFlowNET.Core/Estimators/README.md View File

@@ -1,6 +1,7 @@
### TensorFlow Estimator
# TensorFlow Estimator

TensorFlow Estimator is a high-level TensorFlow API that greatly simplifies machine learning programming. Estimators encapsulate training, evaluation, prediction, and exporting for your model.

Guide: <https://www.tensorflow.org/guide/estimators>


https://github.com/tensorflow/estimator

+ 12
- 0
src/TensorFlowNET.Core/Estimators/RunConfig.cs View File

@@ -0,0 +1,12 @@
using System;

namespace Tensorflow.Estimators
{
public class RunConfig
{
public RunConfig(string model_dir)
{

}
}
}

+ 15
- 0
src/TensorFlowNET.Core/Estimators/Training.cs View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Estimators
{
public class Training
{
public static void train_and_evaluate()
{
var executor = new _TrainingExecutor();
executor.run();
}
}
}

+ 26
- 0
src/TensorFlowNET.Core/Estimators/_TrainingExecutor.cs View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Estimators
{
public class _TrainingExecutor
{
Estimator _estimator;

public _TrainingExecutor(Estimator estimator)
{

}

public void run()
{
run_local();
}

private void run_local()
{

}
}
}

+ 1
- 0
src/TensorFlowNET.Core/TensorFlowNET.Core.csproj View File

@@ -68,5 +68,6 @@ Docs: https://tensorflownet.readthedocs.io</Description>
<ItemGroup>
<Folder Include="Distribute\" />
<Folder Include="Keras\Initializers\" />
<Folder Include="Models\" />
</ItemGroup>
</Project>

+ 21
- 0
src/TensorFlowNET.Models/ObjectDetection/ModelLib.cs View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using static Tensorflow.Binding;
using Tensorflow.Estimators;

namespace Tensorflow.Models.ObjectDetection
{
public class ModelLib
{
public void create_estimator_and_inputs(RunConfig run_config)
{
var estimator = tf.estimator.Estimator(config: run_config);
}

public void create_train_and_eval_specs()
{

}
}
}

+ 68
- 0
test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection/Main.cs View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Tensorflow;
using Tensorflow.Models.ObjectDetection;
using static Tensorflow.Binding;

namespace TensorFlowNET.Examples.ImageProcessing.ObjectDetection
{
public class Main : IExample
{
public bool Enabled { get; set; } = true;
public bool IsImportingGraph { get; set; } = true;

public string Name => "Object Detection API";

dynamic FLAGS = new
{
model_dir = "D:/Projects/PythonLab/tf-models/research/object_detection/models/model"
};

ModelLib model_lib = new ModelLib();

public bool Run()
{
var config = tf.estimator.RunConfig(model_dir: FLAGS.model_dir);
model_lib.create_estimator_and_inputs(run_config: config);

// Currently only a single Eval Spec is allowed.
tf.estimator.train_and_evaluate();

return true;
}

public Graph BuildGraph()
{
throw new NotImplementedException();
}

public Graph ImportGraph()
{
throw new NotImplementedException();
}

public void Predict(Session sess)
{
throw new NotImplementedException();
}

public void PrepareData()
{
throw new NotImplementedException();
}



public void Train(Session sess)
{
throw new NotImplementedException();
}

void IExample.Test(Session sess)
{
throw new NotImplementedException();
}
}
}

+ 12
- 0
test/TensorFlowNET.Examples/ImageProcessing/YOLO/Main.cs View File

@@ -51,6 +51,7 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO
RefVariable global_step;
Tensor learn_rate;
Tensor loss;
List<RefVariable> first_stage_trainable_var_list;
#endregion

public bool Run()
@@ -141,6 +142,17 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO

tf_with(tf.name_scope("define_first_stage_train"), scope =>
{
first_stage_trainable_var_list = new List<RefVariable>();
foreach (var var in tf.trainable_variables())
{
var var_name = var.op.name;
var var_name_mess = var_name.Split('/');
if (new[] { "conv_sbbox", "conv_mbbox", "conv_lbbox" }.Contains(var_name_mess[0]))
first_stage_trainable_var_list.Add(var as RefVariable);
}

var adam = tf.train.AdamOptimizer(learn_rate);
var first_stage_optimizer = adam.minimize(loss, var_list: first_stage_trainable_var_list);
});

return graph;


+ 1
- 0
test/TensorFlowNET.Examples/TensorFlowNET.Examples.GPU.csproj View File

@@ -29,6 +29,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\TensorFlowDatasets\TensorFlowDatasets.csproj" />
<ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" />
<ProjectReference Include="..\..\src\TensorFlowNET.Models\TensorFlowNET.Models.csproj" />
<ProjectReference Include="..\..\src\TensorFlowText\TensorFlowText.csproj" />
<ProjectReference Include="..\..\src\TensorFlowHub\TensorFlowHub.csproj" />
</ItemGroup>


+ 1
- 4
test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj View File

@@ -25,11 +25,8 @@
<ItemGroup>
<ProjectReference Include="..\..\src\TensorFlowDatasets\TensorFlowDatasets.csproj" />
<ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" />
<ProjectReference Include="..\..\src\TensorFlowNET.Models\TensorFlowNET.Models.csproj" />
<ProjectReference Include="..\..\src\TensorFlowText\TensorFlowText.csproj" />
<ProjectReference Include="..\..\src\TensorFlowHub\TensorFlowHub.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="ImageProcessing\ObjectDetection\" />
</ItemGroup>
</Project>

+ 1
- 1
test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs View File

@@ -1,7 +1,7 @@
using System;
using System.IO;
using Tensorflow;
using Tensorflow.Estimator;
using Tensorflow.Estimators;

namespace TensorFlowNET.Examples
{


+ 1
- 1
test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Tensorflow;
using Tensorflow.Estimator;
using Tensorflow.Estimators;
using TensorFlowNET.Examples.Utility;
using static Tensorflow.Binding;
using static TensorFlowNET.Examples.DataHelpers;


+ 1
- 1
test/TensorFlowNET.Examples/Utility/CoNLLDataset.cs View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Tensorflow.Estimator;
using Tensorflow.Estimators;

namespace TensorFlowNET.Examples.Utility
{


Loading…
Cancel
Save