TensorFlowSharp icon indicating copy to clipboard operation
TensorFlowSharp copied to clipboard

TensorFlow.TFException: 'Invalid GraphDef'

Open RexTheCapt opened this issue 5 years ago • 2 comments

Describe the bug I took your example from README.MD and pasted it in and got a few errors and made a few modifications to make it go away. I can't seem to get it to work so here is the code. This is the image I am trying to feed it https://www.google.com/search?q=dogs&newwindow=1&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjp2YCZzeThAhXnk4sKHa_cB2oQ_AUIDigB&biw=1284&bih=699#imgrc=GK40Gyy6hLCFvM:

Link to project https://mega.nz/#!66J0yYAQ!kYW2z2-hQS-ym3nynQ9xMM_rr40tqNym6YOH3y5zwSI

using System;
using System.IO;
using System.Windows.Forms;
using TensorFlow;

namespace SharpNeatTest
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            using (var graph = new TFGraph())
            {
                graph.Import(File.ReadAllBytes("test.jpg")); // TensorFlow.TFException: 'Invalid GraphDef'
                var session = new TFSession(graph);
                var runner = session.GetRunner();
                TFTensor tensor = null;
                runner.AddInput(graph["input"][0], tensor);
                runner.Fetch(graph["output"][0]);

                var output = runner.Run();

                // Fetch the results from output:
                TFTensor result = output[0];
            }
        }
    }
}

To Reproduce Use the Debug mode on x64 CPU.

Load the code.

Debug. Done.

That was all I did.

Expected behavior To run without errors?

Screenshots I don't think screenshots are required here.

Desktop (please complete the following information):

  • OS: Windows 10 Version 1809 (OS Build 17763.437)
  • Browser: Firefox Quantum 66.0.3

Smartphone (please complete the following information): Noy using a phone for this

Additional context Not that I can think of

RexTheCapt avatar Apr 22 '19 21:04 RexTheCapt

Replace .jpg with your ML Model (.pb file). Remember that you are using frozen weights for that model. I also had the same problem. I followed https://github.com/migueldeicaza/TensorFlowSharp/issues/374#issuecomment-496353019 and this resolved my problem.

tanmay-18 avatar Nov 21 '19 07:11 tanmay-18

Hi there, I have the same issue, here is my code:

tf.compat.v1.disable_eager_execution(); var modelPath = "emotion_detection_model.pb"; var buffer = System.IO.File.ReadAllBytes(modelPath); var graph = tf.Graph().as_default(); graph.Import(buffer);

I get TensorFlow.TFException: 'Invalid GraphDef'. I tested emotion_detection_model.pb in Python app and it's fine so the prooblem is not in model.

AndriyKagui avatar Apr 16 '23 20:04 AndriyKagui