Skip to content

ML.Net - The first dimension of paddings must be the rank of inputs[4,2] [1,1,320,320,3] #5364

Closed
@crazyoutlook

Description

@crazyoutlook

System information
OS version/distro: Windows 10 Pro
.NET Version (eg., dotnet --info): dotnet framework 4.7
Issue :
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 -TensorflowException: The first dimension of paddings must be the rank of inputs[4,2] [1,1,320,320,3] [[{{node conv1/pad_size}}]]
The same custom vision model works fine when consumed in Python code.

Source code / logs
Details:

Project Name : TransferLearningTF
Class name : program.cs
Method Name : GenerateModel

Code :

IEstimator pipeline = mlContext.Transforms.LoadImages(outputColumnName: "image_tensor", imageFolder: _imagesFolder, inputColumnName: nameof(ImageData.ImagePath))
.Append(mlContext.Transforms.ResizeImages(outputColumnName: "image_tensor", imageWidth: InceptionSettings.ImageWidth, imageHeight: InceptionSettings.ImageHeight, inputColumnName: "image_tensor"))
.Append(mlContext.Transforms.ExtractPixels(outputColumnName: "image_tensor"))
.Append(mlContext.Model.LoadTensorFlowModel(_inceptionTensorFlowModel)
.ScoreTensorFlowModel(outputColumnNames: new[] { "detected_boxes", "detected_scores", "detected_classes" }, inputColumnNames: new[] { "image_tensor" }, addBatchDimensionInput: true))
.AppendCacheCheckpoint(mlContext);

		IDataView trainingData = mlContext.Data.LoadFromTextFile<ImageData>(path: _trainTagsTsv, hasHeader: false);
        ITransformer model = pipeline.Fit(trainingData);
        IDataView testData = mlContext.Data.LoadFromTextFile<ImageData>(path: _testTagsTsv, hasHeader: false);
        IDataView predictions = model.Transform(testData);
        IEnumerable<ImagePrediction> imagePredictionData = mlContext.Data.CreateEnumerable<ImagePrediction>(predictions, true);

Exception Details :

TensorflowException: The first dimension of paddings must be the rank of inputs[4,2] [1,1,320,320,3]
[[{{node conv1/pad_size}}]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Priority of the issue for triage purpose: Needs to be fixed at some point.bugSomething isn't workingimageBugs related image datatype tasksneed infoThis issue needs more info before triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions