1

I am trying to deploy a web application with ML.NET to a docker container (it works no problem when I run it in IIS Express) but when I run it in the docker file that was created by visual studio, I get the following error saying that tensor flow was not found:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load shared library 'tensorflow' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libtensorflow: cannot open shared object file: No such file or directory at Tensorflow.c_api.TF_NewGraph() at Tensorflow.Graph..ctor() at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSession(IExceptionContext ectx, Byte[] modelBytes, String modelFile) at Microsoft.ML.Vision.ImageClassificationModelParameters..ctor(IHostEnvironment env, ModelLoadContext ctx) at Microsoft.ML.Vision.ImageClassificationModelParameters.Create(IHostEnvironment env, ModelLoadContext ctx) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs) at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstance(IHostEnvironment env, Object args, Object[] extra) at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes](IHostEnvironment env, Type signatureType, TRes& result, String name, String options, Object[] extra) at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig](IHostEnvironment env, TRes& result, String name, String options, Object[] extra) at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig](IHostEnvironment env, TRes& result, Object[] extra) at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra) at Microsoft.ML.Data.MulticlassPredictionTransformer.Create(IHostEnvironment env, ModelLoadContext ctx)

here is the docker file for reference:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Hotdogapp/Server/Hotdogapp.Server.csproj", "Hotdogapp/Server/"]
COPY ["Hotdogapp/Shared/Hotdogapp.Shared.csproj", "Hotdogapp/Shared/"]
COPY ["Hotdogapp/Client/Hotdogapp.Client.csproj", "Hotdogapp/Client/"]
RUN dotnet restore "Hotdogapp/Server/Hotdogapp.Server.csproj"
COPY . .
WORKDIR "/src/Hotdogapp/Server"
RUN dotnet build "Hotdogapp.Server.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Hotdogapp.Server.csproj" -c Release -o /app/publish


FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Hotdogapp.Server.dll"]

is there a special image I should be using for ML.NET/ TensorFlow?

3
  • Which version of SciSharp.TensorFlow.Redist do you have referenced? Commented Aug 12, 2020 at 10:10
  • version 2.2.01 and Microsoft.ML 1.5.0 Commented Aug 13, 2020 at 15:55
  • just updated to 2.3.0 and 1.5.1 for Microsoft.ML and still getting the same error Commented Aug 13, 2020 at 16:03

2 Answers 2

1

The error is thrown because it can't find one of the dependencies libtensorflow.so is using. To find out which dependency is missing, you can go to the runtime folder (/bin/${configuration}/${framework}/runtime/linux-x64/native) and try the following cmd, which should tell you the missing dependeny.

ldd libtensorflow.so

To solve the issue, you can simply install the missing dependency, or use a lower version of tf runtime, (for example redist.tensorflow 1.*) works for me. You can also raise an issue in Tensorflow.Net, where you could get better answer.

Sign up to request clarification or add additional context in comments.

Comments

0

TensorFlow is a python package so you'll need to install that into your Docker image as a dependency. Try adding this to the final stage of the Dockerfile:

RUN apt-get update \
    && apt-get install -y \
        python3-pip \
    && rm -rf /var/lib/apt/lists/*
RUN ln -sf /usr/bin/python3 /usr/bin/python \
    && python -m pip install tensorflow

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.