Skip to content

Commit d68cd12

Browse files
authored
Merge pull request #89455 from PatrickFarley/cusvis-subdomains
[cog serv] Cusvis subdomains
2 parents e751444 + 2e72526 commit d68cd12

11 files changed

+61
-113
lines changed

articles/cognitive-services/Custom-Vision-Service/csharp-tutorial-od.md

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,84 +37,58 @@ This Visual Studio project creates a new Custom Vision project named __My New Pr
3737

3838
## Understand the code
3939

40-
Open the _Program.cs_ file and inspect the code. Insert your subscription keys in the appropriate definitions in the **Main** method.
40+
Open the _Program.cs_ file and inspect the code. [Create environment variables](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account#configure-an-environment-variable-for-authentication) for your training and prediction keys named `CUSTOM_VISION_TRAINING_KEY` and `CUSTOM_VISION_PREDICTION_KEY`, respectively. The script will look for these.
4141

42-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?range=18-27)]
42+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_keys)]
4343

44-
The Endpoint parameter should point to the region where the Azure resource group containing the Custom Vision resources was created in. For this example, we assume the South Central US region and use:
44+
Also, get your Endpoint URL from the Settings page of the Custom Vision website. Save it to an environment variable called `CUSTOM_VISION_ENDPOINT`. The script saves a reference to it at the root of your class.
4545

46-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?range=14-14)]
46+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_endpoint)]
4747

4848
### Create a new Custom Vision Service project
4949

5050
This next bit of code creates an object detection project. The created project will show up on the [Custom Vision website](https://customvision.ai/) that you visited earlier. See the [CreateProject](https://docs.microsoft.com/dotnet/api/microsoft.azure.cognitiveservices.vision.customvision.training.customvisiontrainingclientextensions.createproject?view=azure-dotnet#Microsoft_Azure_CognitiveServices_Vision_CustomVision_Training_CustomVisionTrainingClientExtensions_CreateProject_Microsoft_Azure_CognitiveServices_Vision_CustomVision_Training_ICustomVisionTrainingClient_System_String_System_String_System_Nullable_System_Guid__System_String_System_Collections_Generic_IList_System_String__) method to specify other options when you create your project (explained in the [Build a detector](get-started-build-detector.md) web portal guide).
5151

52-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?range=29-35)]
52+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_create)]
53+
5354

5455
### Add tags to the project
5556

56-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?range=37-39)]
57+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_tags)]
5758

5859
### Upload and tag images
5960

6061
When you tag images in object detection projects, you need to specify the region of each tagged object using normalized coordinates. The following code associates each of the sample images with its tagged region.
6162

62-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?range=41-84)]
63+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_upload_regions)]
6364

6465
Then, this map of associations is used to upload each sample image with its region coordinates. You can upload up to 64 images in a single batch.
6566

66-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?range=86-104)]
67+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_upload)]
6768

6869
At this point, all of the sample images have been uploaded, and each has a tag (**fork** or **scissors**) and an associated pixel rectangle for that tag.
6970

7071
### Train the project
7172

7273
This code creates the first training iteration in the project.
7374

74-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?range=106-117)]
75+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_train)]
7576

7677
### Publish the current iteration
7778

7879
The name given to the published iteration can be used to send prediction requests. An iteration is not available in the prediction endpoint until it is published.
7980

80-
```csharp
81-
// The iteration is now trained. Publish it to the prediction end point.
82-
var publishedModelName = "treeClassModel";
83-
var predictionResourceId = "<target prediction resource ID>";
84-
trainingApi.PublishIteration(project.Id, iteration.Id, publishedModelName, predictionResourceId);
85-
Console.WriteLine("Done!\n");
86-
```
81+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_publish)]
8782

8883
### Create a prediction endpoint
8984

90-
```csharp
91-
// Create a prediction endpoint, passing in the obtained prediction key
92-
CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
93-
{
94-
ApiKey = predictionKey,
95-
Endpoint = SouthCentralUsEndpoint
96-
};
97-
```
85+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_prediction_endpoint)]
9886

9987
### Use the prediction endpoint
10088

10189
This part of the script loads the test image, queries the model endpoint, and outputs prediction data to the console.
10290

