Browse Source

add faster_rcnn_resnet101_voc07.config

tags/v0.12
Oceania2018 6 years ago
parent
commit
67eeab0e73
7 changed files with 172 additions and 24 deletions
  1. +2
    -20
      src/TensorFlowNET.Core/Estimators/RunConfig.cs
  2. +2
    -0
      src/TensorFlowNET.Core/Estimators/_TrainingExecutor.cs
  3. +7
    -1
      src/TensorFlowNET.Models/ObjectDetection/ModelLib.cs
  4. +143
    -0
      src/TensorFlowNET.Models/ObjectDetection/Models/faster_rcnn_resnet101_voc07.config
  5. +7
    -2
      src/TensorFlowNET.Models/ObjectDetection/Utils/ConfigUtil.cs
  6. +10
    -0
      src/TensorFlowNET.Models/TensorFlowNET.Models.csproj
  7. +1
    -1
      test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection/Main.cs

+ 2
- 20
src/TensorFlowNET.Core/Estimators/RunConfig.cs View File

@@ -43,13 +43,12 @@ namespace Tensorflow.Estimators

#endregion

private static readonly object _USE_DEFAULT = new object();
public string model_dir { get; set; }
public ConfigProto session_config { get; set; }
public int? tf_random_seed { get; set; }
public int save_summary_steps { get; set; } = 100;
public object save_checkpoints_steps { get; set; } = _USE_DEFAULT;
public object save_checkpoints_secs { get; set; } = _USE_DEFAULT;
public int save_checkpoints_steps { get; set; }
public int save_checkpoints_secs { get; set; } = 600;
public int keep_checkpoint_max { get; set; } = 5;
public int keep_checkpoint_every_n_hours { get; set; } = 10000;
public int log_step_count_steps{ get; set; } = 100;
@@ -97,23 +96,6 @@ namespace Tensorflow.Estimators

private void Initialize()
{
if (this.save_checkpoints_steps == _USE_DEFAULT && this.save_checkpoints_secs == _USE_DEFAULT)
{
this.save_checkpoints_steps = null;
this.save_checkpoints_secs = 600;
}
else if (this.save_checkpoints_secs == _USE_DEFAULT)
{
this.save_checkpoints_secs = null;
}
else if (this.save_checkpoints_steps == _USE_DEFAULT)
{
this.save_checkpoints_steps = null;
}
else if (this.save_checkpoints_steps != null && save_checkpoints_secs != null)
{
throw new Exception(_SAVE_CKPT_ERR);
}
}
}
}

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

@@ -16,6 +16,8 @@ namespace Tensorflow.Estimators
public _TrainingExecutor(Estimator estimator, TrainSpec train_spec, EvalSpec eval_spec)
{
_estimator = estimator;
_train_spec = train_spec;
_eval_spec = eval_spec;
}

public void run()


+ 7
- 1
src/TensorFlowNET.Models/ObjectDetection/ModelLib.cs View File

@@ -5,6 +5,7 @@ using static Tensorflow.Binding;
using Tensorflow.Estimators;
using System.Linq;
using Tensorflow.Contrib.Train;
using Tensorflow.Models.ObjectDetection.Utils;

