migueldeicaza / TensorFlowSharp

TensorFlow API for .NET languages
MIT License
3.14k stars 578 forks source link

What are the correct steps for TensorflowSharp using the GPU? #290

Open bzburr opened 6 years ago

bzburr commented 6 years ago

HI there

I have a working CPU based TensorflowSharp object detection app. happy days nit at 1.5 seconds per images and thousands of images to process i need to speed it up :)

I also have a working model that is built using the GPU on the same PC.

Can someone tell me exactly what i need to do to make my TensorflowSharp use the GPU.

I've tried downloading the libtensorflow_gpu.dll etc and copying them to the suggested folders, i've tried using the _python_pywrap_tensorflow_internal.pyd renamed to libtensorflow...- but the gpu is isn't getting hit - is there something i need to do when creating the TFSession object?

What might have i missed?

edwardyehuang commented 6 years ago

I don't think your Tensorflowsharp is using libtensorflow_gpu.dll. Maybe you need to rename it to libtensorflow.dll. Also make sure your libtensorflow.dll is larger than 200mb (If you are using 1.7)

bzburr commented 6 years ago

yes i shall write it up and post a "how to" for future reference :)

migueldeicaza commented 6 years ago

You do need to replace the libraries I distribute with the GPU versions.

It is on my TO-Do list to package both and swtich those at runtime. I am just in deep agony at .NET still lacking support for doing this swapping.

I have some of the work done on the dual branch, it is not finished yet.

MykolaKovalchuk commented 6 years ago

Don't want to start one more thread about GPU...

Can someone help me, where I can find libtensorflow.so and libtensorflow_framework.so in Linux (Ubuntu), which are used by Python, and which I have built to work with GPU?

I have found libtensorflow_framework.so in one of Python subfolders, but I cannot find libtensorflow.so anywhere. And when I replace libtensorflow_framework.so in TensorFlowSharp/runtimes subfolder, it does not work with error: "cannot find dll libtensorflow".

MykolaKovalchuk commented 6 years ago

Btw, assemblies in .Net can be loaded manually. So I would have several classes in different assemblies with methods bound to different tensorflow libraries (CPU, GPU), and in runtime initialize class from corresponding assembly.

MykolaKovalchuk commented 6 years ago

I have downloaded pre-built libtensorflow.so and libtensorflow_framework.so from tensorflow site as described here: https://www.tensorflow.org/install/install_c Seems to be working.