103-
```csharp
104-
// Make a prediction against the new project
105-
Console.WriteLine("Making a prediction:");
106-
var imageFile = Path.Combine("Images", "test", "test_image.jpg");
107-
using (var stream = File.OpenRead(imageFile))
108-
{
109-
var result = endpoint.DetectImage(project.Id, publishedModelName, stream);
110-
111-
// Loop over each prediction and write out the results
112-
foreach (var c in result.Predictions)
113-
{
114-
Console.WriteLine($"\t{c.TagName}: {c.Probability:P1} [ {c.BoundingBox.Left}, {c.BoundingBox.Top}, {c.BoundingBox.Width}, {c.BoundingBox.Height} ]");
115-
}
116-
}
117-
```
91+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ObjectDetection/Program.cs?name=snippet_prediction)]
11892

11993
## Run the application
12094

articles/cognitive-services/Custom-Vision-Service/csharp-tutorial.md

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,82 +36,49 @@ This Visual Studio project creates a new Custom Vision project named __My New Pr
3636

3737
## Understand the code
3838

39-
Open the _Program.cs_ file and inspect the code. Insert your subscription keys in the appropriate definitions in the **Main** method.
39+
Open the _Program.cs_ file and inspect the code. [Create environment variables](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account#configure-an-environment-variable-for-authentication) for your training and prediction keys named `CUSTOM_VISION_TRAINING_KEY` and `CUSTOM_VISION_PREDICTION_KEY`, respectively. The script will look for these.
4040

41-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?range=21-30)]
41+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_keys)]
4242

43-
The Endpoint parameter should point to the region where the Azure resource group containing the Custom Vision resources was created in. For this example, we assume the South Central US region and use:
43+
Also, get your Endpoint URL from the Settings page of the Custom Vision website. Save it to an environment variable called `CUSTOM_VISION_ENDPOINT`. The script saves a reference to it at the root of your class.
4444

45-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?range=14-14)]
45+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_endpoint)]
4646

4747
The following lines of code execute the primary functionality of the project.
4848

4949
### Create a new Custom Vision service project
5050

5151
The created project will show up on the [Custom Vision website](https://customvision.ai/) that you visited earlier. See the [CreateProject](https://docs.microsoft.com/dotnet/api/microsoft.azure.cognitiveservices.vision.customvision.training.customvisiontrainingclientextensions.createproject?view=azure-dotnet#Microsoft_Azure_CognitiveServices_Vision_CustomVision_Training_CustomVisionTrainingClientExtensions_CreateProject_Microsoft_Azure_CognitiveServices_Vision_CustomVision_Training_ICustomVisionTrainingClient_System_String_System_String_System_Nullable_System_Guid__System_String_System_Collections_Generic_IList_System_String__) method to specify other options when you create your project (explained in the [Build a classifier](getting-started-build-a-classifier.md) web portal guide).
5252

53-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?range=32-34)]
53+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_create)]
5454

5555
### Create tags in the project
5656

57-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?range=36-38)]
57+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_tags)]
5858

5959
### Upload and tag images
6060

6161
The images for this project are included. They are referenced in the **LoadImagesFromDisk** method in _Program.cs_. You can upload up to 64 images in a single batch.
6262

63-
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?range=40-55)]
63+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_upload)]
6464

6565
### Train the classifier and publish
6666

6767
This code creates the first iteration in the project and then publishes that iteration to the prediction endpoint. The name given to the published iteration can be used to send prediction requests. An iteration is not available in the prediction endpoint until it is published.
6868

69-
```csharp
70-
var iteration = trainingApi.TrainProject(project.Id);
71-
// The returned iteration will be in progress, and can be queried periodically to see when it has completed
72-
while (iteration.Status == "Training")
73-
{
74-
Thread.Sleep(1000);
75-
76-
// Re-query the iteration to get it's updated status
77-
iteration = trainingApi.GetIteration(project.Id, iteration.Id);
78-
}
79-
80-
// The iteration is now trained. Publish it to the prediction end point.
81-
var publishedModelName = "treeClassModel";
82-
var predictionResourceId = "<target prediction resource ID>";
83-
trainingApi.PublishIteration(project.Id, iteration.Id, publishedModelName, predictionResourceId);
84-
Console.WriteLine("Done!\n");
85-
```
69+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_train)]
8670

8771
### Set the prediction endpoint
8872

8973
The prediction endpoint is the reference that you can use to submit an image to the current model and get a classification prediction.
9074

91-
```csharp
92-
// Create a prediction endpoint, passing in obtained prediction key
93-
CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
94-
{
95-
ApiKey = predictionKey,
96-
Endpoint = SouthCentralUsEndpoint
97-
};
98-
```
75+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_prediction_endpoint)]
9976

10077
### Submit an image to the default prediction endpoint
10178

