Skip to content

Commit 67eeab0

Browse files
committed
add faster_rcnn_resnet101_voc07.config
1 parent 757456f commit 67eeab0

7 files changed

Lines changed: 172 additions & 24 deletions

File tree

src/TensorFlowNET.Core/Estimators/RunConfig.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ public class RunConfig
4343

4444
#endregion
4545

46-
private static readonly object _USE_DEFAULT = new object();
4746
public string model_dir { get; set; }
4847
public ConfigProto session_config { get; set; }
4948
public int? tf_random_seed { get; set; }
5049
public int save_summary_steps { get; set; } = 100;
51-
public object save_checkpoints_steps { get; set; } = _USE_DEFAULT;
52-
public object save_checkpoints_secs { get; set; } = _USE_DEFAULT;
50+
public int save_checkpoints_steps { get; set; }
51+
public int save_checkpoints_secs { get; set; } = 600;
5352
public int keep_checkpoint_max { get; set; } = 5;
5453
public int keep_checkpoint_every_n_hours { get; set; } = 10000;
5554
public int log_step_count_steps{ get; set; } = 100;
@@ -97,23 +96,6 @@ public RunConfig(
9796

9897
private void Initialize()
9998
{
100-
if (this.save_checkpoints_steps == _USE_DEFAULT && this.save_checkpoints_secs == _USE_DEFAULT)
101-
{
102-
this.save_checkpoints_steps = null;
103-
this.save_checkpoints_secs = 600;
104-
}
105-
else if (this.save_checkpoints_secs == _USE_DEFAULT)
106-
{
107-
this.save_checkpoints_secs = null;
108-
}
109-
else if (this.save_checkpoints_steps == _USE_DEFAULT)
110-
{
111-
this.save_checkpoints_steps = null;
112-
}
113-
else if (this.save_checkpoints_steps != null && save_checkpoints_secs != null)
114-
{
115-
throw new Exception(_SAVE_CKPT_ERR);
116-
}
11799
}
118100
}
119101
}

src/TensorFlowNET.Core/Estimators/_TrainingExecutor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ internal class _TrainingExecutor
1616
public _TrainingExecutor(Estimator estimator, TrainSpec train_spec, EvalSpec eval_spec)
1717
{
1818
_estimator = estimator;
19+
_train_spec = train_spec;
20+
_eval_spec = eval_spec;
1921
}
2022

2123
public void run()

src/TensorFlowNET.Models/ObjectDetection/ModelLib.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Tensorflow.Estimators;
66
using System.Linq;
77
using Tensorflow.Contrib.Train;
8+
using Tensorflow.Models.ObjectDetection.Utils;
89

