2

I've trained a CNN model on python using Tensorflow, and I plan to use the model in a Unity project (which uses C#).

I guess it's possible to run the python script using IronPython, but does it require the user of the Unity game to have installed Tensorflow? And what about packaging the game for mobile devices (Android)?

Or do I have to instead write a function or something to simulate the process of CNN myself? What would be a simpler way to do this?

3 Answers3

2

How should I deploy a trained CNN model to a C# project?

I did a quick search on the Tensorflow website and the simplest and recommended way to do this is to use C++ instead of Python. This is not about C++ vs Python. It's about portability because any code written in this langugae can run on most platforms Unity supports and the Tensorflow API supports C++ for Android and iOS.

Just download the Tensorflow C++ API. Build a simple wrapper for each Tensorflow class you want to use. On the C# side, call those wapper functions.

For example, let's say that you have a C++ class called Context and you want to make it a plugin and use it in Unity program, see this post that describes how to do that. It's the simplest solution out there. That's how to make a wrapper for a C++ API.

Programmer
  • 121,791
  • 22
  • 236
  • 328
1

You probably want to export your model using the SavedModel format (see this related question/answer).

With that format, you should be able to load the model in either

Hope that helps.

ash
  • 6,681
  • 3
  • 18
  • 30
0

You can start a TensorflowServing which providing a predict service, you can access the predict service by C# grpc client.

Tianjin Gu
  • 784
  • 6
  • 17