Merge branch 'master' into yanchen/docker-copy
This commit is contained in:
Коммит
70cf3a39bc
|
@ -19,8 +19,39 @@ using CNTKImageProcessing;
|
|||
|
||||
namespace CNTKLibraryCSEvalExamples
|
||||
{
|
||||
public class CNTKLibraryManagedExamples
|
||||
public static class CNTKLibraryManagedExamples
|
||||
{
|
||||
/// <summary>
|
||||
/// Data used for all the example tests
|
||||
/// </summary>
|
||||
public static string ExampleTestDataDir;
|
||||
|
||||
/// <summary>
|
||||
/// Vocal data used for sequence tests
|
||||
/// </summary>
|
||||
private static string VocabFile;
|
||||
|
||||
/// <summary>
|
||||
/// Lable data used for sequence tests
|
||||
/// </summary>
|
||||
private static string LabelFile;
|
||||
|
||||
/// <summary>
|
||||
/// Single sample image
|
||||
/// </summary>
|
||||
private static string SampleImage;
|
||||
|
||||
/// <summary>
|
||||
/// Set up commonly used file paths
|
||||
/// </summary>
|
||||
public static void Setup()
|
||||
{
|
||||
ExampleTestDataDir = string.IsNullOrEmpty(ExampleTestDataDir) ? ExampleTestDataDir : ExampleTestDataDir + "\\";
|
||||
VocabFile = ExampleTestDataDir + "query.wl";
|
||||
LabelFile = ExampleTestDataDir + "slots.wl";
|
||||
SampleImage = ExampleTestDataDir + "00000.png";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The example shows
|
||||
/// - how to load model.
|
||||
|
@ -39,7 +70,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Load the model.
|
||||
// The model resnet20.dnn is trained by <CNTK>/Examples/Image/Classification/ResNet/Python/TrainResNet_CIFAR10.py
|
||||
// Please see README.md in <CNTK>/Examples/Image/Classification/ResNet about how to train the model.
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "resnet20.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
|
||||
Function modelFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
|
@ -55,9 +86,8 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Image preprocessing to match input requirements of the model.
|
||||
// This program uses images from the CIFAR-10 dataset for evaluation.
|
||||
// Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.
|
||||
string sampleImage = "00000.png";
|
||||
ThrowIfFileNotExist(sampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", sampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(sampleImage));
|
||||
ThrowIfFileNotExist(SampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", SampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(SampleImage));
|
||||
var resized = bmp.Resize(imageWidth, imageHeight, true);
|
||||
List<float> resizedCHW = resized.ParallelExtractCHW();
|
||||
|
||||
|
@ -83,7 +113,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
var outputVal = outputDataMap[outputVar];
|
||||
var outputData = outputVal.GetDenseData<float>(outputVar);
|
||||
|
||||
Console.WriteLine("Evaluation result for image " + sampleImage);
|
||||
Console.WriteLine("Evaluation result for image " + SampleImage);
|
||||
PrintOutput(outputVar.Shape.TotalSize, outputData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -108,10 +138,10 @@ namespace CNTKLibraryCSEvalExamples
|
|||
{
|
||||
Console.WriteLine("\n===== Evaluate batch of images =====");
|
||||
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "resnet20.dnn";
|
||||
// This program uses images from the CIFAR-10 dataset for evaluation.
|
||||
// Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.
|
||||
var imageList = new List<string>() { "00000.png", "00001.png", "00002.png" };
|
||||
var imageList = new List<string>() { ExampleTestDataDir + "00000.png", ExampleTestDataDir + "00001.png", ExampleTestDataDir + "00002.png" };
|
||||
foreach (var image in imageList)
|
||||
{
|
||||
ThrowIfFileNotExist(image, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", image));
|
||||
|
@ -196,12 +226,12 @@ namespace CNTKLibraryCSEvalExamples
|
|||
{
|
||||
Console.WriteLine("\n===== Evaluate multiple images in parallel =====");
|
||||
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "resnet20.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
|
||||
|
||||
// This program uses images from the CIFAR-10 dataset for evaluation.
|
||||
// Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.
|
||||
var imageFiles = new string[] { "00000.png", "00001.png", "00002.png", "00003.png", "00004.png" };
|
||||
var imageFiles = new string[] { ExampleTestDataDir + "00000.png", ExampleTestDataDir + "00001.png", ExampleTestDataDir + "00002.png", ExampleTestDataDir + "00003.png", ExampleTestDataDir + "00004.png" };
|
||||
var imageList = new BlockingCollection<string>();
|
||||
foreach (var file in imageFiles)
|
||||
{
|
||||
|
@ -304,7 +334,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// For demo purpose, we first read the model into memory
|
||||
// The model resnet20.dnn is trained by <CNTK>/Examples/Image/Classification/ResNet/Python/TrainResNet_CIFAR10.py
|
||||
// Please see README.md in <CNTK>/Examples/Image/Classification/ResNet about how to train the model.
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "resnet20.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
|
||||
var modelBuffer = File.ReadAllBytes(modelFilePath);
|
||||
|
||||
|
@ -320,9 +350,8 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Image preprocessing to match input requirements of the model.
|
||||
// This program uses images from the CIFAR-10 dataset for evaluation.
|
||||
// Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.
|
||||
string sampleImage = "00000.png";
|
||||
ThrowIfFileNotExist(sampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", sampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(sampleImage));
|
||||
ThrowIfFileNotExist(SampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", SampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(SampleImage));
|
||||
var resized = bmp.Resize(imageWidth, imageHeight, true);
|
||||
List<float> resizedCHW = resized.ParallelExtractCHW();
|
||||
|
||||
|
@ -370,7 +399,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Load the model.
|
||||
// The model resnet20.dnn is trained by <CNTK>/Examples/Image/Classification/ResNet/Python/Models/TrainResNet_CIFAR10.py
|
||||
// Please see README.md in <CNTK>/Examples/Image/Classification/ResNet about how to train the model.
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "resnet20.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
|
||||
Function modelFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
|
@ -385,9 +414,8 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Image preprocessing to match input requirements of the model.
|
||||
// This program uses images from the CIFAR-10 dataset for evaluation.
|
||||
// Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.
|
||||
string sampleImage = "00000.png";
|
||||
ThrowIfFileNotExist(sampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", sampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(sampleImage));
|
||||
ThrowIfFileNotExist(SampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", SampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(SampleImage));
|
||||
var resized = bmp.Resize(imageWidth, imageHeight, true);
|
||||
List<float> resizedCHW = resized.ParallelExtractCHW();
|
||||
|
||||
|
@ -478,17 +506,15 @@ namespace CNTKLibraryCSEvalExamples
|
|||
|
||||
// The model atis.dnn is trained by <CNTK>/Examples/LanguageUnderstanding/ATIS/Python/LanguageUnderstanding.py
|
||||
// Please see README.md in <CNTK>/Examples/LanguageUnderstanding/ATIS about how to train the model.
|
||||
string modelFilePath = "atis.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "atis.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/LanguageUnderstanding/ATIS to create the model.", modelFilePath));
|
||||
Function modelFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
// Read word and slot index files.
|
||||
string vocabFile = "query.wl";
|
||||
string labelFile = "slots.wl";
|
||||
ThrowIfFileNotExist(vocabFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", vocabFile));
|
||||
ThrowIfFileNotExist(labelFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", labelFile));
|
||||
var vocabToIndex = buildVocabIndex(vocabFile);
|
||||
var indexToSlots = buildSlotIndex(labelFile);
|
||||
ThrowIfFileNotExist(VocabFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", VocabFile));
|
||||
ThrowIfFileNotExist(LabelFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", LabelFile));
|
||||
var vocabToIndex = buildVocabIndex(VocabFile);
|
||||
var indexToSlots = buildSlotIndex(LabelFile);
|
||||
|
||||
// Get input variable
|
||||
var inputVar = modelFunc.Arguments.Single();
|
||||
|
@ -586,17 +612,15 @@ namespace CNTKLibraryCSEvalExamples
|
|||
|
||||
// The model atis.dnn is trained by <CNTK>/Examples/LanguageUnderstanding/ATIS/Python/LanguageUnderstanding.py
|
||||
// Please see README.md in <CNTK>/Examples/LanguageUnderstanding/ATIS about how to train the model.
|
||||
string modelFilePath = "atis.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "atis.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/LanguageUnderstanding/ATIS to create the model.", modelFilePath));
|
||||
Function modelFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
// Read word and slot index files.
|
||||
string vocabFile = "query.wl";
|
||||
string labelFile = "slots.wl";
|
||||
ThrowIfFileNotExist(vocabFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", vocabFile));
|
||||
ThrowIfFileNotExist(labelFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", labelFile));
|
||||
var vocabToIndex = buildVocabIndex(vocabFile);
|
||||
var indexToSlots = buildSlotIndex(labelFile);
|
||||
ThrowIfFileNotExist(VocabFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", VocabFile));
|
||||
ThrowIfFileNotExist(LabelFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", LabelFile));
|
||||
var vocabToIndex = buildVocabIndex(VocabFile);
|
||||
var indexToSlots = buildSlotIndex(LabelFile);
|
||||
|
||||
// Get input variable.
|
||||
var inputVar = modelFunc.Arguments.Single();
|
||||
|
@ -713,17 +737,15 @@ namespace CNTKLibraryCSEvalExamples
|
|||
|
||||
// The model atis.dnn is trained by <CNTK>/Examples/LanguageUnderstanding/ATIS/Python/LanguageUnderstanding.py
|
||||
// Please see README.md in <CNTK>/Examples/LanguageUnderstanding/ATIS about how to train the model.
|
||||
string modelFilePath = "atis.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "atis.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/LanguageUnderstanding/ATIS to create the model.", modelFilePath));
|
||||
Function modelFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
// Read word and slot index files.
|
||||
string vocabFile = "query.wl";
|
||||
string labelFile = "slots.wl";
|
||||
ThrowIfFileNotExist(vocabFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", vocabFile));
|
||||
ThrowIfFileNotExist(labelFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", labelFile));
|
||||
var vocabToIndex = buildVocabIndex(vocabFile);
|
||||
var indexToSlots = buildSlotIndex(labelFile);
|
||||
ThrowIfFileNotExist(VocabFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", VocabFile));
|
||||
ThrowIfFileNotExist(LabelFile, string.Format("Error: The file '{0}' does not exist. Please copy it from <CNTK>/Examples/LanguageUnderstanding/ATIS/BrainScript/ to the output directory.", LabelFile));
|
||||
var vocabToIndex = buildVocabIndex(VocabFile);
|
||||
var indexToSlots = buildSlotIndex(LabelFile);
|
||||
|
||||
// Get input variable
|
||||
var inputVar = modelFunc.Arguments.Single();
|
||||
|
@ -827,7 +849,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Load the model.
|
||||
// The model resnet20.dnn is trained by <CNTK>/Examples/Image/Classification/ResNet/Python/TrainResNet_CIFAR10.py
|
||||
// Please see README.md in <CNTK>/Examples/Image/Classification/ResNet about how to train the model.
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "resnet20.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
|
||||
Function rootFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
|
@ -853,9 +875,8 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Image preprocessing to match input requirements of the model.
|
||||
// This program uses images from the CIFAR-10 dataset for evaluation.
|
||||
// Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.
|
||||
string sampleImage = "00000.png";
|
||||
ThrowIfFileNotExist(sampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", sampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(sampleImage));
|
||||
ThrowIfFileNotExist(SampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", SampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(SampleImage));
|
||||
var resized = bmp.Resize((int)imageWidth, (int)imageHeight, true);
|
||||
List<float> resizedCHW = resized.ParallelExtractCHW();
|
||||
|
||||
|
@ -899,7 +920,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Load the model.
|
||||
// The model resnet20.dnn is trained by <CNTK>/Examples/Image/Classification/ResNet/Python/TrainResNet_CIFAR10.py
|
||||
// Please see README.md in <CNTK>/Examples/Image/Classification/ResNet about how to train the model.
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = ExampleTestDataDir + "resnet20.dnn";
|
||||
ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
|
||||
Function modelFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
|
@ -924,9 +945,8 @@ namespace CNTKLibraryCSEvalExamples
|
|||
// Image preprocessing to match input requirements of the model.
|
||||
// This program uses images from the CIFAR-10 dataset for evaluation.
|
||||
// Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.
|
||||
string sampleImage = "00000.png";
|
||||
ThrowIfFileNotExist(sampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", sampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(sampleImage));
|
||||
ThrowIfFileNotExist(SampleImage, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", SampleImage));
|
||||
Bitmap bmp = new Bitmap(Bitmap.FromFile(SampleImage));
|
||||
var resized = bmp.Resize((int)imageWidth, (int)imageHeight, true);
|
||||
List<float> resizedCHW = resized.ParallelExtractCHW();
|
||||
|
||||
|
|
|
@ -48,6 +48,12 @@ namespace CNTKLibraryCSEvalExamples
|
|||
#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())
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
MemoryTests.Device0 = deviceList[0];
|
||||
|
||||
// Load the model.
|
||||
string modelFilePath = "resnet20.dnn";
|
||||
string modelFilePath = CNTKLibraryManagedExamples.ExampleTestDataDir + "resnet20.dnn";
|
||||
CNTKLibraryManagedExamples.ThrowIfFileNotExist(modelFilePath, string.Format("Error: The model '{0}' does not exist. Please follow instructions in README.md in <CNTK>/Examples/Image/Classification/ResNet to create the model.", modelFilePath));
|
||||
Function modelFunc = Function.Load(modelFilePath, device);
|
||||
|
||||
|
@ -81,7 +81,7 @@ namespace CNTKLibraryCSEvalExamples
|
|||
int imageChannels = inputShape[2];
|
||||
int imageSize = inputShape.TotalSize;
|
||||
|
||||
var imageList = new List<string>() { "00000.png", "00001.png", "00002.png" };
|
||||
var imageList = new List<string>() { CNTKLibraryManagedExamples.ExampleTestDataDir + "00000.png", CNTKLibraryManagedExamples.ExampleTestDataDir + "00001.png", CNTKLibraryManagedExamples.ExampleTestDataDir + "00002.png" };
|
||||
foreach (var image in imageList)
|
||||
{
|
||||
CNTKLibraryManagedExamples.ThrowIfFileNotExist(image, string.Format("Error: The sample image '{0}' does not exist. Please see README.md in <CNTK>/Examples/Image/DataSets/CIFAR-10 about how to download the CIFAR-10 dataset.", image));
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
set -x
|
||||
|
||||
# Since we only use python to train a model for evaluation test, it is sufficient to train the model only with one python version.
|
||||
# Now it is trained with Python 2.7. If it is not supported anymore, need to use another python version.
|
||||
# Now it is trained with Python 3.5. If it is not supported anymore, need to use another python version.
|
||||
# TODO: have a better way to configure how run test only on a single python version
|
||||
PythonVer=$(python -c "import sys; sys.stdout.write(str(sys.version_info[0])); sys.stdout.flush()")
|
||||
if [ "$PythonVer" == "3" ]; then
|
||||
echo Skip this test for Python 3.5/3.6. Run this test only on Python 2.7 to save test time.
|
||||
PythonVer=$(python -c "import sys; sys.stdout.write(str(sys.version_info[0])+str(sys.version_info[1])); sys.stdout.flush()")
|
||||
if [ "$PythonVer" != "35" ]; then
|
||||
echo Skip this test for Python 2.7/3.6. Run this test only on Python 3.5 to save test time.
|
||||
# Simulate test completes.
|
||||
set +x
|
||||
echo Evaluation completes
|
||||
|
@ -24,10 +24,13 @@ fi
|
|||
|
||||
if [ "$OS" == "Windows_NT" ]; then
|
||||
TestDataSourceDir=`cygpath -au $CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY`
|
||||
RunTestDataDir=$TEST_BIN_DIR/data
|
||||
else
|
||||
TestDataSourceDir=$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY
|
||||
# On Linux, all dotnet dlls are built into lib dir, so keeping the data dir in the same location
|
||||
RunTestDataDir=$TEST_BIN_DIR/../lib/data
|
||||
fi
|
||||
|
||||
mkdir $RunTestDataDir
|
||||
# Set CUDA_VISIBLE_DEVICES to exclude all gpu if running on cpu device
|
||||
[ "$TEST_DEVICE" == "cpu" ] && export CUDA_VISIBLE_DEVICES=-1
|
||||
|
||||
|
@ -35,21 +38,28 @@ if [ "$TEST_DEVICE" == "cpu" ]; then
|
|||
echo Use pre-trained resnet_20_cifar_10 model and atis.dnn in $CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY for tests on CPU device.
|
||||
# Unzip data only, without training model
|
||||
python train_models_for_evaluation.py -u -d $TEST_DEVICE || exit $?
|
||||
cp $TestDataSourceDir/PreTrainedModels/EvalModels/resnet20_cifar10_python.dnn resnet20.dnn || exit $?
|
||||
cp $TestDataSourceDir/PreTrainedModels/EvalModels/atis.dnn atis.dnn || exit $?
|
||||
cp $TestDataSourceDir/PreTrainedModels/EvalModels/resnet20_cifar10_python.dnn $RunTestDataDir/resnet20.dnn || exit $?
|
||||
cp $TestDataSourceDir/PreTrainedModels/EvalModels/atis.dnn $RunTestDataDir/atis.dnn || exit $?
|
||||
else
|
||||
echo Use the on-the-fly trained resnet_20_cifar_10 model for tests on GPU device.
|
||||
# Train resnet cifar model and atis model
|
||||
python train_models_for_evaluation.py -d $TEST_DEVICE || exit $?
|
||||
mv resnet20_0.dnn resnet20.dnn || exit $?
|
||||
mv atis_0.dnn atis.dnn || exit $?
|
||||
mv resnet20_0.dnn $RunTestDataDir/resnet20.dnn || exit $?
|
||||
mv atis_0.dnn $RunTestDataDir/atis.dnn || exit $?
|
||||
fi
|
||||
mv data/train/* . || exit $?
|
||||
cp $TEST_ROOT_DIR/../../Examples/LanguageUnderstanding/ATIS/BrainScript/query.wl . || exit $?
|
||||
cp $TEST_ROOT_DIR/../../Examples/LanguageUnderstanding/ATIS/BrainScript/slots.wl . || exit $?
|
||||
mv data/train/* $RunTestDataDir || exit $?
|
||||
cp $TEST_ROOT_DIR/../../Examples/LanguageUnderstanding/ATIS/BrainScript/query.wl $RunTestDataDir || exit $?
|
||||
cp $TEST_ROOT_DIR/../../Examples/LanguageUnderstanding/ATIS/BrainScript/slots.wl $RunTestDataDir || exit $?
|
||||
|
||||
if [ "$OS" == "Windows_NT" ]; then
|
||||
$TEST_BIN_DIR/CNTKLibraryCSEvalExamplesTest.exe
|
||||
pushd $TEST_BIN_DIR > /dev/null
|
||||
echo 'Running command "dotnet CNTKLibraryCSEvalExamplesTest.dll" `cygpath -aw $RunTestDataDir`'
|
||||
dotnet CNTKLibraryCSEvalExamplesTest.dll `cygpath -aw $RunTestDataDir`
|
||||
popd > /dev/null
|
||||
# This is created by train_models_for_evaluation.py, remove after test
|
||||
rm -rf ./data
|
||||
# Remove temp test data dir
|
||||
rm -rf $RunTestDataDir
|
||||
else
|
||||
echo Cannot run CNTKLibraryCSEvalExampleTest on Linux.
|
||||
exit 1
|
||||
|
|
|
@ -636,6 +636,9 @@ class Function(cntk_py.Function):
|
|||
substitutions = substitutions or {}
|
||||
if not isinstance(substitutions, dict):
|
||||
raise TypeError("Variable substitution map must be a dictionary")
|
||||
for prev_node, new_node in substitutions.items():
|
||||
if not new_node or not prev_node:
|
||||
raise AttributeError("Cannot replace node: " + str(prev_node) + " with node: " + str(new_node) + ". Neither node can be None.")
|
||||
return super(Function, self).clone(method, substitutions)
|
||||
|
||||
@property
|
||||
|
|
|
@ -578,3 +578,41 @@ def test_clone_with_deep_rnn_chaining():
|
|||
seq_op_res = seq_op_func(c1)
|
||||
net = rnn_seq(seq_op_res)
|
||||
cloned = net.clone('freeze')
|
||||
|
||||
|
||||
def test_clone_with_unfound_new_node():
|
||||
x = C.input_variable(())
|
||||
y = C.combine(x * x, x + x)
|
||||
y0 = y[0]
|
||||
y1 = y[1]
|
||||
y0_new = C.plus(y0,0, name="test")
|
||||
X=C.logging.find_by_name(y0_new, 'QueryReply_y')
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
y_clone = y.clone(C.CloneMethod.share, {y0:y0_new, y1:X})
|
||||
|
||||
|
||||
def test_clone_with_unfound_previous_node():
|
||||
x = C.input_variable(())
|
||||
y = C.combine(x * x, x + x)
|
||||
y0 = y[0]
|
||||
y1 = y[1]
|
||||
y0_new = C.plus(y0,0, name="test")
|
||||
X=C.logging.find_by_name(y0_new, 'QueryReply_y')
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
y_clone = y.clone(C.CloneMethod.share, {X:y0_new})
|
||||
|
||||
|
||||
def test_clone_with_wrong_type_node():
|
||||
x = C.input_variable(())
|
||||
y = C.combine(x * x, x + x)
|
||||
y0 = y[0]
|
||||
y1 = y[1]
|
||||
y0_new = C.plus(y0,0, name="test")
|
||||
X=C.logging.find_by_name(y0_new, 'QueryReply_y')
|
||||
|
||||
a = 5
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
y_clone = y.clone(C.CloneMethod.share, {y0:a})
|
|
@ -0,0 +1,69 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License.txt in the project root for
|
||||
# license information.
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
import numpy as np
|
||||
import cntk as C
|
||||
from onnx.backend.base import Backend
|
||||
from onnx import helper, TensorProto
|
||||
from .backend_rep import CNTKBackendRep
|
||||
|
||||
class CNTKBackend(Backend):
|
||||
@staticmethod
|
||||
def set_device(device):
|
||||
if device == 'CPU':
|
||||
C.try_set_default_device(C.device.cpu())
|
||||
elif device == 'GPU' or device == 'CUDA':
|
||||
try:
|
||||
C.try_set_default_device(C.device.gpu(0))
|
||||
except:
|
||||
C.use_default_device()
|
||||
else:
|
||||
C.use_default_device()
|
||||
|
||||
@classmethod
|
||||
def run_node(cls, node, input, device='CPU'):
|
||||
input_tensors = []
|
||||
|
||||
if len(node.input) != len(input):
|
||||
raise ValueError(
|
||||
"Unexpected Input Size: Op_Type = {0}, Expected = {1}, Received = {2}"
|
||||
.format(node.op_type, len(node.input), len(input))
|
||||
)
|
||||
|
||||
for i in range(len(input)):
|
||||
input_tensors.append(helper.make_tensor_value_info(node.input[i], TensorProto.FLOAT, input[i].shape))
|
||||
|
||||
onnx_graph = helper.make_graph([node], "test_{}".format(node.op_type), input_tensors, [])
|
||||
onnx_model = helper.make_model(onnx_graph)
|
||||
return CNTKBackend.run_model(onnx_model, input, device)
|
||||
|
||||
@classmethod
|
||||
def run_model(cls, model, input, device='CPU'):
|
||||
with open(r'tmp_model.pb', 'wb') as f:
|
||||
f.write(model.SerializeToString())
|
||||
|
||||
CNTKBackend.set_device(device)
|
||||
c_model = C.Function.load(r'tmp_model.pb', format=C.ModelFormat.ONNX)
|
||||
c_inputs = {c_model.arguments[i]:input[i] for i in range(len(input))}
|
||||
res = c_model.eval(c_inputs)
|
||||
return [res]
|
||||
|
||||
@classmethod
|
||||
def prepare(cls, model, device='CPU', **kwargs):
|
||||
with open(r'tmp_model.pb', 'wb') as f:
|
||||
f.write(model.SerializeToString())
|
||||
|
||||
CNTKBackend.set_device(device)
|
||||
c_model = C.Function.load(r'tmp_model.pb', format=C.ModelFormat.ONNX)
|
||||
return CNTKBackendRep(c_model)
|
||||
|
||||
@classmethod
|
||||
def supports_device(cls, device='CPU'):
|
||||
return device in ['CPU', 'GPU', 'CUDA']
|
||||
|
||||
run_node = CNTKBackend.run_node
|
||||
supports_device = CNTKBackend.supports_device
|
||||
prepare = CNTKBackend.prepare
|
|
@ -0,0 +1,18 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License.txt in the project root for
|
||||
# license information.
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
import cntk as C
|
||||
import numpy as np
|
||||
from onnx.backend.base import BackendRep
|
||||
|
||||
class CNTKBackendRep(BackendRep):
|
||||
def __init__(self, model):
|
||||
self.model = model
|
||||
|
||||
def run(self, inputs, **kwargs):
|
||||
input = {self.model.arguments[i]:inputs[i] for i in range(len(inputs))}
|
||||
res = self.model.eval(input)
|
||||
return [res]
|
|
@ -0,0 +1,48 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License.txt in the project root for
|
||||
# license information.
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
import onnx.backend.test
|
||||
|
||||
from onnx_cntk import backend as cntk_backend
|
||||
|
||||
# This is a pytest magic variable to load extra plugins
|
||||
pytest_plugins = 'onnx.backend.test.report'
|
||||
|
||||
backend_test = onnx.backend.test.BackendTest(cntk_backend, __name__)
|
||||
|
||||
skip_models = [
|
||||
'bvlc_alexnet',
|
||||
'densenet121',
|
||||
'inception_v1',
|
||||
'inception_v2',
|
||||
'resnet50',
|
||||
'shufflenet',
|
||||
'vgg16',
|
||||
'vgg19',
|
||||
]
|
||||
|
||||
skip_ops = [
|
||||
'test_max',
|
||||
'test_min',
|
||||
]
|
||||
|
||||
skip_tests = skip_models + skip_ops
|
||||
for test in skip_tests:
|
||||
backend_test.exclude(test)
|
||||
|
||||
# import all test cases at global scope to make them visible to python.unittest
|
||||
globals().update(backend_test
|
||||
.enable_report()
|
||||
.test_cases)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Загрузка…
Ссылка в новой задаче