Skip to content

Commit 71113fb

Browse files
authored
Merge pull request #115310 from areddish/areddish/python-quickstart-update
Updates to match version 2.0.0 of custom vision SDK
2 parents 058a902 + 68a26b8 commit 71113fb

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

articles/cognitive-services/Custom-Vision-Service/includes/quickstarts/python-tutorial-od.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ See the [create_project](https://docs.microsoft.com/python/api/azure-cognitivese
4040
```Python
4141
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
4242
from azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateEntry, Region
43+
from msrest.authentication import ApiKeyCredentials
4344

4445
ENDPOINT = "<your API endpoint>"
4546

@@ -50,7 +51,8 @@ prediction_resource_id = "<your prediction resource id>"
5051

5152
publish_iteration_name = "detectModel"
5253

53-
trainer = CustomVisionTrainingClient(training_key, endpoint=ENDPOINT)
54+
credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
55+
trainer = CustomVisionTrainingClient(ENDPOINT, credentials)
5456

5557
# Find the object detection domain
5658
obj_detection_domain = next(domain for domain in trainer.get_domains() if domain.type == "ObjectDetection" and domain.name == "General")
@@ -188,10 +190,11 @@ To send an image to the prediction endpoint and retrieve the prediction, add the
188190

189191
```Python
190192
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
193+
from msrest.authentication import ApiKeyCredentials
191194

192195
# Now there is a trained endpoint that can be used to make a prediction
193-
194-
predictor = CustomVisionPredictionClient(prediction_key, endpoint=ENDPOINT)
196+
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
197+
predictor = CustomVisionPredictionClient(ENDPOINT, prediction_credentials)
195198

196199
# Open the sample image and get back the prediction results.
197200
with open(base_image_url + "images/Test/test_od_image.jpg", mode="rb") as test_data:

articles/cognitive-services/Custom-Vision-Service/includes/quickstarts/python-tutorial.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ See the [create_project](https://docs.microsoft.com/python/api/azure-cognitivese
3838
```Python
3939
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
4040
from azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateEntry
41+
from msrest.authentication import ApiKeyCredentials
4142

4243
ENDPOINT = "<your API endpoint>"
4344

@@ -48,7 +49,8 @@ prediction_resource_id = "<your prediction resource id>"
4849

4950
publish_iteration_name = "classifyModel"
5051

51-
trainer = CustomVisionTrainingClient(training_key, endpoint=ENDPOINT)
52+
credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
53+
trainer = CustomVisionTrainingClient(ENDPOINT, credentials)
5254

5355
# Create a new project
5456
print ("Creating project...")
@@ -122,9 +124,11 @@ To send an image to the prediction endpoint and retrieve the prediction, add the
122124

123125
```python
124126
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
127+
from msrest.authentication import ApiKeyCredentials
125128

126129
# Now there is a trained endpoint that can be used to make a prediction
127-
predictor = CustomVisionPredictionClient(prediction_key, endpoint=ENDPOINT)
130+
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
131+
predictor = CustomVisionPredictionClient(ENDPOINT, prediction_credentials)
128132

129133
with open(base_image_url + "images/Test/test_image.jpg", "rb") as image_contents:
130134
results = predictor.classify_image(

0 commit comments

Comments
 (0)