Azure-Samples / Azure-Samples/cognitive-services-quickstart-code

CustomVisionQuickstart.py uses wrong endpoint for predictor client config

Ouverte
#295 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
Jupyter Notebook
Étoiles
389
Forks
556
Merge moyen
3 j 12 h
PR mergées (30 j)
1

Description

> Please provide us with the following information:
> ---------------------------------------------------------------

### This issue is for a: (mark with an `x`)
```
- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
```

### Minimal steps to reproduce
>Run "cognitive-services-quickstart-code/python/CustomVision/ObjectDetection/CustomVisionQuickstart.py" with following info:
```
ENDPOINT = "TRAINING_RESOURCE_ENDPOINT"
training_key = "TRAINING_RESOURCE_API_KEY"
prediction_key = "PREDICTION_API_KEY"
prediction_resource_id = "PREDICTION_RESOURCE_ID"
```

## Any log messages given by the failure
```
CustomVisionErrorException Traceback (most recent call last)
Input In [29], in
1 with open(os.path.join (base_image_location, "test", "test_image.jpg"), mode="rb") as test_data:
----> 2 results = predictor.detect_image(project.id, publish_iteration_name, test_data)

File c:\...\venv\lib\site-packages\azure\cognitiveservices\vision\customvision\prediction\operations\_custom_vision_prediction_client_operations.py:358, in CustomVisionPredictionClientOperationsMixin.detect_image(self, project_id, published_name, image_data, application, custom_headers, raw, **operation_config)
355 response = self._client.send(request, stream=False, **operation_config)
357 if response.status_code not in [200]:
--> 358 raise models.CustomVisionErrorException(self._deserialize, response)
360 deserialized = None
361 if response.status_code == 200:

CustomVisionErrorException: Operation returned an invalid status code 'Unauthorized'
```

### Expected/desired behavior
> Returned results

### OS and Version?
> Windows 11 Enterprise

### Versions
>21H2

### Mention any other details that might be useful
Fixed by changing the following:
```
TRAINING_ENDPOINT = "TRAINING_RESOURCE_ENDPOINT"
training_key = "TRAINING_RESOURCE_API_KEY"
PREDICTION_ENDPOINT = "PREDICTION_RESOURCE_ENDPOINT"
prediction_key = "PREDICTION_API_KEY"
prediction_resource_id = "PREDICTION_RESOURCE_ID"

credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
trainer = CustomVisionTrainingClient(TRAINING_ENDPOINT, credentials)
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
predictor = CustomVisionPredictionClient(PREDICTION_ENDPOINT, prediction_credentials)
```

Be sure to update docs if this is indeed an issue:
- https://docs.microsoft.com/en-us/azure/cognitive-services/Custom-Vision-Service/quickstarts/image-classification?tabs=visual-studio&pivots=programming-language-python

- https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/quickstarts/object-detection?tabs=visual-studio&pivots=programming-language-python
> ---------------------------------------------------------------

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Open cognitive-services-quickstart-code/python/CustomVision/ObjectDetection/CustomVisionQuickstart.py and compare its predictor client configuration with the separate prediction endpoint and key shown in the issue. Run the object-detection quickstart with the listed resource values and confirm that detection returns results instead of Unauthorized. Check the linked image-classification and object-detection documentation for matching configuration guidance.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
api
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.