.NET Framework and TensorFlow.NET/Machine Learning

I am trying to load a pre-trained tensorflow model that was written in python into C#. One of my requirements is I cannot depend on python being installed on a computer since this eventual DLL will get passed around a lot on different computers. I am having to use .NET Framework 4.6.2 for LabView support, but TensorFlow.NET is not directly supported by .NET Framework 4.6.2, but is under .NET Standard 2.0. I've seen some places where it should work with 4.6.2 and other places where it won't. I thought I'd ask here to see if someone has had a similar experience. The main problem is .Net Framework doesn't have good support for backend packages that TensorFlow.NET needs. If there is another way to load a python machine learning model, like a .pkl file, into C# and have it predict data that works too. I have also tried using ML.NET instead of using a python model, but ML.NET is limited for my needs.
8 Replies
reflectronic
reflectronic8mo ago
.NET Standard 2.0 should mostly work with .NET Framework 4.6.2. it is unlikely that it won't work when you say
doesn't have good support for backend packages that TensorFlow.NET needs
i assume that means you tried installed the SciSharp.TensorFlow.Redist package that you need, and it did not work?
user610programmer
user610programmerOP8mo ago
I was able to install the SciSharp.TensorFlow.Redist package but it basically ignored it. On TensorFlow.NET's github page, someone was having a similar issue and one of the mods said that .NET Framework didn't support backend packages well. They could've misunderstood something or maybe something got updated but it hasn't worked for me thus far
reflectronic
reflectronic8mo ago
do you have tensorflow.dll in your build output once you install it?
user610programmer
user610programmerOP8mo ago
yes
reflectronic
reflectronic8mo ago
how do you know it's being 'ignored'?
user610programmer
user610programmerOP8mo ago
I was assuming it was. I just started over installing everything in a new project and it seems like it has gotten passed the backend problem. Now it is just a TensorFlow.Binding error: Unhandled Exception: System.TypeInitializationException: The type initializer for 'Tensorflow.Binding' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at Tensorflow.c_api.TF_Version() at Tensorflow.tensorflow..ctor() at Tensorflow.Binding..cctor() --- End of inner exception stack trace --- at Tensorflow.Binding.get_tf() at TFTest.Program.Main(String[] args) in *\Program.cs:line 12 I am just testing it with some test code which is: using System; using static Tensorflow.Binding; namespace TFTest { internal class Program { static void Main(string[] args) { var hello = tf.constant("hello"); Console.WriteLine(hello); } } }
reflectronic
reflectronic8mo ago
you need to disable Prefer 32-bit
user610programmer
user610programmerOP8mo ago
That seems to have worked. Thanks
Want results from more Discord servers?
Add your server