Search code examples
c#azure-cognitive-servicesmicrosoft-custom-vision

CustomVision API returns “Operation returned an invalid status code: 'Bad Request'”


I get this error when using the CustomVisionPredictionClient like so:

var predictionApi = new CustomVisionPredictionClient()
{
    ApiKey = _predictionKey,
    Endpoint = "https://westeurope.api.cognitive.microsoft.com"
};
var result = await predictionApi.ClassifyImageAsync(project.Id, _modelName, imageData);
  • The project/project id is retrieved via the training API, on which I can call GetProjects() without a problem. It should be correct, if I change it to something wrong I get a "not found" exception.
  • _modelName is the published name of the iteration ("xxxRecognition", see screenshot below), it should also be correct, when I change it I get "not found".
  • imageData is just a FileStream from a PNG image.

enter image description here


Solution

  • The problem was that I created an "Object Detection" type project and tried to use it with ClassifyImage() which has to be used with "Classification" type projects. So I have to use DetectImage() instead. :)