@@ -18,7 +18,12 @@ | |||||
<Description>Google's TensorFlow full binding in .NET Standard. | <Description>Google's TensorFlow full binding in .NET Standard. | ||||
Docs: https://tensorflownet.readthedocs.io</Description> | Docs: https://tensorflownet.readthedocs.io</Description> | ||||
<AssemblyVersion>0.11.0.0</AssemblyVersion> | <AssemblyVersion>0.11.0.0</AssemblyVersion> | ||||
<PackageReleaseNotes>Changes since v0.10.0:</PackageReleaseNotes> | |||||
<PackageReleaseNotes>Changes since v0.10.0: | |||||
1. Upgrade NumSharp to v0.20. | |||||
2. Add DisposableObject class to manage object lifetime. | |||||
3. Add tf.no_op, tf.nn.in_top_k, tf.GraphKeys and tf.trainable_variables. | |||||
4. Change tensorflow to non-static class in order to execute some initialization process. | |||||
5. Overloade session.run(), make syntax simpler.</PackageReleaseNotes> | |||||
<LangVersion>7.3</LangVersion> | <LangVersion>7.3</LangVersion> | ||||
<FileVersion>0.11.0.0</FileVersion> | <FileVersion>0.11.0.0</FileVersion> | ||||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | <PackageLicenseFile>LICENSE</PackageLicenseFile> | ||||
@@ -158,7 +158,7 @@ namespace Tensorflow | |||||
// Or get the initial value from a Tensor or Python object. | // Or get the initial value from a Tensor or Python object. | ||||
else | else | ||||
{ | { | ||||
_initial_value = ops.convert_to_tensor(initial_value, name: "initial_value"); | |||||
_initial_value = ops.convert_to_tensor(initial_value, name: "initial_value", dtype: dtype); | |||||
var shape = _initial_value.shape; | var shape = _initial_value.shape; | ||||
dtype = _initial_value.dtype; | dtype = _initial_value.dtype; | ||||
@@ -488,6 +488,8 @@ namespace Tensorflow | |||||
switch (value) | switch (value) | ||||
{ | { | ||||
case String str: | |||||
return constant_op.constant(str, dtype: TF_DataType.TF_STRING, name: name); | |||||
case NDArray nd: | case NDArray nd: | ||||
return constant_op.constant(nd, dtype: dtype, name: name); | return constant_op.constant(nd, dtype: dtype, name: name); | ||||
case Tensor tensor: | case Tensor tensor: | ||||
@@ -0,0 +1,17 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||||
{ | |||||
public class Dataset | |||||
{ | |||||
string annot_path; | |||||
public int Length = 0; | |||||
public Dataset(string dataset_type, Config cfg) | |||||
{ | |||||
annot_path = dataset_type == "train" ? cfg.TRAIN.ANNOT_PATH : cfg.TEST.ANNOT_PATH; | |||||
} | |||||
} | |||||
} |
@@ -13,13 +13,26 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||||
/// </summary> | /// </summary> | ||||
public class Main : IExample | public class Main : IExample | ||||
{ | { | ||||
public bool Enabled { get; set; } = true; | |||||
public bool Enabled { get; set; } = false; | |||||
public bool IsImportingGraph { get; set; } = false; | public bool IsImportingGraph { get; set; } = false; | ||||
public string Name => "YOLOv3"; | public string Name => "YOLOv3"; | ||||
#region args | |||||
Dictionary<int, string> classes; | Dictionary<int, string> classes; | ||||
Config config; | |||||
int num_classes; | |||||
float learn_rate_init; | |||||
float learn_rate_end; | |||||
int first_stage_epochs; | |||||
int second_stage_epochs; | |||||
int warmup_periods; | |||||
string time; | |||||
float moving_ave_decay; | |||||
int max_bbox_per_scale; | |||||
int steps_per_period; | |||||
Dataset trainset, testset; | |||||
Config cfg; | |||||
Tensor input_data; | Tensor input_data; | ||||
Tensor label_sbbox; | Tensor label_sbbox; | ||||
@@ -28,7 +41,8 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||||
Tensor true_sbboxes; | Tensor true_sbboxes; | ||||
Tensor true_mbboxes; | Tensor true_mbboxes; | ||||
Tensor true_lbboxes; | Tensor true_lbboxes; | ||||
Tensor trainable; | |||||
Tensor trainable; | |||||
#endregion | |||||
public bool Run() | public bool Run() | ||||
{ | { | ||||
@@ -90,14 +104,28 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||||
public void PrepareData() | public void PrepareData() | ||||
{ | { | ||||
config = new Config(Name); | |||||
cfg = new Config(Name); | |||||
string dataDir = Path.Combine(Name, "data"); | string dataDir = Path.Combine(Name, "data"); | ||||
Directory.CreateDirectory(dataDir); | Directory.CreateDirectory(dataDir); | ||||
classes = new Dictionary<int, string>(); | classes = new Dictionary<int, string>(); | ||||
foreach (var line in File.ReadAllLines(config.CLASSES)) | |||||
foreach (var line in File.ReadAllLines(cfg.YOLO.CLASSES)) | |||||
classes[classes.Count] = line; | classes[classes.Count] = line; | ||||
num_classes = classes.Count; | |||||
learn_rate_init = cfg.TRAIN.LEARN_RATE_INIT; | |||||
learn_rate_end = cfg.TRAIN.LEARN_RATE_END; | |||||
first_stage_epochs = cfg.TRAIN.FISRT_STAGE_EPOCHS; | |||||
second_stage_epochs = cfg.TRAIN.SECOND_STAGE_EPOCHS; | |||||
warmup_periods = cfg.TRAIN.WARMUP_EPOCHS; | |||||
DateTime now = DateTime.Now; | |||||
time = $"{now.Year}-{now.Month}-{now.Day}-{now.Hour}-{now.Minute}-{now.Minute}"; | |||||
moving_ave_decay = cfg.YOLO.MOVING_AVE_DECAY; | |||||
max_bbox_per_scale = 150; | |||||
trainset = new Dataset("train", cfg); | |||||
testset = new Dataset("test", cfg); | |||||
steps_per_period = trainset.Length; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -7,13 +7,52 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||||
{ | { | ||||
public class Config | public class Config | ||||
{ | { | ||||
string _root; | |||||
public string CLASSES; | |||||
public YoloConfig YOLO; | |||||
public TrainConfig TRAIN; | |||||
public TrainConfig TEST; | |||||
public Config(string root) | public Config(string root) | ||||
{ | { | ||||
_root = root; | |||||
CLASSES = Path.Combine(_root, "data", "classes", "coco.names"); | |||||
YOLO = new YoloConfig(root); | |||||
TRAIN = new TrainConfig(root); | |||||
} | |||||
public class YoloConfig | |||||
{ | |||||
string _root; | |||||
public string CLASSES; | |||||
public float MOVING_AVE_DECAY = 0.9995f; | |||||
public int[] STRIDES = new int[] { 8, 16, 32 }; | |||||
public YoloConfig(string root) | |||||
{ | |||||
_root = root; | |||||
CLASSES = Path.Combine(_root, "data", "classes", "coco.names"); | |||||
} | |||||
} | |||||
public class TrainConfig | |||||
{ | |||||
string _root; | |||||
public int BATCH_SIZE = 6; | |||||
public int[] INPUT_SIZE = new int[] { 320, 352, 384, 416, 448, 480, 512, 544, 576, 608 }; | |||||
public bool DATA_AUG = true; | |||||
public float LEARN_RATE_INIT = 1e-4f; | |||||
public float LEARN_RATE_END = 1e-6f; | |||||
public int WARMUP_EPOCHS = 2; | |||||
public int FISRT_STAGE_EPOCHS = 20; | |||||
public int SECOND_STAGE_EPOCHS = 30; | |||||
public string INITIAL_WEIGHT; | |||||
public string ANNOT_PATH; | |||||
public TrainConfig(string root) | |||||
{ | |||||
_root = root; | |||||
INITIAL_WEIGHT = Path.Combine(_root, "data", "checkpoint", "yolov3_coco_demo.ckpt"); | |||||
ANNOT_PATH = Path.Combine(_root, "data", "dataset", "voc_train.txt"); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -24,7 +24,7 @@ namespace TensorFlowNET.UnitTest | |||||
[TestMethod] | [TestMethod] | ||||
public void StringVar() | public void StringVar() | ||||
{ | { | ||||
var mammal1 = tf.Variable("Elephant", name: "var1", dtype: tf.chars); | |||||
var mammal1 = tf.Variable("Elephant", name: "var1", dtype: tf.@string); | |||||
var mammal2 = tf.Variable("Tiger"); | var mammal2 = tf.Variable("Tiger"); | ||||
} | } | ||||
@@ -11,6 +11,7 @@ namespace TensorFlowNET.UnitTest.control_flow_ops_test | |||||
/// <summary> | /// <summary> | ||||
/// https://www.tensorflow.org/api_docs/python/tf/while_loop | /// https://www.tensorflow.org/api_docs/python/tf/while_loop | ||||
/// </summary> | /// </summary> | ||||
[Ignore] | |||||
[TestMethod] | [TestMethod] | ||||
public void SimpleWhileLoop() | public void SimpleWhileLoop() | ||||
{ | { | ||||