Example #1
0
        /// <summary>
        /// Program entry point
        /// </summary>
        /// <param name="args">Program arguments (ignored)</param>
        private static void Main(string[] args)
        {
            try
            {
                // The examples assume the executable is running from the data folder
                // We switch the current directory to the data folder (assuming the executable is in the <CNTK>/x64/Debug|Release folder
                Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, @"..\..\Examples\Image\MNIST\Data\");
                
                Dictionary<string, List<float>> outputs;

                using (var model = new IEvaluateModelManagedF())
                {
                    // Initialize model evaluator
                    string config = GetConfig();
                    model.Init(config);

                    // Load model
                    string modelFilePath = Path.Combine(Environment.CurrentDirectory, @"..\Output\Models\01_OneHidden");
                    model.LoadModel(modelFilePath);

                    // Generate random input values in the appropriate structure and size
                    var inputs = GetDictionary("features", 28*28, 255);
                    
                    // We can call the evaluate method and get back the results (single layer)...
                    // List<float> outputList = model.Evaluate(inputs, "ol.z", 10);

                    // ... or we can preallocate the structure and pass it in (multiple output layers)
                    outputs = GetDictionary("ol.z", 10, 1);
                    model.Evaluate(inputs, outputs);                    
                }
                
                Console.WriteLine("--- Output results ---");
                foreach (var item in outputs)
                {
                    Console.WriteLine("Output layer: {0}", item.Key);
                    foreach (var entry in item.Value)
                    {
                        Console.WriteLine(entry);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0} \n {1}", ex, ex.InnerException != null ? ex.InnerException.Message : "No Inner Exception");
            }

            Console.WriteLine("Press <Enter> to terminate.");
            Console.ReadLine();
        }
Example #2
0
        /// <summary>
        /// Program entry point
        /// </summary>
        /// <param name="args">Program arguments (ignored)</param>
        private static void Main(string[] args)
        {
            try
            {
                // The examples assume the executable is running from the data folder
                // We switch the current directory to the data folder (assuming the executable is in the <CNTK>/x64/Debug|Release folder
                Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, @"..\..\Examples\Image\MNIST\Data\");

                Dictionary <string, List <float> > outputs;

                using (var model = new IEvaluateModelManagedF())
                {
                    // Initialize model evaluator
                    string config = GetConfig();
                    model.Init(config);

                    // Load model
                    string modelFilePath = Path.Combine(Environment.CurrentDirectory, @"..\Output\Models\01_OneHidden");
                    model.LoadModel(modelFilePath);

                    // Generate random input values in the appropriate structure and size
                    var inputs = GetDictionary("features", 28 * 28, 255);

                    // We can call the evaluate method and get back the results (single layer)...
                    // List<float> outputList = model.Evaluate(inputs, "ol.z", 10);

                    // ... or we can preallocate the structure and pass it in (multiple output layers)
                    outputs = GetDictionary("ol.z", 10, 1);
                    model.Evaluate(inputs, outputs);
                }

                Console.WriteLine("--- Output results ---");
                foreach (var item in outputs)
                {
                    Console.WriteLine("Output layer: {0}", item.Key);
                    foreach (var entry in item.Value)
                    {
                        Console.WriteLine(entry);
                    }
                }
            }
            catch (CNTKException ex)
            {
                Console.WriteLine("Error: {0}\nNative CallStack: {1}\n Inner Exception: {2}", ex.Message, ex.NativeCallStack, ex.InnerException != null ? ex.InnerException.Message : "No Inner Exception");
            }

            Console.WriteLine("Press <Enter> to terminate.");
            Console.ReadLine();
        }