diff --git a/docs/machine-learning/deep-learning-overview.md b/docs/machine-learning/deep-learning-overview.md index f26d17bca7469..a2a6c7d525352 100644 --- a/docs/machine-learning/deep-learning-overview.md +++ b/docs/machine-learning/deep-learning-overview.md @@ -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 [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). @@ -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); // Use the model to make predictions -var predictions = pipeline.Fit(data).GetColumn(TinyYoloModelSettings.ModelOutput); +var predictions = model.Transform(data).GetColumn(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. diff --git a/docs/machine-learning/how-to-guides/machine-learning-model-predictions-ml-net.md b/docs/machine-learning/how-to-guides/machine-learning-model-predictions-ml-net.md index 01ba6c41f861b..713f1e3edc8ef 100644 --- a/docs/machine-learning/how-to-guides/machine-learning-model-predictions-ml-net.md +++ b/docs/machine-learning/how-to-guides/machine-learning-model-predictions-ml-net.md @@ -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(); diff --git a/docs/machine-learning/how-to-guides/retrain-model-ml-net.md b/docs/machine-learning/how-to-guides/retrain-model-ml-net.md index 16c4ec18ab5e6..4ff2d329ce2fe 100644 --- a/docs/machine-learning/how-to-guides/retrain-model-ml-net.md +++ b/docs/machine-learning/how-to-guides/retrain-model-ml-net.md @@ -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 diff --git a/docs/machine-learning/how-to-guides/serve-model-serverless-azure-functions-ml-net.md b/docs/machine-learning/how-to-guides/serve-model-serverless-azure-functions-ml-net.md index 57dca84336479..5d98686039fb5 100644 --- a/docs/machine-learning/how-to-guides/serve-model-serverless-azure-functions-ml-net.md +++ b/docs/machine-learning/how-to-guides/serve-model-serverless-azure-functions-ml-net.md @@ -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. + [!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. diff --git a/docs/machine-learning/how-to-guides/serve-model-web-api-ml-net.md b/docs/machine-learning/how-to-guides/serve-model-web-api-ml-net.md index 6368ce8ff6344..d21bb71b29c4c 100644 --- a/docs/machine-learning/how-to-guides/serve-model-web-api-ml-net.md +++ b/docs/machine-learning/how-to-guides/serve-model-web-api-ml-net.md @@ -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. + ```csharp builder.Services.AddPredictionEnginePool() .FromFile(modelName: "SentimentAnalysisModel", filePath: "sentiment_model.zip", watchForChanges: true); diff --git a/docs/machine-learning/tutorials/image-classification.md b/docs/machine-learning/tutorials/image-classification.md index 3a4dbe52aa5d0..2874d1f692c63 100644 --- a/docs/machine-learning/tutorials/image-classification.md +++ b/docs/machine-learning/tutorials/image-classification.md @@ -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. diff --git a/docs/machine-learning/tutorials/object-detection-custom-vision-onnx.md b/docs/machine-learning/tutorials/object-detection-custom-vision-onnx.md index 202655a6478f5..d6858b2280c6a 100644 --- a/docs/machine-learning/tutorials/object-detection-custom-vision-onnx.md +++ b/docs/machine-learning/tutorials/object-detection-custom-vision-onnx.md @@ -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")); ``` diff --git a/docs/machine-learning/tutorials/object-detection-onnx.md b/docs/machine-learning/tutorials/object-detection-onnx.md index 74dc939b5f060..7276d9877b857 100644 --- a/docs/machine-learning/tutorials/object-detection-onnx.md +++ b/docs/machine-learning/tutorials/object-detection-onnx.md @@ -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)] diff --git a/docs/machine-learning/tutorials/text-classification-tf.md b/docs/machine-learning/tutorials/text-classification-tf.md index 487a24b16a707..e3d0baaf8b398 100644 --- a/docs/machine-learning/tutorials/text-classification-tf.md +++ b/docs/machine-learning/tutorials/text-classification-tf.md @@ -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)]