dotnet / dotnet/machinelearning
ResNet101 [ShapeInferenceError] Attribute pads has incorrect size
- Dominant language
- C#
- Stars
- 9.4k
- Forks
- 2k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 11
Description
I am using ML.NET in C# to extract features for a reverse image search. It is based on the code sample from Microsoft's documentation at the following page: [https://learn.microsoft.com/en-us/dotnet/api/microsoft.ml.onnxcatalog.dnnfeaturizeimage?view=ml-dotnet#microsoft-ml-onnxcatalog-dnnfeaturizeimage(microsoft-ml-transformscatalog-system-string-system-func((microsoft-ml-transforms-onnx-dnnimagefeaturizerinput-microsoft-ml-data-estimatorchain((microsoft-ml-transforms-columncopyingtransformer))))-system-string)](url)
I have been successful at extracting features with ResNet18, TensorFlow, TensorFlowInceptionV3, and ONNX TinyYolo2.
**Describe the bug**
I get the following error when trying to use ResNet50 and ResNet101.
**ResNet50**
> System.InvalidOperationException: 'Error initializing model :Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:Fail] Load model from C:\Users\myname\source\repos\ReverseImageSearch\ReverseImageSearch\bin\Debug\net7.0\DnnImageModels\ResNet50Onnx\ResNet50.onnx failed:Node (Pooling1096) Op (AveragePool) [ShapeInferenceError] Attribute pads has incorrect size
**ResNet101**
> System.InvalidOperationException: 'Error initializing model :Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:Fail] Load model from C:\Users\myname\source\repos\ReverseImageSearch\ReverseImageSearch\bin\Debug\net7.0\DnnImageModels\ResNet101Onnx\ResNet101.onnx failed:Node (Pooling2286) Op (AveragePool) [ShapeInferenceError] Attribute pads has incorrect size
This is similar to the "**Closed**" issue at the following link [https://github.com/dotnet/machinelearning/issues/4075](url)
Here is the function
```
public static float[] GenerateImageFeaturesResNet101(string ImagePath)
{
var myFileName = System.IO.Path.GetFileName(ImagePath);
// Create a new ML context, for ML.NET operations. It can be used for
// exception tracking and logging, as well as the source of randomness.
var mlContext = new MLContext();
//
var myImageNetData = new List
{
new ImageNetData {ImagePath = ImagePath, Label = myFileName}
};
var data = mlContext.Data.LoadFromEnumerable(myImageNetData);
var imagesFolder = Path.GetDirectoryName(ImagePath);
// Image loading pipeline.
//
var pipeline = mlContext.Transforms.LoadImages(outputColumnName: "ImageObject", imagesFolder, inputColumnName: "ImagePath")
.Append(mlContext.Transforms.ResizeImages(outputColumnName: "ImageObjectResized", imageWidth:
224, imageHeight: 224, inputColumnName: "ImageObject"))
.Append(mlContext.Transforms.ExtractPixels(outputColumnName: "Pixels", inputColumnName: "ImageObjectResized"))
.Append(mlContext.Transforms.DnnFeaturizeImage(outputColumnName: "FeaturizedImage",
m => m.ModelSelector.ResNet101(mlContext, m.OutputColumn, m.InputColumn), inputColumnName: "Pixels"));
var transformedData = pipeline.Fit(data).Transform(data);
//Extractor image features
var FeaturizedImageValues = transformedData.GetColumn("FeaturizedImage").ToArray();
return FeaturizedImageValues[0];
}
```
**System Information**
- OS & Version:Windows 10
- ML.NET Version: 2.0.1
- .NET Version: .NET 7.0
- microsoft.ml.dnnimagefeaturizer.resnet101 (0.20.1)
- microsoft.ml.dnnimagefeaturizer.resnet50 (0.20.1)
- microsoft.ml.dnnimagefeaturizer.resnet18 (0.20.1)
Contributor guide
Assessment
This issue has not been assessed yet.