10279
In this script, the test image is loaded in the **LoadImagesFromDisk** method, and the model's prediction output is to be displayed in the console. The value of the publishedModelName variable should correspond to the "Published as" value found on the Custom Vision portal's **Performance** tab.
10380

104-
```csharp
105-
// Make a prediction against the new project
106-
Console.WriteLine("Making a prediction:");
107-
var result = endpoint.ClassifyImage(project.Id, publishedModelName, testImage);
108-
109-
// Loop over each prediction and write out the results
110-
foreach (var c in result.Predictions)
111-
{
112-
Console.WriteLine($"\t{c.TagName}: {c.Probability:P1}");
113-
}
114-
```
81+
[!code-csharp[](~/cognitive-services-dotnet-sdk-samples/CustomVision/ImageClassification/Program.cs?name=snippet_prediction)]
11582

11683
## Run the application
11784

articles/cognitive-services/Custom-Vision-Service/go-tutorial-object-detection.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Create a new file called *sample.go* in your preferred project directory.
4545

4646
### Create the Custom Vision service project
4747

48-
Add the following code to your script to create a new Custom Vision service project. Insert your subscription keys in the appropriate definitions. See the [CreateProject](https://docs.microsoft.com/java/api/com.microsoft.azure.cognitiveservices.vision.customvision.training.trainings.createproject?view=azure-java-stable#com_microsoft_azure_cognitiveservices_vision_customvision_training_Trainings_createProject_String_CreateProjectOptionalParameter_) method to specify other options when you create your project (explained in the [Build a detector](get-started-build-detector.md) web portal guide).
48+
Add the following code to your script to create a new Custom Vision service project. Insert your subscription keys in the appropriate definitions. Also, get your Endpoint URL from the Settings page of the Custom Vision website.
49+
50+
See the [CreateProject](https://docs.microsoft.com/java/api/com.microsoft.azure.cognitiveservices.vision.customvision.training.trainings.createproject?view=azure-java-stable#com_microsoft_azure_cognitiveservices_vision_customvision_training_Trainings_createProject_String_CreateProjectOptionalParameter_) method to specify other options when you create your project (explained in the [Build a detector](get-started-build-detector.md) web portal guide).
4951

5052
```go
5153
import(
@@ -64,7 +66,7 @@ var (
6466
training_key string = "<your training key>"
6567
prediction_key string = "<your prediction key>"
6668
prediction_resource_id = "<your prediction resource id>"
67-
endpoint string = "https://southcentralus.api.cognitive.microsoft.com"
69+
endpoint string = "<your endpoint URL>"
6870
project_name string = "Go Sample OD Project"
6971
iteration_publish_name = "detectModel"
7072
sampleDataDirectory = "<path to sample images>"

articles/cognitive-services/Custom-Vision-Service/go-tutorial.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Create a new file called *sample.go* in your preferred project directory.
4545

4646
### Create the Custom Vision service project
4747

48-
Add the following code to your script to create a new Custom Vision service project. Insert your subscription keys in the appropriate definitions. See the [CreateProject](https://docs.microsoft.com/java/api/com.microsoft.azure.cognitiveservices.vision.customvision.training.trainings.createproject?view=azure-java-stable#com_microsoft_azure_cognitiveservices_vision_customvision_training_Trainings_createProject_String_CreateProjectOptionalParameter_) method to specify other options when you create your project (explained in the [Build a classifier](getting-started-build-a-classifier.md) web portal guide).
48+
Add the following code to your script to create a new Custom Vision service project. Insert your subscription keys in the appropriate definitions. Also, get your Endpoint URL from the Settings page of the Custom Vision website.
49+
50+
See the [CreateProject](https://docs.microsoft.com/java/api/com.microsoft.azure.cognitiveservices.vision.customvision.training.trainings.createproject?view=azure-java-stable#com_microsoft_azure_cognitiveservices_vision_customvision_training_Trainings_createProject_String_CreateProjectOptionalParameter_) method to specify other options when you create your project (explained in the [Build a classifier](getting-started-build-a-classifier.md) web portal guide).
4951

5052
```go
5153
import(
@@ -64,7 +66,7 @@ var (
6466
training_key string = "<your training key>"
6567
prediction_key string = "<your prediction key>"
6668
prediction_resource_id = "<your prediction resource id>"
67-
endpoint string = "https://southcentralus.api.cognitive.microsoft.com"
69+
endpoint string = "<your endpoint URL>"
6870
project_name string = "Go Sample Project"
6971
iteration_publish_name = "classifyModel"
7072
sampleDataDirectory = "<path to sample images>"

0 commit comments

Comments
 (0)