0

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

IngoB
  • 2,552
  • 1
  • 20
  • 35

2 Answers2

2

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. :)

IngoB
  • 2,552
  • 1
  • 20
  • 35
-1

There's two items to address here.

Your particular "Bad Request"

Your example, specifically, has one or more of these problems that you haven't really included.

  1. The _modelName is malformed
  2. The imageData is not formatted properly
  3. Some configuration, likely of request headers, is missing or incorrect

That's about the most we can provide from the example you've given. But here's the other concern that will benefit you greatly in the future: "Bad Request" tells you a lot about what's happened.

More about "Bad Request" in general

If you look at ranges within HTTP status codes you'll notice a pattern in the "error" ranges.

  1. In 4xx the requester (you) did something wrong and you can correct it.
  2. In 5xx the responder did something wrong and you cannot correct it.

Beneath that:

  1. In 404 Not Found it seems the request was formed well but the responder cannot find what you've asked for
  2. In 401 Unauthorized you didn't provide any kind of identity
  3. In 403 Forbidden you did provide an identity but you're not allowed to perform this action

But in 400 Bad Request the responder couldn't validate your request as good input at all. That means you can look at the API documentation again, compare it with your implementation, and try again.

clarkitect
  • 1,720
  • 14
  • 23