ml-agents icon indicating copy to clipboard operation
ml-agents copied to clipboard

CoreBrainInternal.cs does not find namespace TensorFlow

Open likeygame opened this issue 8 years ago • 38 comments

I defined ENABLE_TENSORFLOW and installed TFSharpPlugin. when attached bytes script file to Graph Model of Brain and played, it works. But it does not work to debug C# script in visual studio.

here are errors. Error CS0246 The type or namespace name 'TensorFlow' could not be found (are you missing a using directive or an assembly reference?) Warning The primary reference "TensorFlowSharp" could not be resolved because it was built against the ".NETFramework,Version=v4.6.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6".

likeygame avatar Mar 30 '18 01:03 likeygame

+1

ghost avatar Mar 30 '18 13:03 ghost

+1

storedenen avatar Apr 05 '18 10:04 storedenen

+1

ituni avatar Apr 09 '18 07:04 ituni

+1

entropia666 avatar Apr 13 '18 17:04 entropia666

I am unable to reproduce this bug. Can you tell me what platform, what version of visual studio and Unity do you use, where the error appears (VS or Unity Console)? I do not understand But it does not work to debug C# script in visual studio. Can you give more details and maybe a screenshot ?

vincentpierre avatar Apr 14 '18 06:04 vincentpierre

When you press the button in VS "attach to unity" to run in debug mode, it doesn't work. Vincent, I can let you on my machine if you want, with teamviewer, and show you.

entropia666 avatar Apr 14 '18 08:04 entropia666

Unity Version 2017 3.1f1 VIsual Studio 2017 15.6.2 .net framework 4.7.02556 Microsoft Visual Studio Community 2017 Version 15.6.2

Details: VisualStudio.15.Release/15.6.2+27428.2005 Microsoft .NET Framework Version 4.7.02556

Installed Version: Community

C# Tools 2.7.0-beta3-62707-11. Commit Hash: 75dfc9b33ed624dff3985c7435c902c3c58c0e5c C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

Visual Basic Tools 2.7.0-beta3-62707-11. Commit Hash: 75dfc9b33ed624dff3985c7435c902c3c58c0e5c Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Unity 3.6.0.5 Visual Studio Tools for Unity

entropia666 avatar Apr 14 '18 09:04 entropia666

Thank you for this information @entropia666 My Visual Studio is not connected to my Unity and no one in my team tried to connect the two. We only use Visual Studio to edit code and when we want to run it, we click the play button in the Unity Editor. The issue could be that Visual Studio needs to make sure that the .NET frameworks are compatible while Unity does not. Is it possible for you to play a scene with the internal brain without having to use Visual Studio? I am still unable to reproduce this problem, does it affect both Mac and Windows ?

vincentpierre avatar Apr 14 '18 21:04 vincentpierre

@vincentpierre how does your team single step through code if you do not use the VS debugger?

I think the message is pretty clear - whomever built the TensorflowSharp dll did it against 4.6.1 - Can we get a copy of the dll built with 4.6 instead?

Also if you look at the web page for tensorflowsharp you will find this text "On Visual Studio, make sure that you are targeting .NET 4.6.1 or later, as this package uses some features of newer .NETs. Otherwise, the package will not be added. Once you do this, you can just use the TensorFlowSharp nuget"

So not compatible with Unity at 4.6 unless there is some work around?

Edit : posted https://github.com/migueldeicaza/TensorFlowSharp/issues/258

ghost avatar Apr 15 '18 18:04 ghost

Hi, We do not use the VS debugger at all. Like I said, we use VS to edit code and then run it in the editor. Thank you for brining this problem to our attention, I think the issue is that the VS debugger is stricter than the Unity editor when it comes to .NET version. Like you said, Unity is 4.6 and TensorFlowSharp is 4.6.1, so this problem will require some workaround. I would like to know if you can run the editor with internal brain or if the VS debugger prevents you from running the editor in play mode.

vincentpierre avatar Apr 15 '18 21:04 vincentpierre

I can confirm that we can still run the game within the Unity editor with this, but when we try to attach Visual Studio to Unity to do debugging we run into the same issue above.

Our Environment:

  1. Unity version 2017.2.0f3
  2. Visual Studio Professional 2017 - v15.6.6

Yecats avatar Apr 15 '18 23:04 Yecats

@vincentpierre No issues in the editor that are apparent. It is only when run through the VS debugger.

It seems assemblies in Unity work if they are 4.6.x

I hope the author of TensorFLowSharp responds to my issue