namespace Tensorflow.Models.ObjectDetection
{
@@ -19,11 +20,16 @@ namespace Tensorflow.Models.ObjectDetection
{
var estimator = tf.estimator.Estimator(config: run_config);

var config = ConfigUtil.get_configs_from_pipeline_file(pipeline_config_path);
var eval_input_configs = config.EvalInputReader;

var eval_input_fns = new Action[eval_input_configs.Count];

return new TrainAndEvalDict
{
estimator = estimator,
train_steps = train_steps,
eval_input_fns = new Action[0]
eval_input_fns = eval_input_fns
};
}



+ 143
- 0
src/TensorFlowNET.Models/ObjectDetection/Models/faster_rcnn_resnet101_voc07.config View File

@@ -0,0 +1,143 @@
{
"model": {
"fasterRcnn": {
"numClasses": 20,
"imageResizer": {
"keepAspectRatioResizer": {
"minDimension": 600,
"maxDimension": 1024
}
},
"featureExtractor": {
"type": "faster_rcnn_resnet101",
"firstStageFeaturesStride": 16
},
"firstStageAnchorGenerator": {
"gridAnchorGenerator": {
"heightStride": 16,
"widthStride": 16,
"scales": [
0.25,
0.5,
1.0,
2.0
],
"aspectRatios": [
0.5,
1.0,
2.0
]
}
},
"firstStageBoxPredictorConvHyperparams": {
"op": "CONV",
"regularizer": {
"l2Regularizer": {
"weight": 0.0
}
},
"initializer": {
"truncatedNormalInitializer": {
"stddev": 0.009999999776482582
}
}
},
"firstStageNmsScoreThreshold": 0.0,
"firstStageNmsIouThreshold": 0.699999988079071,
"firstStageMaxProposals": 300,
"firstStageLocalizationLossWeight": 2.0,
"firstStageObjectnessLossWeight": 1.0,
"initialCropSize": 14,
"maxpoolKernelSize": 2,
"maxpoolStride": 2,
"secondStageBoxPredictor": {
"maskRcnnBoxPredictor": {
"fcHyperparams": {
"op": "FC",
"regularizer": {
"l2Regularizer": {
"weight": 0.0
}
},
"initializer": {
"varianceScalingInitializer": {
"factor": 1.0,
"uniform": true,
"mode": "FAN_AVG"
}
}
},
"useDropout": false,
"dropoutKeepProbability": 1.0
}
},
"secondStagePostProcessing": {
"batchNonMaxSuppression": {
"scoreThreshold": 0.0,
"iouThreshold": 0.6000000238418579,
"maxDetectionsPerClass": 100,
"maxTotalDetections": 300
},
"scoreConverter": "SOFTMAX"
},
"secondStageLocalizationLossWeight": 2.0,
"secondStageClassificationLossWeight": 1.0
}
},
"trainConfig": {
"batchSize": 1,
"dataAugmentationOptions": [
{
"randomHorizontalFlip": {}
}
],
"optimizer": {
"momentumOptimizer": {
"learningRate": {
"manualStepLearningRate": {
"initialLearningRate": 9.999999747378752e-05,
"schedule": [
{
"step": 500000,
"learningRate": 9.999999747378752e-06
},
{
"step": 700000,
"learningRate": 9.999999974752427e-07
}
]
}
},
"momentumOptimizerValue": 0.8999999761581421
},
"useMovingAverage": false
},
"gradientClippingByNorm": 10.0,
"fineTuneCheckpoint": "D:/tmp/faster_rcnn_resnet101_coco/model.ckpt",
"fromDetectionCheckpoint": true,
"numSteps": 800000
},
"trainInputReader": {
"labelMapPath": "D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_label_map.pbtxt",
"tfRecordInputReader": {
"inputPath": [
"D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_train.record"
]
}
},
"evalConfig": {
"numExamples": 4952
},
"evalInputReader": [
{
"labelMapPath": "D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_label_map.pbtxt",
"shuffle": false,
"numReaders": 1,
"tfRecordInputReader": {
"inputPath": [
"D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_val.record"
]
}
}
]
}

+ 7
- 2
src/TensorFlowNET.Models/ObjectDetection/Utils/ConfigUtil.cs View File

@@ -1,14 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Tensorflow.Models.ObjectDetection.Protos;

namespace Tensorflow.Models.ObjectDetection.Utils
{
public class ConfigUtil
{
public object get_configs_from_pipeline_file(string pipeline_config_path)
public static TrainEvalPipelineConfig get_configs_from_pipeline_file(string pipeline_config_path)
{
throw new NotImplementedException("");
var json = File.ReadAllText(pipeline_config_path);
var pipeline_config = TrainEvalPipelineConfig.Parser.ParseJson(json);

return pipeline_config;
}
}
}

+ 10
- 0
src/TensorFlowNET.Models/TensorFlowNET.Models.csproj View File

@@ -6,6 +6,16 @@
<RootNamespace>Tensorflow.Models</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Remove="ObjectDetection\Models\faster_rcnn_resnet101_voc07.config" />
</ItemGroup>

<ItemGroup>
<Content Include="ObjectDetection\Models\faster_rcnn_resnet101_voc07.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TensorFlowNET.Core\TensorFlowNET.Core.csproj" />
</ItemGroup>


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

@@ -20,7 +20,7 @@ namespace TensorFlowNET.Examples.ImageProcessing.ObjectDetection
ModelLib model_lib = new ModelLib();

string model_dir = "D:/Projects/PythonLab/tf-models/research/object_detection/models/model";
string pipeline_config_path = "D:/Projects/PythonLab/tf-models/research/object_detection/models/model/faster_rcnn_resnet101_voc07.config";
string pipeline_config_path = "ObjectDetection/Models/faster_rcnn_resnet101_voc07.config";
int num_train_steps = 1;
int sample_1_of_n_eval_examples = 1;
int sample_1_of_n_eval_on_train_examples = 5;


Loading…
Cancel
Save