The Prediction Api, from Custom Vision , does not respond the data back when passing byte data.

Shamine Dsouza 116 Reputation points
2021-02-18T06:59:55.813+00:00

Hi,

I recently published by training model for object identification, trained and tested it .
However , when I call the api , and pass the byte[] data for the image , it does not return or respond any data back.
It gets stuck on PostAsync(url, content) method.

I am refereeing to the same code available in.
https://video2.skills-academy.com/en-us/azure/cognitive-services/custom-vision-service/use-prediction-api.

Please help.

Azure AI Custom Vision
Azure AI Custom Vision
An Azure artificial intelligence service and end-to-end platform for applying computer vision to specific domains.
235 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,623 questions
0 comments No comments
{count} votes

Accepted answer
  1. Shamine Dsouza 116 Reputation points
    2021-02-21T13:49:45.367+00:00

    Solved it . With both Api and the SDK Code .

    The above error was due to iteration name had space in between . I replaced the project name with iteration Published name. It has to be copied from The performance page and Copy the label 'published as'.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. romungi-MSFT 43,691 Reputation points Microsoft Employee
    2021-02-18T09:59:21.863+00:00

    @Shamine Dsouza I just tried the tutorial with my project and it seems to work as expected.

    69501-image.png

    I am curious if you have used the complete prediction API for the image file from your project. This should be the second URL from the pop up when you click Prediction URL button and the key should also be available with the header value.


  2. Shamine Dsouza 116 Reputation points
    2021-02-20T05:50:14.573+00:00

    Can you help me with a sample sdk code , to retrieve the trained model and test it.
    Or any reference link

    0 comments No comments

  3. Shamine Dsouza 116 Reputation points
    2021-02-21T12:00:43.973+00:00

    Hi, I was able to find the code for SDK code and create a dummy aaplication . However I am getting an Error, and so I am unable to predict the object.

    Referring to the code in this
    https://video2.skills-academy.com/en-us/azure/cognitive-services/custom-vision-service/quickstarts/image-classification?tabs=visual-studio&pivots=programming-language-csharp

    I am getting an error on this line of Code :
    var result = predictionApi.DetectImage(project.Id, project.Name, stream);
    Error: Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.CustomVisionErrorException
    HResult=0x80131500
    Message=Operation returned an invalid status code 'NotFound'
    Source=<Cannot evaluate the exception source>
    StackTrace:
    <Cannot evaluate the exception stack trace>

    Since my model is already , I just used the test iteration part .

    CustomVisionTrainingClient TrainingApi = AuthenticateTraining(ENDPOINT, trainingKey);
    CustomVisionPredictionClient predictionApi = AuthenticatePrediction(ENDPOINT, predictionKey);

            //// Find the object detection domain  
            //var domains = TrainingApi.GetDomains();  
            //var objDetectionDomain = domains.FirstOrDefault(d => d.Type == "ObjectDetection");  
    
            var projects = TrainingApi.GetProjects();  
            var project = TrainingApi.GetProject(Guid.Parse(projects[0].Id));  
    
            TestIteration(predictionApi, project);  
    

    private void TestIteration(CustomVisionPredictionClient predictionApi, Project project)
    {

            var imageFile = Server.MapPath("~/" + imgPath);  
             
            using (var stream = File.OpenRead(imageFile))  
            {  
                ***var result = predictionApi.DetectImage(project.Id, project.Name, stream);***  
    
                lblResponse.Text  = result.Predictions;  
                
            }  
             
        }  
    
    0 comments No comments