| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6c8c2e5 commit e3de673
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,12 @@ | |||
| 18 | 18 | <Description>Google's TensorFlow full binding in .NET Standard. | |
| 19 | 19 | Docs: https://tensorflownet.readthedocs.io</Description> | |
| 20 | 20 | <AssemblyVersion>0.11.0.0</AssemblyVersion> | |
| 21 | - <PackageReleaseNotes>Changes since v0.10.0:</PackageReleaseNotes> | ||
| 21 | + <PackageReleaseNotes>Changes since v0.10.0: | ||
| 22 | + 1. Upgrade NumSharp to v0.20. | ||
| 23 | + 2. Add DisposableObject class to manage object lifetime. | ||
| 24 | + 3. Add tf.no_op, tf.nn.in_top_k, tf.GraphKeys and tf.trainable_variables. | ||
| 25 | + 4. Change tensorflow to non-static class in order to execute some initialization process. | ||
| 26 | + 5. Overloade session.run(), make syntax simpler.</PackageReleaseNotes> | ||
| 22 | 27 | <LangVersion>7.3</LangVersion> | |
| 23 | 28 | <FileVersion>0.11.0.0</FileVersion> | |
| 24 | 29 | <PackageLicenseFile>LICENSE</PackageLicenseFile> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,7 +158,7 @@ private void _init_from_args(object initial_value, | |||
| 158 | 158 | // Or get the initial value from a Tensor or Python object. | |
| 159 | 159 | else | |
| 160 | 160 | { | |
| 161 | - _initial_value = ops.convert_to_tensor(initial_value, name: "initial_value"); | ||
| 161 | + _initial_value = ops.convert_to_tensor(initial_value, name: "initial_value", dtype: dtype); | ||
| 162 | 162 | ||
| 163 | 163 | var shape = _initial_value.shape; | |
| 164 | 164 | dtype = _initial_value.dtype; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -488,6 +488,8 @@ public static Tensor internal_convert_to_tensor(object value, TF_DataType dtype | |||
| 488 | 488 | ||
| 489 | 489 | switch (value) | |
| 490 | 490 | { | |
| 491 | + case String str: | ||
| 492 | + return constant_op.constant(str, dtype: TF_DataType.TF_STRING, name: name); | ||
| 491 | 493 | case NDArray nd: | |
| 492 | 494 | return constant_op.constant(nd, dtype: dtype, name: name); | |
| 493 | 495 | case Tensor tensor: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Text; | ||
| 4 | + | ||
| 5 | + namespace TensorFlowNET.Examples.ImageProcessing.YOLO | ||
| 6 | + { | ||
| 7 | + public class Dataset | ||
| 8 | + { | ||
| 9 | + string annot_path; | ||
| 10 | + public int Length = 0; | ||
| 11 | + | ||
| 12 | + public Dataset(string dataset_type, Config cfg) | ||
| 13 | + { | ||
| 14 | + annot_path = dataset_type == "train" ? cfg.TRAIN.ANNOT_PATH : cfg.TEST.ANNOT_PATH; | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,13 +13,26 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||
| 13 | 13 | /// </summary> | |
| 14 | 14 | public class Main : IExample | |
| 15 | 15 | { | |
| 16 | - public bool Enabled { get; set; } = true; | ||
| 16 | + public bool Enabled { get; set; } = false; | ||
| 17 | 17 | public bool IsImportingGraph { get; set; } = false; | |
| 18 | - | ||
| 19 | 18 | public string Name => "YOLOv3"; | |
| 20 | 19 | ||
| 20 | + #region args | ||
| 21 | 21 | Dictionary<int, string> classes; | |
| 22 | - Config config; | ||
| 22 | + int num_classes; | ||
| 23 | + float learn_rate_init; | ||
| 24 | + float learn_rate_end; | ||
| 25 | + int first_stage_epochs; | ||
| 26 | + int second_stage_epochs; | ||
| 27 | + int warmup_periods; | ||
| 28 | + string time; | ||
| 29 | + float moving_ave_decay; | ||
| 30 | + int max_bbox_per_scale; | ||
| 31 | + int steps_per_period; | ||
| 32 | + | ||
| 33 | + Dataset trainset, testset; | ||
| 34 | + | ||
| 35 | + Config cfg; | ||
| 23 | 36 | ||
| 24 | 37 | Tensor input_data; | |
| 25 | 38 | Tensor label_sbbox; | |
@@ -28,7 +41,8 @@ public class Main : IExample | |||
| 28 | 41 | Tensor true_sbboxes; | |
| 29 | 42 | Tensor true_mbboxes; | |
| 30 | 43 | Tensor true_lbboxes; | |
| 31 | - Tensor trainable; | ||
| 44 | + Tensor trainable; | ||
| 45 | + #endregion | ||
| 32 | 46 | ||
| 33 | 47 | public bool Run() | |
| 34 | 48 | { | |
@@ -90,14 +104,28 @@ public void Predict(Session sess) | |||
| 90 | 104 | ||
| 91 | 105 | public void PrepareData() | |
| 92 | 106 | { | |
| 93 | - config = new Config(Name); | ||
| 107 | + cfg = new Config(Name); | ||
| 94 | 108 | ||
| 95 | 109 | string dataDir = Path.Combine(Name, "data"); | |
| 96 | 110 | Directory.CreateDirectory(dataDir); | |
| 97 | 111 | ||
| 98 | 112 | classes = new Dictionary<int, string>(); | |
| 99 | - foreach (var line in File.ReadAllLines(config.CLASSES)) | ||
| 113 | + foreach (var line in File.ReadAllLines(cfg.YOLO.CLASSES)) | ||
| 100 | 114 | classes[classes.Count] = line; | |
| 115 | + num_classes = classes.Count; | ||
| 116 | + | ||
| 117 | + learn_rate_init = cfg.TRAIN.LEARN_RATE_INIT; | ||
| 118 | + learn_rate_end = cfg.TRAIN.LEARN_RATE_END; | ||
| 119 | + first_stage_epochs = cfg.TRAIN.FISRT_STAGE_EPOCHS; | ||
| 120 | + second_stage_epochs = cfg.TRAIN.SECOND_STAGE_EPOCHS; | ||
| 121 | + warmup_periods = cfg.TRAIN.WARMUP_EPOCHS; | ||
| 122 | + DateTime now = DateTime.Now; | ||
| 123 | + time = $"{now.Year}-{now.Month}-{now.Day}-{now.Hour}-{now.Minute}-{now.Minute}"; | ||
| 124 | + moving_ave_decay = cfg.YOLO.MOVING_AVE_DECAY; | ||
| 125 | + max_bbox_per_scale = 150; | ||
| 126 | + trainset = new Dataset("train", cfg); | ||
| 127 | + testset = new Dataset("test", cfg); | ||
| 128 | + steps_per_period = trainset.Length; | ||
| 101 | 129 | } | |
| 102 | 130 | } | |
| 103 | 131 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,13 +7,52 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||
| 7 | 7 | { | |
| 8 | 8 | public class Config | |
| 9 | 9 | { | |
| 10 | - string _root; | ||
| 11 | - public string CLASSES; | ||
| 10 | + public YoloConfig YOLO; | ||
| 11 | + public TrainConfig TRAIN; | ||
| 12 | + public TrainConfig TEST; | ||
| 12 | 13 | ||
| 13 | 14 | public Config(string root) | |
| 14 | 15 | { | |
| 15 | - _root = root; | ||
| 16 | - CLASSES = Path.Combine(_root, "data", "classes", "coco.names"); | ||
| 16 | + YOLO = new YoloConfig(root); | ||
| 17 | + TRAIN = new TrainConfig(root); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public class YoloConfig | ||
| 21 | + { | ||
| 22 | + string _root; | ||
| 23 | + | ||
| 24 | + public string CLASSES; | ||
| 25 | + public float MOVING_AVE_DECAY = 0.9995f; | ||
| 26 | + public int[] STRIDES = new int[] { 8, 16, 32 }; | ||
| 27 | + | ||
| 28 | + public YoloConfig(string root) | ||
| 29 | + { | ||
| 30 | + _root = root; | ||
| 31 | + CLASSES = Path.Combine(_root, "data", "classes", "coco.names"); | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public class TrainConfig | ||
| 36 | + { | ||
| 37 | + string _root; | ||
| 38 | + | ||
| 39 | + public int BATCH_SIZE = 6; | ||
| 40 | + public int[] INPUT_SIZE = new int[] { 320, 352, 384, 416, 448, 480, 512, 544, 576, 608 }; | ||
| 41 | + public bool DATA_AUG = true; | ||
| 42 | + public float LEARN_RATE_INIT = 1e-4f; | ||
| 43 | + public float LEARN_RATE_END = 1e-6f; | ||
| 44 | + public int WARMUP_EPOCHS = 2; | ||
| 45 | + public int FISRT_STAGE_EPOCHS = 20; | ||
| 46 | + public int SECOND_STAGE_EPOCHS = 30; | ||
| 47 | + public string INITIAL_WEIGHT; | ||
| 48 | + public string ANNOT_PATH; | ||
| 49 | + | ||
| 50 | + public TrainConfig(string root) | ||
| 51 | + { | ||
| 52 | + _root = root; | ||
| 53 | + INITIAL_WEIGHT = Path.Combine(_root, "data", "checkpoint", "yolov3_coco_demo.ckpt"); | ||
| 54 | + ANNOT_PATH = Path.Combine(_root, "data", "dataset", "voc_train.txt"); | ||
| 55 | + } | ||
| 17 | 56 | } | |
| 18 | 57 | } | |
| 19 | 58 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ public void Initializer() | |||
| 24 | 24 | [TestMethod] | |
| 25 | 25 | public void StringVar() | |
| 26 | 26 | { | |
| 27 | - var mammal1 = tf.Variable("Elephant", name: "var1", dtype: tf.chars); | ||
| 27 | + var mammal1 = tf.Variable("Elephant", name: "var1", dtype: tf.@string); | ||
| 28 | 28 | var mammal2 = tf.Variable("Tiger"); | |
| 29 | 29 | } | |
| 30 | 30 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ public class WhileContextTestCase : PythonTest | |||
| 11 | 11 | /// <summary> | |
| 12 | 12 | /// https://www.tensorflow.org/api_docs/python/tf/while_loop | |
| 13 | 13 | /// </summary> | |
| 14 | + [Ignore] | ||
| 14 | 15 | [TestMethod] | |
| 15 | 16 | public void SimpleWhileLoop() | |
| 16 | 17 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments