Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/machine-learning/deep-learning-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ ML.NET provides APIs to consume models in other formats like TensorFlow and ONNX

These APIs are powered by [TensorFlow.NET](https://github.com/SciSharp/TensorFlow.NET) and the [ONNX Runtime](https://onnxruntime.ai/).

> [!IMPORTANT]
> Only load models from trusted sources. Loading models from untrusted sources is a security risk.

#### TensorFlow

Comment thread
svick marked this conversation as resolved.
[TensorFlow](https://www.tensorflow.org/) is a deep learning framework with a rich ecosystem and a variety of pretrained models available in the [TensorFlow Hub](https://www.tensorflow.org/hub).
Expand Down Expand Up @@ -177,13 +180,13 @@ An inference pipeline using a pretrained ONNX model might look like the followin

```csharp
// Append ApplyOnnxModel transform to pipeline containing any preprocessing transforms
pipeline.Append((modelFile: modelLocation, outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput }, inputColumnNames: new[] { TinyYoloModelSettings.ModelInput })
pipeline = pipeline.Append(mlContext.Transforms.ApplyOnnxModel(modelFile: modelLocation, outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput }, inputColumnNames: new[] { TinyYoloModelSettings.ModelInput }));

// Create ML.NET model from pipeline
var model = pipeline.Fit(data);
Comment thread
svick marked this conversation as resolved.

// Use the model to make predictions
var predictions = pipeline.Fit(data).GetColumn<float[]>(TinyYoloModelSettings.ModelOutput);
var predictions = model.Transform(data).GetColumn<float[]>(TinyYoloModelSettings.ModelOutput);
```

To get started consuming pretrained ONNX models with ML.NET, see the [Object detection using ONNX in ML.NET](tutorials/object-detection-onnx.md) tutorial.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class HousingPrediction

Whether making a single or batch prediction, the prediction pipeline needs to be loaded into the application. This pipeline contains both the data preprocessing transformations and the trained model. The following code snippet loads the prediction pipeline from a file named `model.zip`.

> [!IMPORTANT]
> Only load models from trusted sources. Loading models from untrusted sources is a security risk.

```csharp
//Create MLContext
MLContext mlContext = new MLContext();
Expand Down
3 changes: 3 additions & 0 deletions docs/machine-learning/how-to-guides/retrain-model-ml-net.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ The following algorithms are retrainable in ML.NET:

## Load pretrained model

> [!IMPORTANT]
> Only load models from trusted sources. Loading models from untrusted sources is a security risk.

First, load the pretrained model into your application. To learn more about loading training pipelines and models, see [Save and load a trained model](save-load-machine-learning-models-ml-net.md).

```csharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ The following link provides more information if you want to learn more about [de

1. Then, add a new method called `Configure` to register the `PredictionEnginePool` service below the constructor.

> [!IMPORTANT]
> Only add models from trusted sources. Adding models from untrusted sources is a security risk.

Comment thread
svick marked this conversation as resolved.
[!code-csharp [ConfigureServices](~/machinelearning-samples/samples/csharp/end-to-end-apps/ScalableMLModelOnAzureFunction/SentimentAnalysisFunctionsApp/Startup.cs#L32-L36)]

At a high level, this code initializes the objects and services automatically for later use when requested by the application instead of having to manually do it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ The following link provides more information if you want to learn more about [de

Add the following code to your *Program.cs* file:

> [!IMPORTANT]
> Only add models from trusted sources. Adding models from untrusted sources is a security risk.

Comment thread
svick marked this conversation as resolved.
```csharp
builder.Services.AddPredictionEnginePool<ModelInput, ModelOutput>()
.FromFile(modelName: "SentimentAnalysisModel", filePath: "sentiment_model.zip", watchForChanges: true);
Expand Down
3 changes: 3 additions & 0 deletions docs/machine-learning/tutorials/image-classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ An ML.NET model pipeline is a chain of estimators. No execution happens during p

1. Add the estimator to load the TensorFlow model, and score it:

> [!IMPORTANT]
> Only load models from trusted sources. Loading models from untrusted sources is a security risk.

[!code-csharp[ScoreTensorFlowModel](./snippets/image-classification/csharp/Program.cs#ScoreTensorFlowModel)]

This stage in the pipeline loads the TensorFlow model into memory, then processes the vector of pixel values through the TensorFlow model network. Applying inputs to a deep learning model, and generating an output using the model, is referred to as **Scoring**. When using the model in its entirety, scoring makes an inference, or prediction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ With the empty `IDataView` created, the pipeline can be built to do the predicti
- **outputColumnNames** - A string array containing the names of all of the output column names, which can be found when analyzing the ONNX model in Netron.
- **inputColumnNames** - A string array containing the names of all of the input column name, which can also be found when analyzing the ONNX model in Netron.

> [!IMPORTANT]
> Only apply models from trusted sources. Applying models from untrusted sources is a security risk.

```csharp
.Append(context.Transforms.ApplyOnnxModel(outputColumnNames: new string[] { "detected_boxes", "detected_scores", "detected_classes" }, inputColumnNames: new string[] { "image_tensor" }, modelFile: "./Model/model.onnx"));
```
Expand Down
3 changes: 3 additions & 0 deletions docs/machine-learning/tutorials/object-detection-onnx.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ Just like with post-processing, there are a few steps in the scoring steps. To h
- [`ExtractPixels`](xref:Microsoft.ML.ImageEstimatorsCatalog.ExtractPixels%2A) changes the pixel representation of the image from a Bitmap to a numerical vector.
- [`ApplyOnnxModel`](xref:Microsoft.ML.OnnxCatalog.ApplyOnnxModel%2A) loads the ONNX model and uses it to score on the data provided.

> [!IMPORTANT]
> Only apply models from trusted sources. Applying models from untrusted sources is a security risk.

Define your pipeline in the `LoadModel` method below the `data` variable.

[!code-csharp [ScoringPipeline](~/machinelearning-samples/samples/csharp/getting-started/DeepLearning_ObjectDetection_Onnx/ObjectDetectionConsoleApp/OnnxModelScorer.cs#L55-L58)]
Expand Down
3 changes: 3 additions & 0 deletions docs/machine-learning/tutorials/text-classification-tf.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ The [MLContext class](xref:Microsoft.ML.MLContext) is a starting point for all M

## Load the pretrained TensorFlow model

> [!IMPORTANT]
> Only load models from trusted sources. Loading models from untrusted sources is a security risk.

1. Add code to load the TensorFlow model:

[!code-csharp[LoadTensorFlowModel](./snippets/text-classification-tf/csharp/Program.cs#LoadTensorFlowModel)]
Expand Down
Loading