Closed
Description
openedon Apr 13, 2020
System information
- OS version/distro: Win10
- .NET Version (eg., dotnet --info): .NET Core 3.1
Issue
- What did you do? I have run TensorFlow scoring using mtcnn.pb model
- What happened? I got Tensorflow.TensorflowException: The second input must be a scalar, but it has shape [1,1]
[[Node: _clooppnet/while/add/y/_2 = Switch[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_clooppnet/while/add/y/_1, pnet/while/LoopCond/_135)]] - What did you expect? To get the bounding box, maybe probability and landmarks as well.
Source code / logs
Here is the mtcnn.pb model: mtcnn.zip
This is one of the outputs node (box):
class PredictedImageData
{
[ColumnName("box")]
[VectorType(1)]
public float[] BoundingBox { get; set; }
[ColumnName("landmarks")]
[VectorType(1)]
public float[] Landmarks { get; set; }
[ColumnName("prob")]
public float Probability { get; set; }
}
private struct ImageNetSettings
{
public const int imageHeight = 224;
public const int imageWidth = 224;
}
public class ImageNetData
{
public string ImagePath;
//[ImageType(ImageNetSettings.imageHeight, ImageNetSettings.imageWidth)]
//[VectorType(1)]
//[ColumnName("input")]
//public Bitmap Input { get; set; }
[VectorType(1)]
[ColumnName("min_size")]
public float[] MinSize;
[VectorType(1)]
[ColumnName("factor")]
public float[] Factor;
[VectorType(3)]
[ColumnName("thresholds")]
public float[] Thresholds;
}
static void Main(string[] args)
{
var mlContext = new MLContext(seed: 1);
var modelLocation = "mtcnn.pb";
var data = mlContext.Data.LoadFromEnumerable(new List<ImageNetData>());
var pipeline = mlContext
.Transforms.LoadImages(
outputColumnName: "input",
imageFolder: "",
inputColumnName: nameof(ImageNetData.ImagePath))
.Append(mlContext
.Transforms.ResizeImages(
outputColumnName: "input",
imageWidth: ImageNetSettings.imageWidth,
imageHeight: ImageNetSettings.imageHeight,
inputColumnName: "input"))
.Append(mlContext.Transforms.ExtractPixels(
outputColumnName: "input"))
.Append(mlContext.Model.LoadTensorFlowModel(modelLocation).ScoreTensorFlowModel(
inputColumnNames: new[] { "input", "thresholds", "min_size", "factor" },
//outputColumnNames: new[] { "box", "prob", "landmarks" },
outputColumnNames: new[] { "box" },
addBatchDimensionInput: true));
ITransformer model = pipeline.Fit(data);
var predictionEngine = mlContext.Model.CreatePredictionEngine<ImageNetData, PredictedImageData>(model);
var prediction = predictionEngine.Predict(new ImageNetData
{
ImagePath = "anastasia3.jpg",
//Input = (Bitmap)Image.FromFile("anastasia3.jpg"),
MinSize = new float[] { 40F },
Factor = new float[] { 0.709F },
Thresholds = new float[] { 0.6F, 0.7F, 0.7F }
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment