Josh
Josh

Reputation: 209

Trained tensorflow model used in .NET framework

I used Google Colab to build a 1-D Convoluted Neural Network (CNN) model using Tensorflow (it is a multi-class, multi-label model). I would now like to take that saved model (for example the pb file) and make predictions inside of a .NET Framework using C# (Visual Studio). So I would like to do the following inside a .NET Framework (this is obviously really stripped down):

import tensorflow as tf
import numpy as np
import tensorflow_hub as hub

model = tf.keras.models.load_model('pb_model')

model.predict(data)

I haven't seen an easy solution for Tensorflow 1-D CNN model (which would just be load a Tensorflow library into the .NET Framework.

I've seen the ML.NET where they use transfer learning of a Tensorflow image classification model to begin their learning link.

I recently came across Tensorflow.NET on GitHub link. This seems to be the best avenue as they aim to implement Tensorflow in C# for .NET developers. However this builds a model and then tests it all inside the .NET framework; therefore it does not address how to take a trained 1-D CNN model from python and make predictions in the .NET framework.

Has anyone come across a similar problem and what did you do (or what would you suggest)?

Upvotes: 2

Views: 4360

Answers (1)

LOST
LOST

Reputation: 3284

You can use LostTech.TensorFlow aka Gradient to call pretty much any TensorFlow API from C#.

using tensorflow;

var model = tf.keras.models.load_model("pb_model");
model.predict(data);

More samples here

disclaimer: I am one of the authors.

Upvotes: 4

Related Questions