Skip to content
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

TensorFlow.NET issues with NuGet2Unity #839

Closed
asadowns opened this issue Aug 18, 2021 · 9 comments
Closed

TensorFlow.NET issues with NuGet2Unity #839

asadowns opened this issue Aug 18, 2021 · 9 comments

Comments

@asadowns
Copy link

I am not able to get the SciSharp.TensorFlow.Redist and TensorFlow.NET packages working in my unity environment using NuGet2Unity. The packages are downloaded but the nupkg files are not expanded and there are no dll files. If I manually unzip the nupkg files I am able to find a DLL in the TensorFlow.NET package but not in the SciSharp.TensorFlow.Redist which will not unzip at all.

I created a related issue for this in the NuGet2Unity repo GlitchEnzo/NuGetForUnity#412 since I'm not exactly sure where the problem lies.

Based on what @jvo3dc mentioned in this issue. They were able to get this working with the same approach using a previous version of TensorFlow.NET per their post. If I install their unitypackage directly rather than use NuGet2Unity the dll files do work as expected.

  • NuGet Package: SciSharp.TensorFlow.Redist@2.6.0, TensorFlow.NET@0.60.1
  • NuGetForUnity Version: 3.0.2
  • Unity Version: 2020.3.2f1
  • Operating System: MacOSX (also tested on Windows)
@Oceania2018
Copy link
Member

@asadowns Are you using .net standard 2.0?

@asadowns
Copy link
Author

@Oceania2018 I have tried both .net standard 2.0 and .net 4.x.

@asadowns
Copy link
Author

@Oceania2018 is there any other option for than NuGet for using these bindings in Unity. I saw in this post the author was able to build a unity package from the DLLs but unfortunately I don't know how to do that.

I tried using NuGet in a regular .NET project and that worked as expected but unfortunately I wasn't able to figure out how to copy over just the DLLs I needed with the right platform support.

Also in regards to your previous comment is .net standard 2.0 what you recommend.

Any help you can provide would be much appreciated. Thanks.

@Oceania2018
Copy link
Member

@asadowns
Copy link
Author

@Oceania2018 that seemed to do the trick. What changed?

In case anyone has this issue, I did have to make a few more changes to get it running in my environment.

  1. I had issues with Fody. It was getting both the netclassic and netstandard dlls and was missing some MSBuild dependencies. I had to remove the Fody dependency and use FodyHelpers instead but otherwise everything seems to work.
  2. I also had to follow the recommendations in this thread: DLL Not Found Exception #252 and install the Microsoft.ML.TensorFlow.Redist package otherwise I ran into an issue with running any TF code.

Thank you!

@Oceania2018
Copy link
Member

I changed back to .netstandard 2.0.
Microsoft.ML.TensorFlow.Redist is Tensorflow v1.x.
Is SciSharp.TensorFlow.Redist not working?

@asadowns
Copy link
Author

SciSharp.TensorFlow.Redist is not working. Here is the error that occurs.

I do have using static Tensorflow.Binding; in my code. Any thoughts? Fwiw, I removed Microsoft.ML.TensorFlow.Redist and now after I get it back I can't get it working again even with that.

System.TypeInitializationException : The type initializer for 'Tensorflow.Binding' threw an exception.
  ----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.DllNotFoundException : tensorflow
---
at PredictionBehavior.test () [0x00001] in /Users/asadowns/TensorflowPOC/Assets/Scripts/PredictionBehavior.cs:18 
  at ScriptTest.RandomTest () [0x00007] in /Users/asadowns/TensorflowPOC/Assets/Scripts/Tests 1/ScriptTest.cs:25 
  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 <eae584ce26bc40229c1b1aa476bfa589>:0 
--TargetInvocationException
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00014] in <eae584ce26bc40229c1b1aa476bfa589>:0 
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x000a8] in <eae584ce26bc40229c1b1aa476bfa589>:0 
  at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <eae584ce26bc40229c1b1aa476bfa589>:0 
  at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <eae584ce26bc40229c1b1aa476bfa589>:0 
  at System.Activator.CreateInstance[T] () [0x00021] in <eae584ce26bc40229c1b1aa476bfa589>:0 
  at Tensorflow.Binding.New[T] () [0x00000] in <5ead14e6f8524b02beeda5950188a505>:0 
  at Tensorflow.Binding..cctor () [0x00000] in <5ead14e6f8524b02beeda5950188a505>:0 
--DllNotFoundException
  at (wrapper managed-to-native) Tensorflow.c_api.TF_NewStatus()
  at Tensorflow.Status..ctor () [0x00006] in <5ead14e6f8524b02beeda5950188a505>:0 
  at Tensorflow.tensorflow..ctor () [0x0015f] in <5ead14e6f8524b02beeda5950188a505>:0 
  at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke(System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <eae584ce26bc40229c1b1aa476bfa589>:0

@asadowns
Copy link
Author

@Oceania2018 thanks again for looking into this. I had the same issues with nuget with scisharp.tensorflow.redist. So I had to manually unpack and copy to the dlls into my plugins folder. I'm wondering if the scisharp.tensorflow.redist package also needs to be rebuilt for .netstandard 2.0. Again, appreciate all your help with this. Thanks for the responses.

@Oceania2018
Copy link
Member

scisharp.tensorflow.redist is C binary library. nothing to do with .net.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants