.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
.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 needsi assume that means you tried installed the SciSharp.TensorFlow.Redist package that you need, and it did not work?
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
do you have tensorflow.dll in your build output once you install it?
yes
how do you know it's being 'ignored'?
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);
}
}
}
you need to disable Prefer 32-bit
That seems to have worked. Thanks