Skip to content

MLContext.Data.LoadFromEnumerable() not working in Unity for netstandard2.0 api #5760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KrasnovPavel opened this issue Apr 22, 2021 · 0 comments
Labels
P3 Doc bugs, questions, minor issues, etc.

Comments

@KrasnovPavel
Copy link

System information

  • WIndows 10
  • Unity 2021.1.2f1, backend: mono, api level: netstandard2.0
  • dotnet --info :
 Version:   5.0.201
 Commit:    a09bd5c86c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.201\

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295

.NET SDKs installed:
  5.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue

  • What did you do?
    I have read ML.NET and Unity #1886.
    I have added all necessary dlls to Assets/Plugin folder. And tested that my model working on data from text file.
    Now I want to load data from collection using MLContext.Data.LoadFromEnumerable() function.

  • What happened?
    It works in editor, but in standalone build i get PlutformNotSupported Excepetion.

  • What did you expect?
    Load data without exception.
    It works if i set api level to .Net4.x. Thats why it works in editor, but unfortunatly in real project i have to use .netstandard2.0 for my other dependencies.

Source code / logs

Minimal example:

using System.Linq;
using Microsoft.ML;
using UnityEngine;
using Random = UnityEngine.Random;

public class Clusterisator : MonoBehaviour
{
    void Start()
    {
        Calculate();
    }

    class Point
    {
        public float X, Y, Z;
    }

    public static void Calculate()
    {
        var points = Enumerable.Range(0, 100)
                .Select(_ => new Point {X = Random.value, Y = Random.value, Z = Random.value})
                .ToList();

        var mlContext = new MLContext(seed: 0);
        var dataView = mlContext.Data.LoadFromEnumerable(points);

        var pipeline = mlContext.Transforms
                .Concatenate("Features", "X", "Y", "Z")
                .Append(mlContext.Clustering.Trainers.KMeans(numberOfClusters: 5));

        var transformed = pipeline.Fit(dataView).Transform(dataView);
        var clusterColumn = transformed.Schema.GetColumnOrNull("PredictedLabel").Value;
        var cursor = transformed.GetRowCursor(new[] {clusterColumn});
        var clusterizatorResult = cursor.GetGetter<uint>(clusterColumn);

        while (cursor.MoveNext())
        {
            uint cluster = 0;
            clusterizatorResult(ref cluster);
            Debug.Log(cluster);
        }
    }
}

Exception stack trace:

PlatformNotSupportedException: Operation is not supported on this platform.
  at Microsoft.ML.ApiUtils.GeneratePeek[TOwn,TRow,TValue] (System.Reflection.FieldInfo fieldInfo, System.Reflection.Emit.OpCode assignmentOpCode) [0x00040] in <b2a9703d9c7542afbe2c6d1a607e584a>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a1e9f114a6e64f4eacb529fc802ec93d>:0 
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0004b] in <a1e9f114a6e64f4eacb529fc802ec93d>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <a1e9f114a6e64f4eacb529fc802ec93d>:0 
  at Microsoft.ML.Internal.Utilities.Utils.MarshalInvoke[TArg1,TArg2,TResult] (Microsoft.ML.Internal.Utilities.FuncStaticMethodInfo3`3[T1,T2,TResult] func, System.Type genArg1, System.Type genArg2, System.Type genArg3, TArg1 arg1, TArg2 arg2) [0x0000a] in <52c676b9d07a49dd94084172a2250221>:0 
  at Microsoft.ML.ApiUtils.GeneratePeek[TOwn,TRow] (Microsoft.ML.Data.InternalSchemaDefinition+Column column) [0x0003a] in <b2a9703d9c7542afbe2c6d1a607e584a>:0 
  at Microsoft.ML.Data.DataViewConstructionUtils+DataViewBase`1[TRow]..ctor (Microsoft.ML.Runtime.IHostEnvironment env, System.String name, Microsoft.ML.Data.InternalSchemaDefinition schemaDefn) [0x00060] in <b2a9703d9c7542afbe2c6d1a607e584a>:0 
  at Microsoft.ML.Data.DataViewConstructionUtils+StreamingDataView`1[TRow]..ctor (Microsoft.ML.Runtime.IHostEnvironment env, System.Collections.Generic.IEnumerable`1[T] data, Microsoft.ML.Data.InternalSchemaDefinition schemaDefn) [0x00000] in <b2a9703d9c7542afbe2c6d1a607e584a>:0 
  at Microsoft.ML.Data.DataViewConstructionUtils.CreateFromEnumerable[TRow] (Microsoft.ML.Runtime.IHostEnvironment env, System.Collections.Generic.IEnumerable`1[T] data, Microsoft.ML.Data.SchemaDefinition schemaDefinition) [0x00026] in <b2a9703d9c7542afbe2c6d1a607e584a>:0 
  at Microsoft.ML.DataOperationsCatalog.LoadFromEnumerable[TRow] (System.Collections.Generic.IEnumerable`1[T] data, Microsoft.ML.Data.SchemaDefinition schemaDefinition) [0x00011] in <b2a9703d9c7542afbe2c6d1a607e584a>:0 
  at Clusterisator.Calculate () [0x0003f] in C:\Users\User\RiderProjects\Minimal ML Test\Assets\Clusterisator.cs:25 
  at Clusterisator.Start () [0x00001] in C:\Users\User\RiderProjects\Minimal ML Test\Assets\Clusterisator.cs:10 

Minimal Unity project:
Minimal ML Test.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Doc bugs, questions, minor issues, etc.
Projects
None yet
Development

No branches or pull requests

2 participants