910
namespace Tensorflow.Models.ObjectDetection
1011
{
@@ -19,11 +20,16 @@ public TrainAndEvalDict create_estimator_and_inputs(RunConfig run_config,
1920
{
2021
var estimator = tf.estimator.Estimator(config: run_config);
2122

23+
var config = ConfigUtil.get_configs_from_pipeline_file(pipeline_config_path);
24+
var eval_input_configs = config.EvalInputReader;
25+
26+
var eval_input_fns = new Action[eval_input_configs.Count];
27+
2228
return new TrainAndEvalDict
2329
{
2430
estimator = estimator,
2531
train_steps = train_steps,
26-
eval_input_fns = new Action[0]
32+
eval_input_fns = eval_input_fns
2733
};
2834
}
2935

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"model": {
3+
"fasterRcnn": {
4+
"numClasses": 20,
5+
"imageResizer": {
6+
"keepAspectRatioResizer": {
7+
"minDimension": 600,
8+
"maxDimension": 1024
9+
}
10+
},
11+
"featureExtractor": {
12+
"type": "faster_rcnn_resnet101",
13+
"firstStageFeaturesStride": 16
14+
},
15+
"firstStageAnchorGenerator": {
16+
"gridAnchorGenerator": {
17+
"heightStride": 16,
18+
"widthStride": 16,
19+
"scales": [
20+
0.25,
21+
0.5,
22+
1.0,
23+
2.0
24+
],
25+
"aspectRatios": [
26+
0.5,
27+
1.0,
28+
2.0
29+
]
30+
}
31+
},
32+
"firstStageBoxPredictorConvHyperparams": {
33+
"op": "CONV",
34+
"regularizer": {
35+
"l2Regularizer": {
36+
"weight": 0.0
37+
}
38+
},
39+
"initializer": {
40+
"truncatedNormalInitializer": {
41+
"stddev": 0.009999999776482582
42+
}
43+
}
44+
},
45+
"firstStageNmsScoreThreshold": 0.0,
46+
"firstStageNmsIouThreshold": 0.699999988079071,
47+
"firstStageMaxProposals": 300,
48+
"firstStageLocalizationLossWeight": 2.0,
49+
"firstStageObjectnessLossWeight": 1.0,
50+
"initialCropSize": 14,
51+
"maxpoolKernelSize": 2,
52+
"maxpoolStride": 2,
53+
"secondStageBoxPredictor": {
54+
"maskRcnnBoxPredictor": {
55+
"fcHyperparams": {
56+
"op": "FC",
57+
"regularizer": {
58+
"l2Regularizer": {
59+
"weight": 0.0
60+
}
61+
},
62+
"initializer": {
63+
"varianceScalingInitializer": {
64+
"factor": 1.0,
65+
"uniform": true,
66+
"mode": "FAN_AVG"
67+
}
68+
}
69+
},
70+
"useDropout": false,
71+
"dropoutKeepProbability": 1.0
72+
}
73+
},
74+
"secondStagePostProcessing": {
75+
"batchNonMaxSuppression": {
76+
"scoreThreshold": 0.0,
77+
"iouThreshold": 0.6000000238418579,
78+
"maxDetectionsPerClass": 100,
79+
"maxTotalDetections": 300
80+
},
81+
"scoreConverter": "SOFTMAX"
82+
},
83+
"secondStageLocalizationLossWeight": 2.0,
84+
"secondStageClassificationLossWeight": 1.0
85+
}
86+
},
87+
"trainConfig": {
88+
"batchSize": 1,
89+
"dataAugmentationOptions": [
90+
{
91+
"randomHorizontalFlip": {}
92+
}
93+
],
94+
"optimizer": {
95+
"momentumOptimizer": {
96+
"learningRate": {
97+
"manualStepLearningRate": {
98+
"initialLearningRate": 9.999999747378752e-05,
99+
"schedule": [
100+
{
101+
"step": 500000,
102+
"learningRate": 9.999999747378752e-06
103+
},
104+
{
105+
"step": 700000,
106+
"learningRate": 9.999999974752427e-07
107+
}
108+
]
109+
}
110+
},
111+
"momentumOptimizerValue": 0.8999999761581421
112+
},
113+
"useMovingAverage": false
114+
},
115+
"gradientClippingByNorm": 10.0,
116+
"fineTuneCheckpoint": "D:/tmp/faster_rcnn_resnet101_coco/model.ckpt",
117+
"fromDetectionCheckpoint": true,
118+
"numSteps": 800000
119+
},
120+
"trainInputReader": {
121+
"labelMapPath": "D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_label_map.pbtxt",
122+
"tfRecordInputReader": {
123+
"inputPath": [
124+
"D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_train.record"
125+
]
126+
}
127+
},
128+
"evalConfig": {
129+
"numExamples": 4952
130+
},
131+
"evalInputReader": [
132+
{
133+
"labelMapPath": "D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_label_map.pbtxt",
134+
"shuffle": false,
135+
"numReaders": 1,
136+
"tfRecordInputReader": {
137+
"inputPath": [
138+
"D:/Projects/PythonLab/tf-models/research/object_detection/data/pascal_val.record"
139+
]
140+
}
141+
}
142+
]
143+
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Text;
5+
using Tensorflow.Models.ObjectDetection.Protos;
46

57
namespace Tensorflow.Models.ObjectDetection.Utils
68
{
79
public class ConfigUtil
810
{
9-
public object get_configs_from_pipeline_file(string pipeline_config_path)
11+
public static TrainEvalPipelineConfig get_configs_from_pipeline_file(string pipeline_config_path)
1012
{
11-
throw new NotImplementedException("");
13+
var json = File.ReadAllText(pipeline_config_path);
14+
var pipeline_config = TrainEvalPipelineConfig.Parser.ParseJson(json);
15+
16+
return pipeline_config;
1217
}
1318
}
1419
}

src/TensorFlowNET.Models/TensorFlowNET.Models.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
<RootNamespace>Tensorflow.Models</RootNamespace>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<None Remove="ObjectDetection\Models\faster_rcnn_resnet101_voc07.config" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<Content Include="ObjectDetection\Models\faster_rcnn_resnet101_voc07.config">
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
</Content>
17+
</ItemGroup>
18+
919
<ItemGroup>
1020
<ProjectReference Include="..\TensorFlowNET.Core\TensorFlowNET.Core.csproj" />
1121
</ItemGroup>

test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Main : IExample
2020
ModelLib model_lib = new ModelLib();
2121

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

0 commit comments

Comments
 (0)