Skip to content

MaruTama/tensorflow_for_unity

Repository files navigation

Reference Notes

C#でTensorFlowを動かす。
C#でTensorFlowのCNNを動かす。
Unity上でTensorFlowのCNNを動かす。

Quick start

  1. To set up the development environment and build TensorFlowSharp, please refer to the following.
  2. Create a CNN model
  3. Create a project with unity

How to make development environment

Clone( or Download) TensorFlowSharp

https://github.com/migueldeicaza/TensorFlowSharp

Link of dll file
https://github.com/migueldeicaza/TensorFlowSharp#working-on-tensorflowsharp

ubuntu 16.04

Install flatpak

Reference: Install MonoDevelop preview via FlatPak

$ sudo add-apt-repository ppa:alexlarsson/flatpak
$ sudo apt update
$ sudo apt install flatpak

Install mono Dev

$ flatpak install --user --from https://download.mono-project.com/repo/monodevelop.flatpakref
# Check if it can be started
$ flatpak run com.xamarin.MonoDevelop

Add library to system

Reference1 : LD_LIBRARY_PATH を設定しても反映されないことがある
Reference2 : Interop with Native Libraries

$ cd Downloads
$ wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.1.0.tar.gz
$ cd /usr/local
$ sudo tar xzvf ~/Downloads/libtensorflow-cpu-linux-x86_64-1.1.0.tar.gz
#Configuration a path
$ cd /etc/ld.so.conf.d
$ sudo vim lib_path.conf
#Save the string below(A directory with Libtensorflow.so)
/usr/local/lib
#Rebuild /etc/ld.so.cache
$ sudo ldconfig
$ ldconfig -p > ~/out.txt
#Check if the library has been added
$ find ~/ -type f -name "out.txt" | xargs grep 'libtensorflow.so'

Build the solution

Open the solution (.sin) right under the clone (or download) directory with MonoDevelop.
Screenshot from 2017-03-17 23-33-57.png Next, rebuild the solution with Build -> Rebuild All.
Screenshot from 2017-03-17 23-34-52.png I move SampleTest. Select SampleTest and press Build Project.
Screenshot from 2017-03-18 00-55-02.png

Start the executable file on the console.

Install mono-complete

$ sudo apt-get install mono-complete
$ cd ~/workspace/c_sharp/TensorFlowSharp/SampleTest/bin/Debug
$ mono SampleTest.exe

[Additional notes]
Reference:Nuget and “Unable to load the service index”

I got an error as below. (on 7.29 2017)

[nuget.org] Unable to load the service index for source https://api.nuget.org/v3/index.json. An error occurred while sending the request
Error: SecureChannelFailure (Object reference not set an instance of an object) Object reference not set to an instance of an object

How to deal
run command below from terminal.

export MONO_TLS_PROVIDER=legacy

So the build will pass.

Mac

Version

macOS Sierra 10.12.6
Visual Studio 7.0.1 (build 24)
unity 2017.1.0f3

Install VisualStudio

download and install the installer from the below link
https://www.visualstudio.com/vs/visual-studio-mac/

Add library to system

$ cd ~/Downloads
$ curl -O https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.1.0.tar.gz
$ cd /usr/local
$ sudo tar zxvf ~/Downloads/libtensorflow-cpu-darwin-x86_64-1.1.0.tar.gz
$ cd lib
$ sudo mv libtensorflow.so libtensorflow.dylib
#Check if the library has been added
$ find /usr/local/ -type f -name "libtensorflow.dylib"

Build the solution

Open the solution (.sin) right under the clone (or download) directory with VisualStudio.
Next, rebuild the solution with Build -> Rebuild All.
スクリーンショット 2017-07-31 00.40.19.png

Windows

Version

Microsoft Visual Studio Community 2017
Version 15.2 (26430.16) Releasec
Microsoft .NET Framework
Version 4.6.01586

Add library to system

download dll file from the below link
https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.2.0-rc0.zip

After expansion, rename from tensorflow.dll to libtensorflow.dll and move in C:\Windows\System32.
スクリーンショット 2017-05-15 23.50.34.png

Install VisualStudio

download and install the installer from the below link.
https://www.visualstudio.com/downloads/
Follow the instructions to install the tool.

Build the solution

Open the solution (.sin) right under the clone (or download) directory with VisualStudio.
Next, rebuild the solution with Build -> Rebuild All. スクリーンショット 2017-07-31 00.52.47.png

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published