dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.02k stars 1.88k forks source link

Need a way to predict a batch of examples in one call to Tensorflow #3870

Closed marcmm closed 4 years ago

marcmm commented 5 years ago

System information

Issue

Source code / logs

Please paste or attach the code or logs or traces that would be helpful to diagnose the issue you are reporting.

najeeb-kazmi commented 4 years ago

@marcmm you can do this currently, see this sample.

https://github.com/dotnet/machinelearning/blob/71f0dc28939681198d99c2eb86e1ed326cc8c7d5/docs/samples/Microsoft.ML.Samples/Dynamic/TensorFlow/ImageClassification.cs#L37-L44

Note line 44 which does estimator.Transform(idv). idv can be an IDataView containing many examples. The call to Transform() would predict on all of them.

This other sample shows single predictions by creating a PredictionEngine. However, in place of line 123, you could simply do var batchPredictions = model.Transform(dataView), with dataView being an IDataView containing multiple examples. https://github.com/dotnet/machinelearning/blob/71f0dc28939681198d99c2eb86e1ed326cc8c7d5/docs/samples/Microsoft.ML.Samples/Dynamic/TensorFlow/TextClassification.cs#L63-L64 https://github.com/dotnet/machinelearning/blob/71f0dc28939681198d99c2eb86e1ed326cc8c7d5/docs/samples/Microsoft.ML.Samples/Dynamic/TensorFlow/TextClassification.cs#L99-L123