【问题标题】:ML.Net PredictionEnginePool and Multiple InputML.Net PredictionEnginePool 和多输入
【发布时间】:2021-06-21 03:38:23
【问题描述】:

我环顾四周,似乎推荐的在 API 服务中实现预测引擎的方法是使用 PredictionEnginePool。我目前在 ConfigureServices() 中有这样的设置。

.ConfigureServices(services => {
     services.AddPredictionEnginePool<Input, Output>()
     .FromFile("TrainedModels/my_model.zip");
     })

然后像这样消费:

var predEngine = http.RequestServices.GetRequiredService<PredictionEnginePool<Input, Output>>();            
var prediction = predEngine.Predict(input);

现在我需要让我的端点使用数组数据输入。到目前为止,我所看到的是通过使用ML.Net Multiple Predictions 上的管道和 IDataview/transforms

IDataView predictions = predictionPipeline.Transform(inputData);

但是在我没有管道的情况下使用 PredictionEnginePool 时如何做到这一点? 任何想法表示赞赏,应该还有其他人经历过这个。谢谢!

【问题讨论】:

    标签: c# ml.net


    【解决方案1】:

    这是您的处理程序在使用 PredictionEnginePool 进行多个预测时的样子。

    static async Task PredictHandler(HttpContext http)
    {
        var predEnginePool = http.RequestServices.GetRequiredService<PredictionEnginePool<Input,Output>>();
    
        var input = await JsonSerializer.DeserializeAsync<IEnumerable<Input>>(http.Request.Body);
    
        var response = input.Select((x) => predEnginePool.Predict(x));
    
        await http.Response.WriteAsJsonAsync(response);
    }
    

    假设您的请求正文接受IEnumerable&lt;Input&gt;,请使用LINQ Select 操作从PredictionEnginePool 应用Predict 方法。在这种情况下,response 将是 IEnumerable&lt;Output&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-12
      • 2020-01-01
      • 2020-09-02
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多