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".
+1
+1
+1
+1
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 ?
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.
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
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 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
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.
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:
@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
@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:
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.
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.)

For those of you on Windows, here are the steps that @xiaomaogy did in VS:
It also works for me if I go to Debug > Attach Unity Debugger.
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?
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.
" 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?
@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.
@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.
+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.
Got the same error, cannot run anything because of Internal Brain..
Any updates on this? Without internal brain working, it's hard to make progress. Any workarounds will also be appreciated!
@lagidigu @hsaikia So for both of you, even the workaround I mentioned above doesn't work?
I didn't quite catch which workaround you are referring to. In my case it doesn't have anything to do with Visual Studio. There is an error on the Unity editor itself when I load my internal brain model and run the environment.
This is the error
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)
@hsaikia
The workaround is mentioned in my previous comment which said:
"I am trying to do what you described, but I was not able to reproduce the bug. Here is the steps I took:....."
However your error in the Unity seems unrelated with the TensorflowSharp version. Your error message said tensorflow side is looking for a input with name recurrent_in with type DT_FLOAT.
Did your code use LSTM? Could you please post your code and your trainer_config.yaml?
@xiaomaogy
Yes I use LSTM alongside imitation learning. Here is my agent --
https://github.com/hsaikia/UnityMLAgents/blob/master/SocialWalker/SWAgent.cs
My trainer_config.yaml file is here --
https://github.com/hsaikia/UnityMLAgents/blob/master/SocialWalker/trainer_config.yaml
My Brain is called SWStudent which is the last entry in the config file.
@xiaomaogy the problem is that I cannot even do step 1., as I cannot modify scripts, as long as the following message appears:
Assets/ML-Agents/Scripts/CoreBrainInternal.cs(12,7): error CS0246: The type or namespace name `TensorFlow' could not be found. Are you missing an assembly reference?
Can't really do anything, as the scene won't run because of that. Tensorflow has been installed.
EDIT: Found the fix, it was a package error... My bad.
@hsaikia I think your error is related with your LSTM usage. Could you post your snapshot of your Brain Script?
PlayerSetting -> Scriptomg Define Symbols -> ENABLE_TENSORFLOW
Using this option will result in a CS0246 error.
@xiaomaogy I don't quite understand what you mean by Brain Script. I did already post my agent script. If you wanna know how I assign brains to the instantiated agents, it is done here.
I thought LSTM was turned on only from trainer_config.yaml and has nothing to do with the C# code. In any case, I'll try to turn off LSTM and see if it works. Although without LSTM, my agents would be pretty much useless.
Hello
If you are starting a new project you must import the TFSharpPlugin again.
Well the TFSharpPlugin is imported. My problem still persists. I feel it has something to do with me using LSTM and imitation learning at the same time.
@hsaikia I made a fix for the issue you raised in #766 Can you tell me if it solves the problem you are having ?
Hi @vincentpierre, sorry for not replying earlier. Is the fix merged with the master branch yet? I was working on other projects and haven't had a time to look. I'll try it out soon enough.
@hsaikia It is on develop
Since Unity 2018.x already supports 4.7, I feels it is not necessary to make a .NET 4.6 TensorflowSharp version. Correct me if I am wrong, if I don't see any objection in a few days I will close this issue. @likeygame @rgjones33 @storedenen @ituni
I am closing this thread due to inactivity, but feel free to re-open it if you desire.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
PlayerSetting -> Scriptomg Define Symbols -> ENABLE_TENSORFLOW
Using this option will result in a CS0246 error.