machinelearning icon indicating copy to clipboard operation
machinelearning copied to clipboard

Tensorflow.InvalidArgumentError: Node name contains invalid characters

Open TopCat73 opened this issue 2 years ago • 2 comments

  • OS & Version: [Windows 10]
  • ML.NET Version: [ML.NET v2.01]
  • .NET Version: [.NET 6.0]

I have trained a DNN model using TensorFlot.NET (0.110.2) and saved the model to directory on my PC. I am then attempting to load the saved model using ML.Net. However, an exception "Node name contains invalid characters" is thrown when I attempt to load the saved model using API LoadTensorFlowModel.

Steps to reproduce :

  1. Build a Console App targeting .Net 6.0
  2. Using NuGet Package Manager install Microsoft.ML (2.0.1), Microsoft.ML.TensorFlow (2.0.1) and SciSharp.TensorFlow.Redist (2.11.4)
  3. Download the attached Zip and extract
  4. Call DNNLoader.LoadTensorFlowModel(<filePath>) passing the location of the extracted directory
  5. The exception Tensorflow.InvalidArgumentError: 'Node 'dense_2/bias:': Node name contains invalid characters' is thrown

**Expected ** The trained model to be loaded

Code Sample

using Microsoft.ML; using Microsoft.ML.Data; using Microsoft.ML.Transforms;

namespace DNNPrediction { internal static class DNNLoader { internal static void LoadTensorFlowModel(string modelPath) { MLContext mlContext = new MLContext();

        TensorFlowModel tensorFlowModel = mlContext.Model.LoadTensorFlowModel(modelPath);

        DataViewSchema schema = tensorFlowModel.GetModelSchema();
        Console.WriteLine(" =============== TensorFlow Model Schema =============== ");
        var featuresType = (VectorDataViewType)schema["Features"].Type;
        Console.WriteLine($"Name: Features, Type: {featuresType.ItemType.RawType}, Size: ({featuresType.Dimensions[0]})");
        var predictionType = (VectorDataViewType)schema["Prediction/Softmax"].Type;
        Console.WriteLine($"Name: Prediction/Softmax, Type: {predictionType.ItemType.RawType}, Size: ({predictionType.Dimensions[0]})");
    }
}

}

The trained model files are here

dnn.zip

TopCat73 avatar Jul 27 '23 10:07 TopCat73

as far i know ML.NET only support SciSharp.TensorFlow.Redist 2.3.1

moemura avatar Sep 15 '23 04:09 moemura

Unfortunately I'm facing exactly the same problem, and I cannot find any workaround. Any progress/feedback here?

GeertQonic avatar Jan 03 '24 14:01 GeertQonic