.net - CNTK.CPUOnly在Docker中[Windows]

标签 .net windows docker cntk

我想使用 CNTK.CPUOnly 实现简单的.net 4.7应用程序
然后将其推送到Docker [Windows]。

脚步:

  • 在Visual Studio 2017中创建新的.net 4.7控制台应用程序
  • 打开NuGet管理器并添加CNTK.CPUOnly包(带有依赖项)
  • 编写简单的应用程序:
  • using System;
    using System.IO;
    namespace cntk_docker
    {
        class Program
        {
            static void Main(string[] args)
            {
                var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory);
                foreach (var file in files)
                {
                    Console.WriteLine(file);
                }   
                var device = CNTK.DeviceDescriptor.CPUDevice;
                Console.WriteLine(device);
                Console.Read();
            }
        }
    }
    
    然后我创建了 Dockerfile :
    FROM microsoft/dotnet-framework:4.7
    WORKDIR /app
    COPY bin/x64/Release .
    ENTRYPOINT ["cntk_docker.exe"] 
    

    当我尝试在Docker中运行应用程序时出现异常:
    d:\codetest\cntk_docker>docker run 4e4d0888ae57
    C:\app\Cntk.Composite-2.6.dll
    C:\app\Cntk.Core-2.6.dll
    C:\app\Cntk.Core.CSBinding-2.6.dll
    C:\app\Cntk.Core.Managed-2.6.dll
    C:\app\Cntk.Deserializers.Binary-2.6.dll
    C:\app\Cntk.Deserializers.HTK-2.6.dll
    C:\app\Cntk.Deserializers.Image-2.6.dll
    C:\app\Cntk.Deserializers.TextFormat-2.6.dll
    C:\app\Cntk.Math-2.6.dll
    C:\app\Cntk.PerformanceProfiler-2.6.dll
    C:\app\cntk_docker.exe
    C:\app\cntk_docker.exe.Config
    C:\app\cntk_docker.pdb
    C:\app\libiomp5md.dll
    C:\app\Microsoft.Win32.Primitives.dll
    C:\app\mkldnn.dll
    C:\app\mklml.dll
    C:\app\netstandard.dll
    C:\app\opencv_world310.dll
    C:\app\System.AppContext.dll
    C:\app\System.Collections.Concurrent.dll
    C:\app\System.Collections.dll
    C:\app\System.Collections.NonGeneric.dll
    C:\app\System.Collections.Specialized.dll
    C:\app\System.ComponentModel.dll
    C:\app\System.ComponentModel.EventBasedAsync.dll
    C:\app\System.ComponentModel.Primitives.dll
    C:\app\System.ComponentModel.TypeConverter.dll
    C:\app\System.Console.dll
    C:\app\System.Data.Common.dll
    C:\app\System.Diagnostics.Contracts.dll
    C:\app\System.Diagnostics.Debug.dll
    C:\app\System.Diagnostics.FileVersionInfo.dll
    C:\app\System.Diagnostics.Process.dll
    C:\app\System.Diagnostics.StackTrace.dll
    C:\app\System.Diagnostics.TextWriterTraceListener.dll
    C:\app\System.Diagnostics.Tools.dll
    C:\app\System.Diagnostics.TraceSource.dll
    C:\app\System.Diagnostics.Tracing.dll
    C:\app\System.Drawing.Primitives.dll
    C:\app\System.Dynamic.Runtime.dll
    C:\app\System.Globalization.Calendars.dll
    C:\app\System.Globalization.dll
    C:\app\System.Globalization.Extensions.dll
    C:\app\System.IO.Compression.dll
    C:\app\System.IO.Compression.ZipFile.dll
    C:\app\System.IO.dll
    C:\app\System.IO.FileSystem.dll
    C:\app\System.IO.FileSystem.DriveInfo.dll
    C:\app\System.IO.FileSystem.Primitives.dll
    C:\app\System.IO.FileSystem.Watcher.dll
    C:\app\System.IO.IsolatedStorage.dll
    C:\app\System.IO.MemoryMappedFiles.dll
    C:\app\System.IO.Pipes.dll
    C:\app\System.IO.UnmanagedMemoryStream.dll
    C:\app\System.Linq.dll
    C:\app\System.Linq.Expressions.dll
    C:\app\System.Linq.Parallel.dll
    C:\app\System.Linq.Queryable.dll
    C:\app\System.Net.Http.dll
    C:\app\System.Net.NameResolution.dll
    C:\app\System.Net.NetworkInformation.dll
    C:\app\System.Net.Ping.dll
    C:\app\System.Net.Primitives.dll
    C:\app\System.Net.Requests.dll
    C:\app\System.Net.Security.dll
    C:\app\System.Net.Sockets.dll
    C:\app\System.Net.WebHeaderCollection.dll
    C:\app\System.Net.WebSockets.Client.dll
    C:\app\System.Net.WebSockets.dll
    C:\app\System.ObjectModel.dll
    C:\app\System.Reflection.dll
    C:\app\System.Reflection.Extensions.dll
    C:\app\System.Reflection.Primitives.dll
    C:\app\System.Resources.Reader.dll
    C:\app\System.Resources.ResourceManager.dll
    C:\app\System.Resources.Writer.dll
    C:\app\System.Runtime.CompilerServices.VisualC.dll
    C:\app\System.Runtime.dll
    C:\app\System.Runtime.Extensions.dll
    C:\app\System.Runtime.Handles.dll
    C:\app\System.Runtime.InteropServices.dll
    C:\app\System.Runtime.InteropServices.RuntimeInformation.dll
    C:\app\System.Runtime.Numerics.dll
    C:\app\System.Runtime.Serialization.Formatters.dll
    C:\app\System.Runtime.Serialization.Json.dll
    C:\app\System.Runtime.Serialization.Primitives.dll
    C:\app\System.Runtime.Serialization.Xml.dll
    C:\app\System.Security.Claims.dll
    C:\app\System.Security.Cryptography.Algorithms.dll
    C:\app\System.Security.Cryptography.Csp.dll
    C:\app\System.Security.Cryptography.Encoding.dll
    C:\app\System.Security.Cryptography.Primitives.dll
    C:\app\System.Security.Cryptography.X509Certificates.dll
    C:\app\System.Security.Principal.dll
    C:\app\System.Security.SecureString.dll
    C:\app\System.Text.Encoding.dll
    C:\app\System.Text.Encoding.Extensions.dll
    C:\app\System.Text.RegularExpressions.dll
    C:\app\System.Threading.dll
    C:\app\System.Threading.Overlapped.dll
    C:\app\System.Threading.Tasks.dll
    C:\app\System.Threading.Tasks.Parallel.dll
    C:\app\System.Threading.Thread.dll
    C:\app\System.Threading.ThreadPool.dll
    C:\app\System.Threading.Timer.dll
    C:\app\System.ValueTuple.dll
    C:\app\System.Xml.ReaderWriter.dll
    C:\app\System.Xml.XDocument.dll
    C:\app\System.Xml.XmlDocument.dll
    C:\app\System.Xml.XmlSerializer.dll
    C:\app\System.Xml.XPath.dll
    C:\app\System.Xml.XPath.XDocument.dll
    C:\app\zip.dll
    C:\app\zlib.dll
    
    Unhandled Exception: System.TypeInitializationException: The type initializer for 'CNTK.CNTKLibPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Cntk.Core.CSBinding-2.6.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
    at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_CNTKLib(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
    at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..cctor()
    --- End of inner exception stack trace ---
    at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..ctor()
    at CNTK.CNTKLibPINVOKE..cctor()
    --- End of inner exception stack trace ---
    at CNTK.CNTKLibPINVOKE.DeviceDescriptor__CPUDevice()
    at CNTK.DeviceDescriptor._CPUDevice()
    at CNTK.DeviceDescriptor.get_CPUDevice()
    at cntk_docker.Program.Main(String[] args) in D:\codetest\cntk_docker\cntk_docker\Program.cs:line 14
    

    但是它在我的本地计算机和任何其他带有.net4.7的win10计算机中都可以正常工作。我做错了什么?

    最佳答案

    看起来像CNTK.CPUOnly不能没有以下功能:

  • Microsoft Visual C++ 2013可再发行(x86)
  • Microsoft Visual C++ 2013可再发行(x64)

  • 更新Docker文件后,一切正常
    FROM microsoft/dotnet-framework:4.7
    ADD https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe /vcredist_x86.exe
    RUN C:\vcredist_x86.exe /quiet /install
    ADD https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe /vcredist_x64.exe
    RUN C:\vcredist_x64.exe /quiet /install
    WORKDIR /app
    COPY bin/x64/Release .
    ENTRYPOINT ["cntk_docker.exe"] 
    

    关于.net - CNTK.CPUOnly在Docker中[Windows],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52610037/

    相关文章:

    node.js - 为 localhost 生成 MinIO presignedUrls,而不是 docker 服务名称

    windows - 删除所有停止的容器(在 Windows 上)?

    php - 使用 Docker 在 PhpStorm 中使用 PHPUnit

    .net - 如何在 .NET MySqlCommand 中使用 MySql 用户定义变量?

    .net - 在 LINQ 2 SQL 中不先选择数据就进行更新?

    c# - 将 app.config 作为 MSBuild 脚本的一部分进行更改

    c++ - C++ vector 的二维数组是否适合跟踪二维数组的动态域值?

    windows - 如何将 ionic 应用程序部署到 Windows 10 设备

    .net - .net中非静态类中静态变量的内存分配

    windows - 在 UWP 应用程序中打开 UWP