dotnet / dotnet/machinelearning

Tensorflow.InvalidArgumentError: Node name contains invalid characters

Open
#6,778 2 comments 0 reactions 0 assignees View on GitHub
area-TensorFlow untriaged
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

- 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() 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](https://github.com/dotnet/machinelearning/files/12181963/dnn.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.