| @@ -11,7 +11,9 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class BasicEagerApi : IExample | public class BasicEagerApi : IExample | ||||
| { | { | ||||
| public int Priority => 100; | |||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public string Name => "Basic Eager"; | |||||
| private Tensor a, b, c, d; | private Tensor a, b, c, d; | ||||
| @@ -13,6 +13,9 @@ namespace TensorFlowNET.Examples | |||||
| public class BasicOperations : Python, IExample | public class BasicOperations : Python, IExample | ||||
| { | { | ||||
| public bool Enabled => true; | public bool Enabled => true; | ||||
| public int Priority => 2; | |||||
| public string Name => "Basic Operations"; | |||||
| private Session sess; | private Session sess; | ||||
| public bool Run() | public bool Run() | ||||
| @@ -11,7 +11,10 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class HelloWorld : Python, IExample | public class HelloWorld : Python, IExample | ||||
| { | { | ||||
| public int Priority => 1; | |||||
| public bool Enabled => true; | public bool Enabled => true; | ||||
| public string Name => "Hello World"; | |||||
| public bool Run() | public bool Run() | ||||
| { | { | ||||
| /* Create a Constant op | /* Create a Constant op | ||||
| @@ -10,8 +10,25 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public interface IExample | public interface IExample | ||||
| { | { | ||||
| /// <summary> | |||||
| /// running order | |||||
| /// </summary> | |||||
| int Priority { get; } | |||||
| /// <summary> | |||||
| /// True to run example | |||||
| /// </summary> | |||||
| bool Enabled { get; } | bool Enabled { get; } | ||||
| string Name { get; } | |||||
| /// <summary> | |||||
| /// Build dataflow graph, train and predict | |||||
| /// </summary> | |||||
| /// <returns></returns> | |||||
| bool Run(); | bool Run(); | ||||
| /// <summary> | |||||
| /// Prepare dataset | |||||
| /// </summary> | |||||
| void PrepareData(); | void PrepareData(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -12,7 +12,9 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| public class ImageRecognition : Python, IExample | public class ImageRecognition : Python, IExample | ||||
| { | { | ||||
| public int Priority => 5; | |||||
| public bool Enabled => true; | public bool Enabled => true; | ||||
| public string Name => "Image Recognition"; | |||||
| string dir = "ImageRecognition"; | string dir = "ImageRecognition"; | ||||
| string pbFile = "tensorflow_inception_graph.pb"; | string pbFile = "tensorflow_inception_graph.pb"; | ||||
| @@ -20,6 +20,9 @@ namespace TensorFlowNET.Examples | |||||
| public class InceptionArchGoogLeNet : Python, IExample | public class InceptionArchGoogLeNet : Python, IExample | ||||
| { | { | ||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public int Priority => 100; | |||||
| public string Name => "Inception Arch GoogLeNet"; | |||||
| string dir = "label_image_data"; | string dir = "label_image_data"; | ||||
| string pbFile = "inception_v3_2016_08_28_frozen.pb"; | string pbFile = "inception_v3_2016_08_28_frozen.pb"; | ||||
| string labelFile = "imagenet_slim_labels.txt"; | string labelFile = "imagenet_slim_labels.txt"; | ||||
| @@ -12,7 +12,9 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class LinearRegression : Python, IExample | public class LinearRegression : Python, IExample | ||||
| { | { | ||||
| public int Priority => 3; | |||||
| public bool Enabled => true; | public bool Enabled => true; | ||||
| public string Name => "Linear Regression"; | |||||
| NumPyRandom rng = np.random; | NumPyRandom rng = np.random; | ||||
| @@ -17,7 +17,10 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class LogisticRegression : Python, IExample | public class LogisticRegression : Python, IExample | ||||
| { | { | ||||
| public int Priority => 4; | |||||
| public bool Enabled => true; | public bool Enabled => true; | ||||
| public string Name => "Logistic Regression"; | |||||
| private float learning_rate = 0.01f; | private float learning_rate = 0.01f; | ||||
| private int training_epochs = 10; | private int training_epochs = 10; | ||||
| private int batch_size = 100; | private int batch_size = 100; | ||||
| @@ -9,7 +9,9 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| public class MetaGraph : Python, IExample | public class MetaGraph : Python, IExample | ||||
| { | { | ||||
| public int Priority => 100; | |||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public string Name => "Meta Graph"; | |||||
| public bool Run() | public bool Run() | ||||
| { | { | ||||
| @@ -12,7 +12,10 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class NaiveBayesClassifier : Python, IExample | public class NaiveBayesClassifier : Python, IExample | ||||
| { | { | ||||
| public int Priority => 100; | |||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public string Name => "Naive Bayes Classifier"; | |||||
| public Normal dist { get; set; } | public Normal dist { get; set; } | ||||
| public bool Run() | public bool Run() | ||||
| { | { | ||||
| @@ -10,7 +10,10 @@ namespace TensorFlowNET.Examples | |||||
| /// </summary> | /// </summary> | ||||
| public class NamedEntityRecognition : Python, IExample | public class NamedEntityRecognition : Python, IExample | ||||
| { | { | ||||
| public int Priority => 100; | |||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public string Name => "NER"; | |||||
| public bool Run() | public bool Run() | ||||
| { | { | ||||
| throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
| @@ -15,32 +15,35 @@ namespace TensorFlowNET.Examples | |||||
| var errors = new List<string>(); | var errors = new List<string>(); | ||||
| var success = new List<string>(); | var success = new List<string>(); | ||||
| var disabled = new List<string>(); | var disabled = new List<string>(); | ||||
| var examples = assembly.GetTypes() | |||||
| .Where(x => x.GetInterfaces().Contains(typeof(IExample))) | |||||
| .Select(x => (IExample)Activator.CreateInstance(x)) | |||||
| .OrderBy(x => x.Priority) | |||||
| .ToArray(); | |||||
| foreach (Type type in assembly.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(IExample)))) | |||||
| foreach (IExample example in examples) | |||||
| { | { | ||||
| if (args.Length > 0 && !args.Contains(type.Name)) | |||||
| if (args.Length > 0 && !args.Contains(example.Name)) | |||||
| continue; | continue; | ||||
| Console.WriteLine($"{DateTime.UtcNow} Starting {type.Name}", Color.Tan); | |||||
| var example = (IExample)Activator.CreateInstance(type); | |||||
| Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White); | |||||
| try | try | ||||
| { | { | ||||
| if (example.Enabled) | if (example.Enabled) | ||||
| if (example.Run()) | if (example.Run()) | ||||
| success.Add(type.Name); | |||||
| success.Add($"{example.Priority} {example.Name}"); | |||||
| else | else | ||||
| errors.Add(type.Name); | |||||
| errors.Add($"{example.Priority} {example.Name}"); | |||||
| else | else | ||||
| disabled.Add(type.Name); | |||||
| disabled.Add($"{example.Priority} {example.Name}"); | |||||
| } | } | ||||
| catch (Exception ex) | catch (Exception ex) | ||||
| { | { | ||||
| Console.WriteLine(ex); | Console.WriteLine(ex); | ||||
| } | } | ||||
| Console.WriteLine($"{DateTime.UtcNow} Completed {type.Name}", Color.Tan); | |||||
| Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White); | |||||
| } | } | ||||
| success.ForEach(x => Console.WriteLine($"{x} example is OK!", Color.Green)); | success.ForEach(x => Console.WriteLine($"{x} example is OK!", Color.Green)); | ||||
| @@ -15,7 +15,10 @@ namespace TensorFlowNET.Examples.CnnTextClassification | |||||
| /// </summary> | /// </summary> | ||||
| public class TextClassificationTrain : Python, IExample | public class TextClassificationTrain : Python, IExample | ||||
| { | { | ||||
| public int Priority => 100; | |||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public string Name => "Text Classification"; | |||||
| private string dataDir = "text_classification"; | private string dataDir = "text_classification"; | ||||
| private string dataFileName = "dbpedia_csv.tar.gz"; | private string dataFileName = "dbpedia_csv.tar.gz"; | ||||
| @@ -11,7 +11,10 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| public class TextClassificationWithMovieReviews : Python, IExample | public class TextClassificationWithMovieReviews : Python, IExample | ||||
| { | { | ||||
| public int Priority => 6; | |||||
| public bool Enabled => false; | public bool Enabled => false; | ||||
| public string Name => "Movie Reviews"; | |||||
| string dir = "text_classification_with_movie_reviews"; | string dir = "text_classification_with_movie_reviews"; | ||||
| string dataFile = "imdb.zip"; | string dataFile = "imdb.zip"; | ||||
| NDArray train_data, train_labels, test_data, test_labels; | NDArray train_data, train_labels, test_data, test_labels; | ||||