Skip to content

Commit fd04bc8

Browse files
committed
Converted e2e with tool
1 parent bc7156a commit fd04bc8

File tree

387 files changed

+205875
-1741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

387 files changed

+205875
-1741
lines changed

samples/visualbasic/end-to-end-apps/AnomalyDetection-Sales/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| ML.NET version | API type | Status | App Type | Data type | Scenario | ML Task | Algorithms |
44
|----------------|-------------------|-------------------------------|-------------|-----------|---------------------|---------------------------|-----------------------------|
5-
| v1.1.0 | Dynamic API | Up-to-date | WinForms app | .csv files | Spike and Change Point Detection of Product Sales | Anomaly Detection | IID Spike Detection and IID Change point Detection |
5+
| v1.3.1 | Dynamic API | Up-to-date | WinForms app | .csv files | Spike and Change Point Detection of Product Sales | Anomaly Detection | IID Spike Detection and IID Change point Detection |
66

77
![Alt Text](./SpikeDetectionE2EApp/SpikeDetection.WinForms/images/productsales.gif)
88

@@ -29,7 +29,7 @@ Note: This app is written in .NET Framework, so you must manually restore the nu
2929
* Uses [IidSpikeDetector](https://docs.microsoft.com/dotnet/api/microsoft.ml.transforms.timeseries.iidspikedetector?view=ml-dotnet) and [IidChangePointDetector](https://docs.microsoft.com/dotnet/api/microsoft.ml.transforms.timeseries.iidchangepointdetector?view=ml-dotnet).
3030

3131
## Dataset
32-
We have created sample dataset for Product sales. The dataset `product-sales.csv` can be found [here](./Data/product-sales.csv)
32+
We have created sample dataset for Product sales. The dataset `product-sales.csv` can be found [here](./SpikeDetectionE2EApp/Data/product-sales.csv)
3333

3434
Format of **Product Sales DataSet** looks like below.
3535

samples/visualbasic/end-to-end-apps/AnomalyDetection-Sales/SpikeDetectionE2EApp/SpikeDetection.ModelTrainer/SpikeDetectionModelTrainer.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
</ItemGroup>
1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.ML" Version="$(MicrosoftMLVersion)" />
21-
<PackageReference Include="Microsoft.ML.TimeSeries" Version="$(MicrosoftMLPreviewVersion)" />
21+
<PackageReference Include="Microsoft.ML.TimeSeries" Version="$(MicrosoftMLVersion)" />
2222
</ItemGroup>
2323
</Project>

samples/visualbasic/end-to-end-apps/AnomalyDetection-Sales/SpikeDetectionE2EApp/SpikeDetection.WinForms/SpikeDetection.WinForms.vbproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@
126126
</ItemGroup>
127127
<ItemGroup>
128128
<PackageReference Include="Microsoft.ML">
129-
<Version>1.0.0-preview</Version>
129+
<Version>$(MicrosoftMLVersion)</Version>
130130
</PackageReference>
131131
<PackageReference Include="Microsoft.ML.CpuMath">
132-
<Version>1.0.0-preview</Version>
132+
<Version>$(MicrosoftMLVersion)</Version>
133133
</PackageReference>
134134
<PackageReference Include="Microsoft.ML.Mkl.Redist">
135-
<Version>1.0.0-preview</Version>
135+
<Version>$(MicrosoftMLVersion)</Version>
136136
</PackageReference>
137137
<PackageReference Include="Microsoft.ML.TimeSeries">
138-
<Version>0.12.0-preview</Version>
138+
<Version>$(MicrosoftMLVersion)</Version>
139139
</PackageReference>
140140
<PackageReference Include="Newtonsoft.Json">
141141
<Version>10.0.3</Version>

samples/visualbasic/end-to-end-apps/DeepLearning_ImageClassification_TensorFlow/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
| ML.NET version | API type | Status | App Type | Data type | Scenario | ML Task | Algorithms |
44
|----------------|-------------------|-------------------------------|-------------|-----------|---------------------|---------------------------|-----------------------------|
5-
| v1.1.0 | Dynamic API | up-to-date | Console app | Images and text labels | Images classification | TensorFlow model | DeepLearning model |
5+
| v1.3.1 | Dynamic API | up-to-date | Console app | Images and text labels | Images classification | TensorFlow model | DeepLearning model |
66

77

88
## Problem
99
The problem is how to run/score a TensorFlow model in a web app/service while using in-memory images.
1010

11-
## Solution:
11+
## Solution
1212
The model (`model.pb`) is trained using TensorFlow as disscussed in the blogpost [Run with ML.NET C# code a TensorFlow model exported from Azure Cognitive Services Custom Vision](https://devblogs.microsoft.com/cesardelatorre/run-with-ml-net-c-code-a-tensorflow-model-exported-from-azure-cognitive-services-custom-vision/).
1313

14-
see the below architecture that shows how to run/score TensorFlow model in ASP.NET Core Razor web app/service
14+
See the below architecture that shows how to run/score TensorFlow model in ASP.NET Core Razor web app/service:
1515

1616
![](docs/scenario-architecture.png)
1717

1818

19-
The difference between [getting started sample](https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/getting-started/DeepLearning_ImageClassification_TensorFlow) and this end-to-end sample is that the images are loaded from **file** in getting started sample where as the images are loaded from **in-memory** in this end-to-end sample.
19+
The difference between the [getting started sample](https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/getting-started/DeepLearning_ImageClassification_TensorFlow) and this end-to-end sample is that the images are loaded from **file** in getting started sample whereas the images are loaded from **in-memory** in this end-to-end sample.
2020

2121
**Note:** this sample is trained using Custom images and it predicts the only specific images that are in [TestImages](./TestImages) Folder.
22+
23+
## Fine-Tuning for Your Custom Model
24+
25+
If you are using a custom trained TensorFlow model and getting low scores, you may need to [resize your input images](https://lutzroeder.github.io/netron/) and fine-tune some of the values in the [ImageSettings struct](https://github.com/dotnet/machinelearning-samples/blob/aaa490461b3d313d1dcd828eaf0bf4ced6609a16/samples/csharp/end-to-end-apps/DeepLearning_ImageClassification_TensorFlow/TensorFlowImageClassification/ML/TensorFlowModelConfigurator.cs#L22), such as the image size (imageHeight and imageWidth) and offset (mean). As you adjust these values, take note of how they affect scoring.
26+
27+
You can review the [Run with ML.NET C# code a TensorFlow model exported from Azure Cognitive Services Custom Vision
28+
](https://devblogs.microsoft.com/cesardelatorre/run-with-ml-net-c-code-a-tensorflow-model-exported-from-azure-cognitive-services-custom-vision/) blogpost if you have any questions about meeting the needs of your model to get accurate predictions.

samples/visualbasic/end-to-end-apps/DeepLearning_ImageClassification_TensorFlow/TensorFlowImageClassification/Controllers/ImageClassificationController.vb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ Namespace TensorFlowImageClassification.Controllers
9090
'Set a single label as predicted or even none if probabilities were lower than 70%
9191
Dim imageBestLabelPrediction = New ImagePredictedLabelWithProbability With {.ImageId = imageInputData.GetHashCode().ToString()}
9292

93-
With GetBestLabel(labels, probabilities)
94-
imageBestLabelPrediction.PredictedLabel = .Item1
95-
imageBestLabelPrediction.Probability = .Item2
96-
End With
93+
'INSTANT VB TODO TASK: VB has no equivalent to the C# deconstruction assignments:
94+
(imageBestLabelPrediction.PredictedLabel, imageBestLabelPrediction.Probability) = GetBestLabel(labels, probabilities)
9795

98-
Return imageBestLabelPrediction
96+
Return imageBestLabelPrediction
9997
End Function
10098

10199
Private Function GetBestLabel(labels() As String, probs() As Single) As (String, Single)
@@ -124,7 +122,7 @@ Namespace TensorFlowImageClassification.Controllers
124122
' GET api/ImageClassification
125123
<HttpGet>
126124
Public Function [Get]() As ActionResult(Of IEnumerable(Of String))
127-
Return New ActionResult(Of IEnumerable(Of String))({"ACK Heart beat 1", "ACK Heart beat 2"})
128-
End Function
125+
Return New String() { "ACK Heart beat 1", "ACK Heart beat 2" }
126+
End Function
129127
End Class
130128
End Namespace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Imports Microsoft.Extensions.ML
2+
Imports Microsoft.Extensions.Primitives
3+
Imports Microsoft.ML
4+
Imports System.Threading
5+
6+
Namespace TensorFlowImageClassification.ML
7+
Public Class InMemoryModelLoader
8+
Inherits ModelLoader
9+
10+
Private ReadOnly _model As ITransformer
11+
12+
Public Sub New(model As ITransformer)
13+
_model = model
14+
End Sub
15+
16+
Public Overrides Function GetModel() As ITransformer
17+
Return _model
18+
End Function
19+
20+
Public Overrides Function GetReloadToken() As IChangeToken
21+
Return New CancellationChangeToken(CancellationToken.None)
22+
End Function
23+
End Class
24+
End Namespace

samples/visualbasic/end-to-end-apps/DeepLearning_ImageClassification_TensorFlow/TensorFlowImageClassification/ML/TensorFlowModelConfigurator.vb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
Imports Microsoft.ML
2-
Imports System
32
Imports System.Collections.Generic
4-
Imports System.IO
53
Imports System.Linq
6-
Imports System.Threading.Tasks
74
Imports TensorFlowImageClassification.ML.DataModels
85

96
Namespace TensorFlowImageClassification.ML
107
Public Class TensorFlowModelConfigurator
118
Private ReadOnly _mlContext As MLContext
12-
Private ReadOnly _mlModel As ITransformer
9+
10+
Public ReadOnly Property Model As ITransformer
1311

1412
Public Sub New(tensorFlowModelFilePath As String)
1513
_mlContext = New MLContext
1614

1715
' Model creation and pipeline definition for images needs to run just once, so calling it from the constructor:
18-
_mlModel = SetupMlnetModel(tensorFlowModelFilePath)
16+
Model = SetupMlnetModel(tensorFlowModelFilePath)
1917
End Sub
2018

2119
Public Structure ImageSettings
@@ -50,10 +48,5 @@ Namespace TensorFlowImageClassification.ML
5048
Dim dv = _mlContext.Data.LoadFromEnumerable(Of ImageInputData)(list)
5149
Return dv
5250
End Function
53-
54-
Public Sub SaveMLNetModel(mlnetModelFilePath As String)
55-
' Save/persist the model to a .ZIP file to be loaded by the PredictionEnginePool
56-
_mlContext.Model.Save(_mlModel, Nothing, mlnetModelFilePath)
57-
End Sub
5851
End Class
5952
End Namespace

0 commit comments

Comments
 (0)