Skip to content

Instantly share code, notes, and snippets.

@pgsin
Created August 22, 2018 09:30
Show Gist options
  • Save pgsin/35bdc96f89a7c0ff431d9dfd8df2ee6a to your computer and use it in GitHub Desktop.
Save pgsin/35bdc96f89a7c0ff431d9dfd8df2ee6a to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TensorFlow;
namespace MachineLearning
{
class Program
{
private static string _modelPath;
static void Main(string[] args)
{
// Path of the Frozen model
_modelPath = "D:\\net_Repos\\net\\MachineLearning\\Model\\frozen_model.pb";
string modelFile = _modelPath;
float[,] data = {{3, 10, 7, 20, 5, 9, 7, 9, 4, 3},
{ 3, 5, 7, 4, 5, 9, 7, 9, 4, 3},
{ 2, 8, 8, 7, 8, 5, 5, 9, 7, 2}};
// TensorflowSharp Session
using (var graph = new TFGraph()){
var model = File.ReadAllBytes(modelFile);
graph.Import(model);
Console.Write("reached here");
var session = new TFSession(graph);
var runner = session.GetRunner();
Console.Write("reached here");
// AddInput is the input node and Fetch is the output node in Tensorflow graph
runner.AddInput (graph ["Placeholder/inputs_placeholder"] [0], data).Fetch (graph ["Accuracy/predictions"] [0]);
var output = runner.Run();
var result = output[0];
var se = (Boolean[,])result.GetValue(jagged: false);
Console.WriteLine ("{0}[1]", result);
for (int i = 0; i < se.GetLength(0); i++){
for (int j = 0; j < se.GetLength(1); j++){
Console.WriteLine("{0}", se[i, j]);
}
}
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment