TensorFlowSharp icon indicating copy to clipboard operation
TensorFlowSharp copied to clipboard

Version 1.13.0 of TensorFlowSharp unable to consume .PB model file (works with updated tensorflow.dll)

Open sdg002 opened this issue 6 years ago • 6 comments

Describe the bug I have a simple C# console EXE (.NET Framework which uses Version 1.13.0 of TensorFlowSharp . The EXE produces this error when consuming a TF model file produced using Version 1.14.0 of tensorflow-gpu . The EXE worked beautifully few months ago. I upgraded the version of TF and ran into this problem.

TensorFlow.TFException: NodeDef mentions attr 'explicit_paddings' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_BFLOAT16, DT_FLOAT, DT_DOUBLE]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID"]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]; attr=dilations:list(int),default=[1, 1, 1, 1]>; NodeDef: {{node conv1/convolution}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](conv1_input, conv1/kernel/read). 
(Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
   at TensorFlow.TFStatus.CheckMaybeRaise(TFStatus incomingStatus, Boolean last)
   at TensorFlow.TFGraph.Import(TFBuffer graphDef, TFImportGraphDefOptions options, TFStatus status)
   at TensorFlow.TFGraph.Import(Byte[] buffer, TFImportGraphDefOptions options, TFStatus status)
   at TensorFlow.TFGraph.Import(Byte[] buffer, String prefix, TFStatus status)
   at ConsoleAppTester.Program.TestMnistImagesUsingTrainedModel(String modelfile, String folderWithMNIST) in C:\Users\saurabhd\MyTrials\MachineLearnings-2\MNISTpng\ConsoleAppTester\Program.cs:line 101
   at ConsoleAppTester.Program.Main(String[] args) in C:\Users\saurabhd\MyTrials\MachineLearnings-2\MNISTpng\ConsoleAppTester\Program.cs:line 23

To Reproduce

  • Train MNIST using TF 1.14 (GPU)
  • Export model and weights to .PB
  • Use 1.13 TensorflowSharp to import the graph

Expected behavior The same TensorFlowSharp code worked with older Tensorflow models.

Desktop (please complete the following information):

  • OS: Windows 10
  • Version: TF 1.14 , TensorFlowSharp 1.13

What solved the problem? I copied over the latest tensorflow.dll as libtensorflow.dll into the output directory of the C# executable project. Source URL: https://www.tensorflow.org/install/lang_c

Thank you for all the efforts. I am happy to provide further Python scripts if you want test cases.

sdg002 avatar Aug 01 '19 11:08 sdg002

I had the same problems. I had resolved training the network with the same TF version 1.13. It's a work around but actually works.

DavideCatto avatar Aug 08 '19 15:08 DavideCatto

Hi @DavideCatto , Thanks for replying. I tried downgrading to 1.13 but I get this message. By any chance would you know why Python would not allow me to install 1.13? Thanks, Saurabh

py -m pip install tensorflow-gpu==1.13
Collecting tensorflow-gpu==1.13
  Could not find a version that satisfies the requirement tensorflow-gpu==1.13 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 2.0.0a0, 2.0.0b0, 2.0.0b1)
No matching distribution found for tensorflow-gpu==1.13

sdg002 avatar Aug 09 '19 09:08 sdg002

Hi @DavideCatto , Thanks for replying. I tried downgrading to 1.13 but I get this message. By any chance would you know why Python would not allow me to install 1.13? Thanks, Saurabh

py -m pip install tensorflow-gpu==1.13
Collecting tensorflow-gpu==1.13
  Could not find a version that satisfies the requirement tensorflow-gpu==1.13 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 2.0.0a0, 2.0.0b0, 2.0.0b1)
No matching distribution found for tensorflow-gpu==1.13

Try tensorflow-gpu==r1.13 Cheers

DavideCatto avatar Aug 09 '19 09:08 DavideCatto

Thanks for the hint.

This command worked.

py -m pip install tensorflow-gpu==1.13.1

sdg002 avatar Aug 11 '19 11:08 sdg002

Instead of recompiling you could update the tensorflow dll. This was the easiest way for me:

  1. Install the SciSharp.TensorFlow.Redist package for the tensorflow version you need.
  2. Copy the tensorflow.dll from there into the root directory of the project and rename to libtensorflow.dll
  3. Add this file to your project in VS and set its build properties to "Content" and "Copy if newer"

geometrikal avatar Oct 23 '19 22:10 geometrikal

Instead of recompiling you could update the tensorflow dll. This was the easiest way for me:

  1. Install the SciSharp.TensorFlow.Redist package for the tensorflow version you need.
  2. Copy the tensorflow.dll from there into the root directory of the project and rename to libtensorflow.dll
  3. Add this file to your project in VS and set its build properties to "Content" and "Copy if newer"

can you explain the 2nd and 3rd step please. @geometrikal

mage-sh avatar Feb 29 '20 07:02 mage-sh