fix csharp examples and references

This commit is contained in:
TJ 2018-10-01 15:44:06 -07:00
Родитель fcdeef63d0
Коммит 7c838d3b6c
12 изменённых файлов: 62 добавлений и 40 удалений

Просмотреть файл

@ -43,7 +43,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<ProjectReference Include="..\..\..\bindings\csharp\CNTKLibraryManagedDll\CNTKLibraryManagedDll.csproj" />
<Reference Include="netstandard" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Evaluation\ImageExtension\CNTKImageProcessing.cs">
@ -71,20 +71,24 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Cntk.Core.Managed-2.6, processorArchitecture=AMD64">
<HintPath>..\packages\CNTK.CPUOnly.2.6.0\lib\netstandard2.0\Cntk.Core.Managed-2.6.dll</HintPath>
<Private>True</Private>
</Reference>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets" Condition="Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets')" />
<Import Project="..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets" Condition="Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets')" />
<Import Project="..\packages\CNTK.CPUOnly.2.6.0\build\net45\CNTK.CPUOnly.targets" Condition="Exists('..\packages\CNTK.CPUOnly.2.6.0\build\net45\CNTK.CPUOnly.targets')" />
<Import Project="..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets" Condition="Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets')" />
<Import Project="..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets" Condition="Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets')" />
<Import Project="..\packages\CNTK.CPUOnly.2.6.0\build\netstandard2.0\CNTK.CPUOnly.targets" Condition="Exists('..\packages\CNTK.CPUOnly.2.6.0\build\netstandard2.0\CNTK.CPUOnly.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.CPUOnly.2.6.0\build\net45\CNTK.CPUOnly.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.CPUOnly.2.6.0\build\net45\CNTK.CPUOnly.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.CPUOnly.2.6.0\build\netstandard2.0\CNTK.CPUOnly.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.CPUOnly.2.6.0\build\netstandard2.0\CNTK.CPUOnly.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

Просмотреть файл

