ML.NET 1.4.0预测引擎由于x64 UWP中的System.Drawing而引发PlatformNotSupportedException

时间:2020-01-09 04:07:32

标签: c# xamarin uwp ml.net

我一般对机器学习,Xamarin和.NET都比较陌生-也是第一次使用ML.NET。

我最近在TensorFlow中训练了对象检测模型,我想将其与我正在开发的Xamarin应用程序集成。找到了一些教程,这些教程解释了如何使用ML.NET导入.pb文件以及如何使用PredictionEngine(https://devblogs.microsoft.com/cesardelatorre/run-with-ml-net-c-code-a-tensorflow-model-exported-from-azure-cognitive-services-custom-vision/)进行推理。

我一直在相当稳定的进步,直到在PredictionEngine实例上调用Predict方法时遇到此错误:

System.PlatformNotSupportedException: 'System.Drawing is not supported on this platform.'

This exception was originally thrown at this call stack:
    System.Drawing.Bitmap.Bitmap(string)
    Microsoft.ML.Data.ImageLoadingTransformer.Mapper.MakeGetterImageDataViewType.AnonymousMethod__0(ref System.Drawing.Bitmap)
    Microsoft.ML.Transforms.Image.ImageResizingTransformer.Mapper.MakeGetter.AnonymousMethod__1(ref System.Drawing.Bitmap)
    Microsoft.ML.Transforms.Image.ImagePixelExtractingTransformer.Mapper.GetGetterCore.AnonymousMethod__1(ref Microsoft.ML.Data.VBuffer<TValue>)
    Microsoft.ML.Transforms.TensorFlowTransformer.TensorValueGetterVec<T>.GetTensor()
    Microsoft.ML.Transforms.TensorFlowTransformer.Mapper.UpdateCacheIfNeeded(long, Microsoft.ML.Transforms.TensorFlowTransformer.ITensorValueGetter[], string[], Microsoft.ML.Transforms.TensorFlowTransformer.Mapper.OutputCache)
    Microsoft.ML.Transforms.TensorFlowTransformer.Mapper.MakeGetter.AnonymousMethod__4(ref Microsoft.ML.Data.VBuffer<T>)
    Microsoft.ML.Data.TypedCursorable<TRow>.TypedRowBase.CreateDirectVBufferSetter.AnonymousMethod__0(TRow)
    Microsoft.ML.Data.TypedCursorable<TRow>.TypedRowBase.FillValues(TRow)
    Microsoft.ML.PredictionEngineBase<TSrc, TDst>.Predict(TSrc)
    ...
    [Call Stack Truncated]

以下是我安装的一些NuGet软件包:

  • Microsoft.ML 1.4.0
  • Microsoft.ML.TensorFlow 1.4.0
  • Microsoft.ML.ImageAnalytics 1.4.0
  • Microsoft.NETCore.UniversalWindowsPlatform 6.2.9
  • NETStandard.Library 2.0.3
  • SciSharp.TensorFlow.Redist 1.15.0
  • Xamarin.Essentials 1.2.0
  • Xamarin.Forms 4.2.0.709249

我正在尝试为x64 UWP构建。在这种情况下,似乎无法在其他在线位置找到此错误。这个问题最相似,但对我没有任何帮助:ML.NET fails to run on uwp

我很确定我理解错误的含义-如先前链接的SO问题所述:

这是一个.NET Standard异常,当库尝试访问未在平台上实际实现的API时发生。

真正的问题是,如果我使用的平台与ML.NET 1.4.0兼容,为什么要打这个呢?

据我所知,ML.NET应该能够在UWP(https://docs.microsoft.com/en-us/windows/ai/windows-ml/get-started-uwp)和x64平台(https://github.com/dotnet/machinelearning)上运行,那么我还缺少什么?

任何想法/建议都非常感谢。

2 个答案:

答案 0 :(得分:0)

Microsoft.ML是支持uwp平台。但是 sourceSets["main"].dependencies { implementation(npm("@jetbrains/kotlin-react", "16.9.0-pre.89")) implementation(npm("@jetbrains/kotlin-react-dom", "16.9.0-pre.89")) implementation(npm("@jetbrains/kotlin-css", "1.0.0-pre.89")) implementation(npm("@jetbrains/kotlin-css-js", "1.0.0-pre.89")) implementation(npm("@jetbrains/kotlin-styled", "1.0.0-pre.89")) implementation(npm("react-google-charts")) implementation("org.jetbrains.kotlinx:kotlinx-html-js:0.6.12") } 是用于GDI +的.NET名称空间。该技术不适用于Windows应用商店应用程序或通用Windows应用程序。参见.NET for Windows apps。您可以在Windows Store应用程序和UWP中使用Win2D lib进行绘制。请避免在uwp项目中使用System.Drawing

答案 1 :(得分:0)

目前的明确答案是:ML.NET不支持UWP的图像,并且目前没有计划提供它。

https://github.com/dotnet/machinelearning/issues/3154#issuecomment-573178943