static void Main(string[] args)
{
var mlContext = new MLContext();
var tensorFlowModel = mlContext.Model.LoadTensorFlowModel(@"raw_model.pb");
//var schema = tensorFlowModel.GetModelSchema();
var testdata = mlContext.Data.LoadFromEnumerable(new List<TensorData>());
var pipeline = tensorFlowModel.ScoreTensorFlowModel(
new[] { "dense_8/BiasAdd" }, new[] { "dense_6_input" }, addBatchDimensionInput:false);
var model = pipeline.Fit(testdata);
var predictionFunction = mlContext.Model.CreatePredictionEngine<TensorData, OutputScores>(model);
TensorData inputData = new TensorData {
input = new float[] {
0.123289999999999f,
0f,
10.0099999999999f,
0f,
0.547f,
5.913f,
92.9f ,
2.3534f,
6f,
432f,
17.8f,
394.949999999999f,
16.21f
}
};
OutputScores prediction = predictionFunction.Predict(inputData);
Console.WriteLine($"**********************************************************************");
Console.WriteLine($"Predicted price: {prediction.Output[0]}\t actual price: 7.2");
Console.WriteLine($"**********************************************************************");
//IDataView predictions = pipeline.Transform(data);
}
raw_model.pb是TensorFlow训练好的模型,TensorData是想要预测的值。模型输入参数13个,输出参数1个。
数据的构造如下:
public class TensorData
{
[ColumnName("dense_6_input")]
[LoadColumn(0, 13)]
[VectorType(13)]
public float[] input { get; set; }
}
class OutputScores
{
[ColumnName("dense_8/BiasAdd")]
[VectorType(1)]
public float[] Output { get; set; }
}
现在程序运行没有error,但是预测结果却相差很大,实际值为7.2,而预测出的值却为-50,而这个模型在python里预测的结果是没有问题的。
在官方的网页中,有TensorFlow训练好的分类模型拿来再训练和预测的例子,但是回归问题却找不到例子。
请问是哪部分代码写的不对呢?