static void Main(string[] args) { Console.WriteLine("======== Evaluate model using C# GPU Build ========"); Console.WriteLine(" ====== Run evaluation on CPU ====="); // Evalaute a single image. CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.CPUDevice); // Evaluate a batch of images CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.CPUDevice); // Evaluate multiple sample requests in parallel CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(DeviceDescriptor.CPUDevice); // Evaluate a single sequence with one-hot vector CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.CPUDevice); // Evalaute a batch of variable length sequences with one-hot vector CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.CPUDevice); // Use GPU for evaluation. Console.WriteLine(" ====== Run evaluation on GPU ====="); CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.GPUDevice(0)); Console.WriteLine("======== Evaluation completes. ========"); }
static void Main(string[] args) { Console.WriteLine("======== Evaluate model using C# CPUOnly Build ========"); // Evalaute a single image. CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.CPUDevice); // Evaluate a batch of images CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.CPUDevice); // Evaluate an image asynchronously Task evalTask = CNTKLibraryManagedExamples.EvaluationSingleImageAsync(DeviceDescriptor.CPUDevice); evalTask.Wait(); // Evaluate multiple sample requests in parallel CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(DeviceDescriptor.CPUDevice); // Evaluate a single sequence with one-hot vector CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.CPUDevice); // Evalaute a batch of variable length sequences with one-hot vector CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.CPUDevice); Console.WriteLine("======== Evaluation completes. ========"); }
static void Main(string[] args) { #if CPUONLY Console.WriteLine("======== Evaluate model on CPU using CPUOnly build ========"); #else Console.WriteLine("======== Evaluate model on CPU using GPU build ========"); #endif CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.CPUDevice); if (IsGPUAvailable()) { Console.WriteLine(" ====== Evaluate model on GPU ====="); CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.GPUDevice(0)); } Console.WriteLine("======== Evaluation completes. ========"); }
static void Main(string[] args) { #if CPUONLY Console.WriteLine("======== Evaluate model on CPU using CPUOnly build ========"); #else Console.WriteLine("======== Evaluate model on CPU using GPU build ========"); #endif if (ShouldRunOnCpu()) { CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.CPUDevice); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.CPUDevice); // It is sufficient to test loading model from memory buffer only on CPU. CNTKLibraryManagedExamples.LoadModelFromMemory(DeviceDescriptor.CPUDevice); } if (ShouldRunOnGpu()) { Console.WriteLine(" ====== Evaluate model on GPU ====="); CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.GPUDevice(0)); } Console.WriteLine("======== Evaluation completes. ========"); }
static void Main(string[] args) { Console.WriteLine("======== Evaluate model using C# GPU Build ========"); Console.WriteLine(" ====== Run evaluation on CPU ====="); // Evaluate a single image. CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.CPUDevice); // Evaluate a batch of images. CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.CPUDevice); // Evaluate multiple sample requests in parallel. CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallelAsync(DeviceDescriptor.CPUDevice).Wait(); // Evaluate an image asynchronously. Task evalTask = CNTKLibraryManagedExamples.EvaluationSingleImageAsync(DeviceDescriptor.CPUDevice); evalTask.Wait(); // Evaluate a single sequence using one-hot vector input. CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.CPUDevice); // Evaluate a batch of variable length sequences with one-hot vector input. CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.CPUDevice); // Evaluate a sequence using sparse input. CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingSparse(DeviceDescriptor.CPUDevice); // Load model from memory buffer. CNTKLibraryManagedExamples.LoadModelFromMemory(DeviceDescriptor.CPUDevice); // Use GPU for evaluation. Console.WriteLine(" ====== Run evaluation on GPU ====="); CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.GPUDevice(0)); // Evaluate an image asynchronously evalTask = CNTKLibraryManagedExamples.EvaluationSingleImageAsync(DeviceDescriptor.GPUDevice(0)); evalTask.Wait(); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallelAsync(DeviceDescriptor.GPUDevice(0)).Wait(); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingSparse(DeviceDescriptor.GPUDevice(0)); CNTKLibraryManagedExamples.LoadModelFromMemory(DeviceDescriptor.GPUDevice(0)); // Evaluate intermediate layer. CNTKLibraryManagedExamples.EvaluateIntermediateLayer(DeviceDescriptor.GPUDevice(0)); // Evaluate combined outputs. CNTKLibraryManagedExamples.EvaluateCombinedOutputs(DeviceDescriptor.GPUDevice(0)); Console.WriteLine("======== Evaluation completes. ========"); }
static void Main(string[] args) { #if CPUONLY Console.WriteLine("======== Evaluate model on CPU using CPUOnly build ========"); #else Console.WriteLine("======== Evaluate model on CPU using GPU build ========"); #endif if (ShouldRunOnCpu()) { var device = DeviceDescriptor.CPUDevice; CNTKLibraryManagedExamples.EvaluationSingleImage(device); // Run memory tests. MemoryTests.ValidateObjectReferences(device); CNTKLibraryManagedExamples.EvaluationBatchOfImages(device); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(device); // Run memory tests again. MemoryTests.ValidateObjectReferences(device); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingSparse(device); // It is sufficient to test loading model from memory buffer only on CPU. CNTKLibraryManagedExamples.LoadModelFromMemory(device); MemoryTests.WriteOutputs(); } if (ShouldRunOnGpu()) { Console.WriteLine(" ====== Evaluate model on GPU ====="); var device = DeviceDescriptor.GPUDevice(0); // Run memory tests. MemoryTests.ValidateObjectReferences(device); CNTKLibraryManagedExamples.EvaluationSingleImage(device); CNTKLibraryManagedExamples.EvaluationBatchOfImages(device); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallel(device); // Run memory tests. MemoryTests.ValidateObjectReferences(device); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingSparse(device); // Run memory tests again. MemoryTests.WriteOutputs(); } Console.WriteLine("======== Evaluation completes. ========"); }
static void Main(string[] args) { Console.WriteLine("======== Evaluate model using C# CPUOnly Build ========"); // Evalaute a single image. CNTKLibraryManagedExamples.EvaluationSingleImage(DeviceDescriptor.CPUDevice); // Evaluate a batch of images CNTKLibraryManagedExamples.EvaluationBatchOfImages(DeviceDescriptor.CPUDevice); // Evaluate a single sequence with one-hot vector CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(DeviceDescriptor.CPUDevice); // Evalaute a batch of variable length sequences with one-hot vector CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(DeviceDescriptor.CPUDevice); Console.WriteLine("======== Evaluation completes. ========"); }
static void Main(string[] args) { // Todo: move to a separate unit test. Console.WriteLine("Test Utils"); int maxThreads = Utils.GetMaxNumCPUThreads(); Utils.SetMaxNumCPUThreads(2); Console.WriteLine("MaxNumCPUThreads: before: " + maxThreads + ", after " + Utils.GetMaxNumCPUThreads()); Utils.SetMaxNumCPUThreads(maxThreads); Console.WriteLine("reset MaxNumCPuThreads to " + Utils.GetMaxNumCPUThreads()); var level = Utils.GetTraceLevel(); Utils.SetTraceLevel(TraceLevel.Info); Console.WriteLine("TraceLevel: before: " + level + ", after " + Utils.GetTraceLevel()); Utils.SetTraceLevel(level); Console.WriteLine("reset TraceLevel to " + Utils.GetTraceLevel()); Console.WriteLine(Utils.DataTypeName(DataType.Float)); Console.WriteLine(Utils.DataTypeSize(DataType.Double)); Console.WriteLine(Utils.DeviceKindName(DeviceDescriptor.CPUDevice.Type)); Console.WriteLine(Utils.DeviceKindName(DeviceKind.GPU)); Console.WriteLine(Utils.IsSparseStorageFormat(StorageFormat.Dense)); Console.WriteLine(Utils.IsSparseStorageFormat(StorageFormat.SparseCSC)); Console.WriteLine(Utils.IsSparseStorageFormat(StorageFormat.SparseBlockCol)); Console.WriteLine(Utils.VariableKindName(VariableKind.Constant)); Console.WriteLine(Utils.VariableKindName(VariableKind.Placeholder)); Console.WriteLine(Utils.VariableKindName(VariableKind.Input)); Console.WriteLine(Utils.VariableKindName(VariableKind.Output)); Console.WriteLine(Utils.VariableKindName(VariableKind.Parameter)); #if CPUONLY Console.WriteLine("======== Evaluate model on CPU using CPUOnly build ========"); #else Console.WriteLine("======== Evaluate model on CPU using GPU build ========"); #endif if (args.Length >= 1) { Console.WriteLine($"-------- running with test data in {args[0]} --------"); CNTKLibraryManagedExamples.ExampleTestDataDir = args[0]; } CNTKLibraryManagedExamples.Setup(); if (ShouldRunOnCpu()) { var device = DeviceDescriptor.CPUDevice; CNTKLibraryManagedExamples.EvaluationSingleImage(device); // Run memory tests. MemoryTests.ValidateObjectReferences(device); CNTKLibraryManagedExamples.EvaluationBatchOfImages(device); MemoryTests.WriteOutputs(); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallelAsync(device).Wait(); // Run memory tests again. MemoryTests.ValidateObjectReferences(device); Task evalTask = CNTKLibraryManagedExamples.EvaluationSingleImageAsync(device); evalTask.Wait(); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingSparse(device); // It is sufficient to test loading model from memory buffer only on CPU. CNTKLibraryManagedExamples.LoadModelFromMemory(device); MemoryTests.WriteOutputs(); MemoryTests.ValueCopyToSparseCSCTest <float>(device); MemoryTests.ValueCopyToSparseCSCTest <double>(device); CNTKLibraryManagedExamples.EvaluateIntermediateLayer(device); CNTKLibraryManagedExamples.EvaluateCombinedOutputs(device); } if (ShouldRunOnGpu()) { Console.WriteLine(" ====== Evaluate model on GPU ====="); var device = DeviceDescriptor.GPUDevice(0); // Run memory tests. MemoryTests.ValidateObjectReferences(device); CNTKLibraryManagedExamples.EvaluationSingleImage(device); CNTKLibraryManagedExamples.EvaluationBatchOfImages(device); CNTKLibraryManagedExamples.EvaluateMultipleImagesInParallelAsync(device).Wait(); // Run memory tests. MemoryTests.ValidateObjectReferences(device); Task evalTask = CNTKLibraryManagedExamples.EvaluationSingleImageAsync(device); evalTask.Wait(); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationBatchOfSequencesUsingOneHot(device); CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingSparse(device); // Run memory tests again. MemoryTests.WriteOutputs(); MemoryTests.ValueCopyToSparseCSCTest <float>(device); MemoryTests.ValueCopyToSparseCSCTest <double>(device); CNTKLibraryManagedExamples.EvaluateIntermediateLayer(device); CNTKLibraryManagedExamples.EvaluateCombinedOutputs(device); } Console.WriteLine("======== Evaluation completes. ========"); }