FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Start to train Yolo #359 · oumarxy/TensorFlow.NET@70df2bb · GitHub

Repository navigation

Commit 70df2bb

Browse files
committed
Start to train Yolo SciSharp#359
1 parent 9edada5 commit 70df2bb

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎src/TensorFlowNET.Core/APIs/tf.train.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public Optimizer AdamOptimizer(Tensor learning_rate, string name = "Adam")
4343
public ExponentialMovingAverage ExponentialMovingAverage(float decay)
4444
=> new ExponentialMovingAverage(decay);
4545

46-
public Saver Saver(VariableV1[] var_list = null) => new Saver(var_list: var_list);
46+
public Saver Saver(VariableV1[] var_list = null, int max_to_keep = 5)
47+
=> new Saver(var_list: var_list, max_to_keep: max_to_keep);
4748

4849
public string write_graph(Graph graph, string logdir, string name, bool as_text = true)
4950
=> graph_io.write_graph(graph, logdir, name, as_text);

‎src/TensorFlowNET.Core/Gradients/gradients_util.cs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ public static Tensor[] _GradientsHelper(Tensor[] ys,
108108
{
109109
// generate gradient subgraph for op.
110110
var op = queue.Dequeue();
111-
if(tf.get_default_graph()._nodes_by_name.Count >= 23868)
112-
{
113111

114-
}
115112
_maybe_colocate_with(op, gradient_uid, colocate_gradients_with_ops);
116113
//if (loop_state != null)
117114
//loop_state.EnterGradWhileContext(op, before: true);

‎test/TensorFlowNET.Examples/ImageProcessing/YOLO/Main.cs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class Main : IExample
5454
List<RefVariable> first_stage_trainable_var_list;
5555
Operation train_op_with_frozen_variables;
5656
Operation train_op_with_all_variables;
57+
Saver loader;
58+
Saver saver;
5759
#endregion
5860

5961
public bool Run()
@@ -74,7 +76,9 @@ public bool Run()
7476

7577
public void Train(Session sess)
7678
{
77-
79+
sess.run(tf.global_variables_initializer());
80+
print($"=> Restoring weights from: {cfg.TRAIN.INITIAL_WEIGHT} ... ");
81+
loader.restore(sess, cfg.TRAIN.INITIAL_WEIGHT);
7882
}
7983

8084
public void Test(Session sess)
@@ -184,6 +188,21 @@ public Graph BuildGraph()
184188
});
185189
});
186190

191+
tf_with(tf.name_scope("loader_and_saver"), delegate
192+
{
193+
loader = tf.train.Saver(net_var);
194+
saver = tf.train.Saver(tf.global_variables(), max_to_keep: 10);
195+
});
196+
197+
tf_with(tf.name_scope("summary"), delegate
198+
{
199+
tf.summary.scalar("learn_rate", learn_rate);
200+
tf.summary.scalar("giou_loss", giou_loss);
201+
tf.summary.scalar("conf_loss", conf_loss);
202+
tf.summary.scalar("prob_loss", prob_loss);
203+
tf.summary.scalar("total_loss", loss);
204+
});
205+
187206
return graph;
188207
}
189208

‎test/TensorFlowNET.Examples/ImageProcessing/YOLO/config.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class TrainConfig
6060
public TrainConfig(string root)
6161
{
6262
_root = root;
63-
INITIAL_WEIGHT = Path.Combine(_root, "data", "checkpoint", "yolov3_coco_demo.ckpt");
63+
INITIAL_WEIGHT = Path.Combine(_root, "checkpoint", "yolov3_coco_demo.ckpt");
6464
ANNOT_PATH = Path.Combine(_root, "data", "dataset", "voc_train.txt");
6565
}
6666
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL