2

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)?

Josh
  • 159
  • 2
  • 10

1 Answers1

4

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.

LOST
  • 2,956
  • 3
  • 25
  • 40
  • I do like your solution; however this will be pushed onto a device with limited storage capacity. Therefore with the requirement to use TF and Python as dependencies, I'm thinking it will be too much. – Josh Nov 20 '20 at 16:06
  • Oh, I misread your question then. ML.NET supports ONNX models, so one option is to convert to ONNX. See https://stackoverflow.com/questions/54214470/tensorflow-to-onnx-conversion – LOST Nov 20 '20 at 21:41