locked
Ml.Net Invalid GraphDef RRS feed

  • Question

  • Hi,

    We are working on how to consume the tensorflow model in .Net using ML.NET. We are using below tutorial as reference :

    Tutorial Link : https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/image-classification

    We tested with model that is used in the Tutorial and it worked fine. But, when we replace tutorial model with our tensorflow model (object detection model which we have exported from Azure Custom Vision), it is throwing an Exception saying ‘Invalid GraphDef’, while loading the tensor flow model. The same custom vison model works fine when consumed in Python code.

    We checked multiple forums but could not find right resolution.

    Details:

    Project Name : TransferLearningTF

    Class name : program.cs

    Method Name : GenerateModel

    Code :

    IEstimator<ITransformer> pipeline = mlContext.Transforms.LoadImages(outputColumnName: "input", imageFolder: _imagesFolder, inputColumnName: nameof(ImageData.ImagePath))

                                                                                                  .Append(mlContext.Model.LoadTensorFlowModel(_inceptionTensorFlowModel)

                                                                                                                    .ScoreTensorFlowModel(outputColumnNames: new[] { "softmax2_pre_activation" }, inputColumnNames: new[] { "input" }, addBatchDimensionInput: true))

    Exception Details :

    Exception Message : Tensorflow exception triggered while loading model

    Source : Microsoft.ML.TensorFlow

    Stacktrace

       at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSessionByModelFilePath(IExceptionContext ectx, String modelFile, Boolean metaGraph)    at Microsoft.ML.TensorFlow.TensorFlowUtils.GetSession(IHostEnvironment env, String modelPath, Boolean metaGraph)    at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTensorFlowModel(IHostEnvironment env, String modelPath)    at Microsoft.ML.TensorflowCatalog.LoadTensorFlowModel(ModelOperationsCatalog catalog, String modelLocation)    at PredictionModel.Program.GenerateModel(MLContext mlContext) in D:\Cognitive-Samples-VideoFrameAnalysis-master\Windows\PredictionModel\Program.cs:line 35    at PredictionModel.Program.Main(String[] args) in D:\Cognitive-Samples-VideoFrameAnalysis-master\Windows\PredictionModel\Program.cs:line 22

    Inner Exception:

    Exception  Message  : Invalid GraphDef

    Source :  TensorFlow.NET

    Stack trace

       at Tensorflow.Status.Check(Boolean throwException)    at Tensorflow.Graph.Import(Byte[] bytes, String prefix)    at Tensorflow.Graph.Import(String file_path, String prefix)    at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSessionByModelFilePath(IExceptionContext ectx, String modelFile, Boolean metaGraph)

    Thursday, July 23, 2020 9:16 AM

Answers

All replies

  • Hi Amitkumar82,

    Since your problem is more related to ML.NET, I haved move the thread to 'where is the forum for...?' forum to help you find the correct forum to go ask questions.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 24, 2020 9:39 AM
  • Friday, July 24, 2020 9:55 AM