locked
infer .net with Unity3D RRS feed

  • Question



  • Hello, 

    I'm working on a project using **Unity** with **Microsoft Kinect**  and **Microsoft infer.net** machine learning tool to create some body gesture recognition using Kinect. I used the sample project with NITE as a start for unity and it works fine.
    The problem is when I tried to add the Infer.net dlls.

    I am using Unity 3.2 pro it uses C# and mono. I copied all the dlls from the infer.net folder to the assets folder in my project (where unity adds them as references). it first complained about some dlls from system (I don't know why ?) so I copied them to the assets as well (System.deplyment.dll , system.windows.forms.dll).

    Finally the compiler was ok with all the classes and types. I compile in VS2010 and everything is ok. but when I play the program in Unity it gives me this error :
    InvalidProgramException: Errors found when compiling algorithm:
    MicrosoftResearch.Infer.ModelCompiler.CompileWithoutParams (ITypeDeclaration itd, System.Reflection.MethodBase method, MicrosoftResearch.Transforms.AttributeRegistry`2 inputAttributes)
    



    and the log is

    platform assembly: C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\Mono.Security.dll (this message is harmless)
      Platform assembly: C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\System.Runtime.Serialization.Formatters.Soap.dll (this message is harmless)
      Platform assembly: C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\Mono.Posix.dll (this message is harmless)
      Platform assembly: C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\Microsoft.JScript.dll (this message is harmless)
      Compilation failed with 3 error(s)(0,0) : error CS0006: cannot find metadata file `data-0AF40020'
      (0,0) : error CS0006: cannot find metadata file `data-18E90020'
      (0,0) : error CS0006: cannot find metadata file `data-12CB0020'
      InvalidProgramException: Errors found when compiling algorithm:
       at MicrosoftResearch.Infer.ModelCompiler.CompileWithoutParams (ITypeDeclaration itd, System.Reflection.MethodBase method, MicrosoftResearch.Transforms.AttributeRegistry`2 inputAttributes)
    [0x00000] in <filename unknown>:0  at MicrosoftResearch.Infer.InferenceEngine.Compile () 
    [0x00000] in <filename unknown>:0  at MicrosoftResearch.Infer.InferenceEngine.BuildAndCompile (Boolean inferOnlySpecifiedVars, IEnumerable`1 vars) 
    [0x00000] in <filename unknown>:0  at MicrosoftResearch.Infer.InferenceEngine.GetCompiledInferenceAlgorithm (Boolean inferOnlySpecifiedVars, IVariable var) 
    [0x00000] in <filename unknown>:0  at MicrosoftResearch.Infer.InferenceEngine.InferAll (Boolean inferOnlySpecifiedVars, IVariable var) 
    [0x00000] in <filename unknown>:0  at MicrosoftResearch.Infer.InferenceEngine.Infer[VectorGaussian] (IVariable var) 
    [0x00000] in <filename unknown>:0  at BPM.InferW (System.Collections.Generic.List`1[] xValuesData) 
    [0x0005e] in G:\study\kinect project\Unity kinect\Assets\scripts\BPM.cs:252  at BPM.Train (System.Collections.Generic.List`1[] xValuesData) 
    [0x00069] in G:\study\kinect project\Unity kinect\Assets\scripts\BPM.cs:231  at BPMtest.Test_BPM (Int32 nClass, Int32 totalFeatures, Double noisePrec, System.String fileName, MicrosoftResearch.Infer.Maths.Vector[] testData) 
    [0x00048] in G:\study\kinect project\Unity kinect\Assets\scripts\BPMtest.cs:58  at BPMtest.Start () 
    [0x000c1] in G:\study\kinect project\Unity kinect\Assets\scripts\BPMtest.cs:38 
    
     
    Any Ideas ?
    Friday, June 24, 2011 11:56 PM

All replies

  • From the stack trace, it appears that this error is happening when Infer.NET tries to compile the code that it generated.  Try adding the generated code file to your C# project (without changing anything else) and see if the project compiles. You can find more details about compiling generated code at http://research.microsoft.com/en-us/um/cambridge/projects/infernet/docs/Using%20a%20precompiled%20inference%20algorithm.aspx.   If it does compile in your project, then the issue is with invoking the Mono compiler at runtime.
    Saturday, June 25, 2011 12:01 PM
  • Thank you. That seems the case here.

    The code is being generated in the Model_EP.cs file correctly. But it seems like it doesn't find the file after that to compile it. I tried the other method of adding the .cs file to the project and instantiate it manually and it worked fine.

    But the problem is that this way is too troublesome and manual. So everytime I change the model, I have to go to the other part of the code and change the variable and other stuff. My question is that isn't there any other way to do this like to explicitly specify the path of the generated code file to the algorithm (like in the IGeneratedAlgorithm  method but using a file name instead of an object).

    this method didn't work too because of the same error.

    Any other suggestions maybe ?

    Thank yo.

     

     

    P.S. I'm very new to infer.net and I'm really in a hurry for my school project. So excuse me if couldn't read enough documentation.

    Saturday, June 25, 2011 3:37 PM
  • I found the problem is that infer creates the generated code files right next to the exe file. while unity can only see stuff inside the "assets" folder which is next to the exe too.

    Is there any way to change where infer creates the generated code file?   or where is reads it from ?

    Saturday, June 25, 2011 9:35 PM
  • You can use engine.Compiler.GeneratedSourceFolder to specify where the source goes. For example:

    engine.Compiler.GeneratedSourceFolder = @"..\..";
    

     

    Monday, June 27, 2011 9:21 AM
    Owner