@ -11,6 +11,7 @@ namespace CNTK.CSTrainingExamples
{
static void Main(string[] args)
{
TestCommon.TestDataDirPrefix = "../../";
var device = DeviceDescriptor.CPUDevice;
Console.WriteLine($"======== running LogisticRegression.TrainAndEvaluate using {device.Type} ========");
LogisticRegression.TrainAndEvaluate(device);

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CNTK.CPUOnly" version="2.6.0" targetFramework="net45" />
<package id="CNTK.Deps.MKL" version="2.6.0" targetFramework="net45" />
<package id="CNTK.Deps.OpenCV.Zip" version="2.6.0" targetFramework="net45" />
<package id="CNTK.CPUOnly" version="2.6.0" targetFramework="netstandard2.0" />
<package id="CNTK.Deps.MKL" version="2.6.0" targetFramework="netstandard2.0" />
<package id="CNTK.Deps.OpenCV.Zip" version="2.6.0" targetFramework="netstandard2.0" />
</packages>

Просмотреть файл

@ -44,7 +44,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<ProjectReference Include="..\..\..\bindings\csharp\CNTKLibraryManagedDll\CNTKLibraryManagedDll.csproj" />
<Reference Include="netstandard" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Evaluation\ImageExtension\CNTKImageProcessing.cs">
@ -72,22 +72,26 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Cntk.Core.Managed-2.6, processorArchitecture=AMD64">
<HintPath>..\packages\CNTK.GPU.2.6.0\lib\netstandard2.0\Cntk.Core.Managed-2.6.dll</HintPath>
<Private>True</Private>
</Reference>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\CNTK.Deps.Cuda.2.6.0\build\net45\CNTK.Deps.Cuda.targets" Condition="Exists('..\packages\CNTK.Deps.Cuda.2.6.0\build\net45\CNTK.Deps.Cuda.targets')" />
<Import Project="..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets" Condition="Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets')" />
<Import Project="..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets" Condition="Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets')" />
<Import Project="..\packages\CNTK.GPU.2.6.0\build\net45\CNTK.GPU.targets" Condition="Exists('..\packages\CNTK.GPU.2.6.0\build\net45\CNTK.GPU.targets')" />
<Import Project="..\packages\CNTK.Deps.Cuda.2.6.0\build\netstandard2.0\CNTK.Deps.Cuda.targets" Condition="Exists('..\packages\CNTK.Deps.Cuda.2.6.0\build\netstandard2.0\CNTK.Deps.Cuda.targets')" />
<Import Project="..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets" Condition="Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets')" />
<Import Project="..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets" Condition="Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets')" />
<Import Project="..\packages\CNTK.GPU.2.6.0\build\netstandard2.0\CNTK.GPU.targets" Condition="Exists('..\packages\CNTK.GPU.2.6.0\build\netstandard2.0\CNTK.GPU.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\CNTK.Deps.Cuda.2.6.0\build\net45\CNTK.Deps.Cuda.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.Cuda.2.6.0\build\net45\CNTK.Deps.Cuda.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.MKL.2.6.0\build\net45\CNTK.Deps.MKL.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\net45\CNTK.Deps.OpenCV.Zip.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.GPU.2.6.0\build\net45\CNTK.GPU.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.GPU.2.6.0\build\net45\CNTK.GPU.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.Cuda.2.6.0\build\netstandard2.0\CNTK.Deps.Cuda.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.Cuda.2.6.0\build\netstandard2.0\CNTK.Deps.Cuda.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.MKL.2.6.0\build\netstandard2.0\CNTK.Deps.MKL.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.Deps.OpenCV.Zip.2.6.0\build\netstandard2.0\CNTK.Deps.OpenCV.Zip.targets'))" />
<Error Condition="!Exists('..\packages\CNTK.GPU.2.6.0\build\netstandard2.0\CNTK.GPU.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.GPU.2.6.0\build\netstandard2.0\CNTK.GPU.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

Просмотреть файл

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -10,6 +11,7 @@ namespace CNTK.CSTrainingExamples
{
static void Main(string[] args)
{
TestCommon.TestDataDirPrefix = "../../";
var device = DeviceDescriptor.GPUDevice(0);
Console.WriteLine($"======== running LogisticRegression.TrainAndEvaluate using {device.Type} ========");
LogisticRegression.TrainAndEvaluate(device);
@ -21,14 +23,23 @@ namespace CNTK.CSTrainingExamples
MNISTClassifier.TrainAndEvaluate(device, true, true);
Console.WriteLine($"======== running CifarResNet.TrainAndEvaluate using {device.Type} ========");
CifarResNetClassifier.CifarDataFolder = "../../Examples/Image/DataSets/CIFAR-10";
CifarResNetClassifier.TrainAndEvaluate(device, true);
TestCommon.TestDataDirPrefix = "../../Examples/Image/DataSets/";
string modelFileSourceDir = "../../PretrainedModels/ResNet_18.model";
if (!File.Exists(modelFileSourceDir))
{
Console.WriteLine("Model file doesn't exist. Please run download_model.py in CNTK/CNTK/PretrainedModels");
Console.ReadKey();
return;
}
Console.WriteLine($"======== running TransferLearning.TrainAndEvaluateWithFlowerData using {device.Type} ========");
TransferLearning.TrainAndEvaluateWithFlowerData(device, true);
TransferLearning.BaseResnetModelFile = "ResNet_18.model";
File.Copy(modelFileSourceDir, TransferLearning.ExampleImageFolder + TransferLearning.BaseResnetModelFile,/*overwrite*/true);
Console.WriteLine($"======== running TransferLearning.TrainAndEvaluateWithAnimalData using {device.Type} ========");
TransferLearning.TrainAndEvaluateWithAnimalData(device, true);
TestCommon.TestDataDirPrefix = "../../";
Console.WriteLine($"======== running LSTMSequenceClassifier.Train using {device.Type} ========");
LSTMSequenceClassifier.Train(device);
}

Просмотреть файл

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CNTK.Deps.Cuda" version="2.6.0" targetFramework="net45" />
<package id="CNTK.Deps.MKL" version="2.6.0" targetFramework="net45" />
<package id="CNTK.Deps.OpenCV.Zip" version="2.6.0" targetFramework="net45" />
<package id="CNTK.GPU" version="2.6.0" targetFramework="net45" />
<package id="CNTK.Deps.Cuda" version="2.6.0" targetFramework="netstandard2.0" />
<package id="CNTK.Deps.MKL" version="2.6.0" targetFramework="netstandard2.0" />
<package id="CNTK.Deps.OpenCV.Zip" version="2.6.0" targetFramework="netstandard2.0" />
<package id="CNTK.GPU" version="2.6.0" targetFramework="netstandard2.0" />
</packages>

Просмотреть файл

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using CNTK.CNTKLibraryCSTrainingTest;
namespace CNTK.CSTrainingExamples
{

Просмотреть файл

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CNTK.CNTKLibraryCSTrainingTest;
namespace CNTK.CSTrainingExamples
{

Просмотреть файл

@ -18,6 +18,10 @@ namespace CNTK.CSTrainingExamples
Sigmoid,
Tanh
}
public static class TestCommon
{
public static string TestDataDirPrefix;
}
public class TestHelper
{
public static Function Dense(Variable input, int outputDim, DeviceDescriptor device,

Просмотреть файл

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using CNTK.CNTKLibraryCSTrainingTest;
using System.Runtime.CompilerServices;
namespace CNTK.CSTrainingExamples
{
@ -22,13 +22,17 @@ namespace CNTK.CSTrainingExamples
/// data folder is: CNTK/Examples/Image
/// model folder is: CNTK/PretrainedModels
/// </summary>
public static string ExampleImageFoler = TestCommon.TestDataDirPrefix;
public static string ExampleImageFolder
{
get { return TestCommon.TestDataDirPrefix; }
set { TestCommon.TestDataDirPrefix = value; }
}
public static string BaseResnetModelFile = TestCommon.TestDataDirPrefix + "/ResNet18_ImageNet_CNTK.model";
private static string featureNodeName = "features";
private static string lastHiddenNodeName = "z.x";
private static int[] imageDims = new int[] { 224, 224, 3 };
/// <summary>
/// TrainAndEvaluateWithFlowerData shows how to do transfer learning with a MinibatchSource. MinibatchSource is constructed with
/// a map file that contains image file paths and labels. Data loading, image preprocessing, and batch randomization are handled
@ -39,7 +43,7 @@ namespace CNTK.CSTrainingExamples
/// it only evaluates the model is it exists. </param>
public static void TrainAndEvaluateWithFlowerData(DeviceDescriptor device, bool forceReTrain = false)
{
string flowerFolder = Path.Combine(ExampleImageFoler, "Flowers");
string flowerFolder = Path.Combine(ExampleImageFolder, "Flowers");
string flowersTrainingMap = Path.Combine(flowerFolder, "1k_img_map.txt");
string flowersValidationMap = Path.Combine(flowerFolder, "val_map.txt");
int flowerModelNumClasses = 102;
@ -65,7 +69,7 @@ namespace CNTK.CSTrainingExamples
Function trainingLoss, predictionError;
// create a transfer model
Function transferLearningModel = CreateTransferLearningModel(BaseResnetModelFile, featureNodeName,
Function transferLearningModel = CreateTransferLearningModel(Path.Combine(ExampleImageFolder, BaseResnetModelFile), featureNodeName,
predictionNodeName, lastHiddenNodeName, flowerModelNumClasses, device,
out imageInput, out labelInput, out trainingLoss, out predictionError);
@ -120,7 +124,7 @@ namespace CNTK.CSTrainingExamples
/// it only evaluates the model is it exists. </param>
public static void TrainAndEvaluateWithAnimalData(DeviceDescriptor device, bool forceRetrain = false)
{
string animalDataFolder = Path.Combine(ExampleImageFoler, "Animals");
string animalDataFolder = Path.Combine(ExampleImageFolder, "Animals");
string[] animals = new string[] { "Sheep", "Wolf" };
int animalModelNumClasses = 2;
string animalsModelFile = Path.Combine(CurrentFolder, "AnimalsTransferLearning.model");
@ -140,7 +144,7 @@ namespace CNTK.CSTrainingExamples
string predictionNodeName = "prediction";
Variable imageInput, labelInput;
Function trainingLoss, predictionError;
Function transferLearningModel = CreateTransferLearningModel(Path.Combine(ExampleImageFoler, BaseResnetModelFile), featureNodeName, predictionNodeName,
Function transferLearningModel = CreateTransferLearningModel(Path.Combine(ExampleImageFolder, BaseResnetModelFile), featureNodeName, predictionNodeName,
lastHiddenNodeName, animalModelNumClasses, device,
out imageInput, out labelInput, out trainingLoss, out predictionError);

Просмотреть файл

@ -18,6 +18,7 @@ models = (('Image Classification', 'AlexNet_ImageNet_CNTK', 'https://www.cntk.ai
('Image Classification', 'InceptionV3_ImageNet_CNTK', 'https://www.cntk.ai/Models/CNTK_Pretrained/InceptionV3_ImageNet_CNTK.model'),
('Image Classification', 'BNInception_ImageNet_Caffe', 'https://www.cntk.ai/Models/Caffe_Converted/BNInception_ImageNet_Caffe.model'),
('Image Classification', 'ResNet18_ImageNet_CNTK', 'https://www.cntk.ai/Models/CNTK_Pretrained/ResNet18_ImageNet_CNTK.model'),
('Image Classification', 'ResNet_18', 'https://cntkbuildstorage.blob.core.windows.net/cntk-pretrained-model/ResNet_18.model'),
('Image Classification', 'ResNet34_ImageNet_CNTK', 'https://www.cntk.ai/Models/CNTK_Pretrained/ResNet34_ImageNet_CNTK.model'),
('Image Classification', 'ResNet50_ImageNet_CNTK', 'https://www.cntk.ai/Models/CNTK_Pretrained/ResNet50_ImageNet_CNTK.model'),
('Image Classification', 'ResNet101_ImageNet_CNTK', 'https://www.cntk.ai/Models/CNTK_Pretrained/ResNet101_ImageNet_CNTK.model'),

Просмотреть файл

@ -148,9 +148,4 @@ namespace CNTK.CNTKLibraryCSTrainingTest
LSTMSequenceClassifier.Train(device);
}
}
public static class TestCommon
{
public static string TestDataDirPrefix;
}
}