question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TensorFlowSharp Unity "'TensorflowSharp' does not exist in the current context" issue

See original GitHub issue

Hi there,

I am tying to build an object detection app using Unity with TensorFlowSharp. The app works when I run it in Unity but I can’t get it to work on my android device. One thing to note is that in one of the scripts there are the following lines:

#if UNITY_ANDROID TensorFlowSharp.Android.NativeBinding.Init(); #endif

but I have to comment these out or else I get an error in both Unity and VS saying:

error CS0103: The name `TensorFlowSharp’ does not exist in the current context.

I tried to build the project by commenting these lines out, copied the APK onto my device and while it runs, it doesn’t detect any objects. It just starts the camera and then that’s it. I read that the above lines of code need to be there in order for this to work on android.

I am completely new to using TensorFlow and TensorFlowSharp in Unity, therefore please let me know if I missed out anything. 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
manolomirandaccommented, Aug 28, 2019

After searching about this issue, I have found that the project has a missing part on this conditional:

#if UNITY_ANDROID

The only thing that I had added was this:

#if UNITY_ANDROID && !UNITY_EDITOR

I hope this help you! 😄 BTW: this is the link of the answer : https://stackoverflow.com/questions/46245530/why-is-platform-dependent-compilation-not-working

1reaction
Pennywise881commented, Jan 7, 2019

OK so I managed to fix this issue. I downloaded an older version of the plugin (v0.3) from here: https://github.com/Syn-McJ/TFClassify-Unity

After exporting it I got another error and the project wouldn’t compile. This is the problem that I was facing: https://github.com/Unity-Technologies/ml-agents/issues/979. Basically I couldn’t run the project in the Editor anymore.

The fix was to check the “Editor” option on the TensorFlowSharp.Android import settings when building. In order to run it in the Editor I had to comment out #if UNITY_ANDROID TensorFlowSharp.Android.NativeBinding.Init(); #endif line and uncheck the “Editor” option under “Include Platforms section” of the TensorFlowSharp.Android import settings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The name does not exist in the current context
My code is located in "Assets\Replayer\Scripts\RecordingManager.cs", directly accessable, I didn't use a namespace yet.
Read more >
Update links throughout .md files for 0.2 release · 4b486330
Open an existing Unity project, or create a new one and import the RL interface package: ... If you will be using Tensorflow...
Read more >
How to set up a custom TensorFlow graph in Unity
First, download and install the TensorFlowSharp plug-in into your Unity environment. The plug-in download can be found in the Unity ...
Read more >
Name doesn't exist in current context, but variable has ...
You are trying to write code directly within the class. That is not allowed. Normally, you could join the field initializer with the...
Read more >
TensorFlowSharep plugin插件下载网址_xubuhui的博客
cs(59,9): error CS0103: The name 'TensorFlowSharp' does not exist in the current context`. Code: "#if UNITY_ANDROID TensorFlowSharp.Android.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found