ghost avatar Apr 17 '18 00:04 ghost

@entropia666 @rgjones33 @staceyhaffner I am trying to do what you described, but I was not able to reproduce the bug. Here is the steps I took:

  1. Set the Brain Type to "Internal" in 3DBall.
  2. Click to "Assets" -> "Open C# Project", the VS opens.
  3. Click the run button in the Unity Editor, the 3DBall scene starts balancing.
  4. Set a breakpoint in CoreBrainInternal.cs: 171.
  5. In VS, go to "Run" -> "Attach To Process", select "Unity Editor", "Debugger" is selected to be "Unity Debugger", then click "Attach". Now the 3DBall scene stops.
  6. From here I was able to single step through the code without any error.

Please let me know where I was doing wrong or differently from you guys. Also the OS I used was mac, and the Visual Studio 7.4.2 (build 12), Unity Editor 2017.3.1f.

xiaomaogy avatar Apr 17 '18 02:04 xiaomaogy

When I do the same steps that you outlined on Windows it attaches just fine. The issue seems to be tied to the "Attach to Unity" button within the tool bar. (I'm guessing its a difference on whether VS is doing a build before running.)

image

For those of you on Windows, here are the steps that @xiaomaogy did in VS:

  1. In VS, go to Debug -> Attach To Process, select Unity.exe, then click Attach.

It also works for me if I go to Debug > Attach Unity Debugger.

Yecats avatar Apr 17 '18 14:04 Yecats

In my case I have imported the soccer example in my existing project. The scene objects related the ml-agents example are currently disabled. I am trying to debug another aspect of my game. I open a script in VS from Unity. I set a breakpoint. I click attach to Unity from the Toolbar. VS does a build and fails due the error msg we are discussing. I am asked if I want to run the last successful build. If I click yes the attach continues. I can then press play in unity and proceed.

@staceyhaffner I am also able to connect to the debugger the way you stated. Prior to this discussion I have always clicked on the Attach to Unity in the tool bar.

TensorFlowSharp has a preque of 4.6.1 for the System.ValueTuple 4.4.0 - by using an older version of NetF, I wonder if things are actually working as designed?

ghost avatar Apr 17 '18 15:04 ghost

So it seems the problem is solved with the way @staceyhaffner stated here. When we release the TensorflowSharp plugin compatible with Tensorflow 1.5 or 1.6, we will try to build it against .NET 4.6 instead of 4.6.1 to see if it works. If you guys think this issue is solved I will close it.

xiaomaogy avatar Apr 17 '18 21:04 xiaomaogy

" we will try to build it against .NET 4.6 instead of 4.6.1 to see if it works." -xiaomaogy Have you guys done this yet?

Aarsh-Singh-Vishen avatar Apr 18 '18 07:04 Aarsh-Singh-Vishen

@xiaomaogy It is a work around so you avoid the compiler warning. I think it still needs a proper solution as you mentioned. Someone needs to understand if System.ValueTuple 4.4.0 is a hard requirement.

ghost avatar Apr 18 '18 12:04 ghost

@Aarsh-Singh-Vishen @rgjones33 We are actually working on upgrading the ML-Agent's TensorflowSharp plugin from 1.4 to 1.5 (or maybe 1.6). Along with that upgrade we will try to build against .NET 4.6 instead of .NET 4.6.1.

xiaomaogy avatar Apr 19 '18 22:04 xiaomaogy

+1 same issue. Internal Brains do not work.

On VS Code :

The primary reference "TensorFlowSharp" could not be resolved because it was built against the ".NETFramework,Version=v4.6.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6".

On Unity Editor :

UnityAgentsException: The tensorflow graph needs an input for recurrent_in  of type DT_FLOAT
CoreBrainInternal.DecideAction (System.Collections.Generic.Dictionary`2[TKey,TValue] agentInfo) (at Assets/ML-Agents/Scripts/CoreBrainInternal.cs:334)
Brain.DecideAction () (at Assets/ML-Agents/Scripts/Brain.cs:241)
Academy.EnvironmentStep () (at Assets/ML-Agents/Scripts/Academy.cs:477)
Academy.FixedUpdate () (at Assets/ML-Agents/Scripts/Academy.cs:507)

I am not 100% certain if this is the case, but up until I upgraded to the latest version of ML Agents, internal brain was working. These errors started popping up after I did a recent git pull a couple of days ago so I presume the bug was introduced recently. Just FYI if it helps.

hsaikia avatar Apr 28 '18 11:04 hsaikia