Giter Club home page Giter Club logo

cognitive-services-dotnet-sdk-samples's Introduction

page_type languages products name description urlFragment
sample
csharp
powershell
azure
C# Samples for Cognitive Services
This repo provides C# samples for the Cognitive Services Nuget Packages.
cognitive-services-dotnet-sdk-samples

Samples for Cognitive Services Nuget Packages

This repo provides C# samples for the Cognitive Services Nuget Packages. If you are interetsed in running a specific example, you can navigate to the corresponding subfolder and check out the individual Readme.

If you are looking for REST API samples in multiple languages, you can navigate here.

Features

C# samples showing use of nuget packages for the Cognitive Services. Idea behind these samples is to showcase 1) how to utilize nuget packages and 2) best practices while handling data for/from these APIs.

Getting Started

Get more information on Cognitive Services offerings from here. This should provide you information on various APIs along with their demos and documentation.

Prerequisites

All samples in this folder require:

Resources

cognitive-services-dotnet-sdk-samples's People

Contributors

aahill avatar areddish avatar ashku-ms avatar assafi avatar attrib75 avatar baon-ms avatar davidlicig avatar diberry avatar harishkrishnav avatar lebronj avatar microsoftopensource avatar mikedodaro avatar mohabghanem avatar moreover0 avatar msftgits avatar patrickfarley avatar potapy4 avatar q3blend avatar ram-msft avatar ronak25 avatar sahithikkss avatar sanjeev3 avatar shakao avatar sssahithikk avatar stefanvalianu avatar sudhansu88 avatar supernova-eng avatar v-jaswel avatar wiazur avatar yangyuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cognitive-services-dotnet-sdk-samples's Issues

Unable to retrieve result even after changing API Key

Unable to retrieve result from API

This issue is for a: (mark with an x)

- [ x ] bug report 
- [ x ] documentation issue or request

Minimal steps to reproduce

Change key and run it.

Any log messages given by the failure

One or more errors occurred. (Operation returned an invalid status code 'Unauthorized')

at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at ComputerVisionSample.Program.Main(String[] args) in C:\Users\mehta\Downloads\cognitive-services-dotnet-sdk-samples-master\cognitive-services-dotnet-sdk-samples-master\ComputerVision\Program.cs:line 24

Expected/desired behavior

Should connect to API

OS and Version?

Windows 10.

Versions

1.0.1-Preview

Ctrl + C in BingSearchv7 SDK samples hangs cmd window

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

When running either the BingAllSearch solution or any of the standalone ones, the instruction to use Ctrl + C to end things just hangs the command window

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 10

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

How do you specify the region endpoint in the bing-image-search-quickstart-csharp.cs code?

#25 specifies that you need to change region endpoint, which I know I need to do, but can't find how, and it doesn't say how in that issue either. What statement or parameter does one have to add to this code in order to specify the region? (this code only appears to demonstrate how it can be done in the default region, with no indication of how to do it on other regions. Can't find a single reference to this syntax anywhere).

'NotFoundIteration' Error when Calling DetectImage() for Object detection 'CustomVisionPredictionClient'

Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.CustomVisionErrorException: 'Operation returned an invalid status code 'NotFound''
Error : Detail
| Body | {Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.CustomVisionError} | Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.CustomVisionError
  | Code | "NotFoundIteration" | string
  | Message | "Invalid iteration" | string

Above is the error , I am getting when running to test the prediction model.
Error is returned on this line of code
var result = predictionApi.DetectImage(project.Id, lstIteration[0].Name, stream);

Sample Code :

private void TestIteration(CustomVisionPredictionClient predictionApi, Project project, IList lstIteration)
{
var imageFile = Server.MapPath("~/" + imgPath);
using (var stream = File.OpenRead(imageFile))
{
var result = predictionApi.DetectImage(project.Id, lstIteration[0].Name, stream);
foreach (var c in result.Predictions)
{
Console.WriteLine($"\t{c.TagName}: {c.Probability:P1} [ {c.BoundingBox.Left}, {c.BoundingBox.Top}, {c.BoundingBox.Width}, {c.BoundingBox.Height} ]");
}
}
}

Exception retrieving examples from LUIS with Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.LUISAuthoringClient

Hi, Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.LUISAuthoringClient.Examples.ListAsync
fails when try to retrieve data

When I try to get the list of LUIS examples, it throws an exception wher indicates that the id it tries to return is greater than int32, when checking the LabeledUtterance and LabelExampleResponse class I see that the id is indeed an int32?

on the image can see that try ot cast 4750297111 as Int32 and throws the exception

imagen

imagen

imagen

thanks for your help

[TextModerator] Resource Not Found

Please use [API Name] Brief description as title.

API Name (Kind)

TextModerator

Issue Description

I have Azure Subscription and I created the cognitive service, and from a c# console, I'm trying to test the TextModerator project.

When this line is called:

var screenResult =
                        client.TextModeration.ScreenText("text/plain", new MemoryStream(Encoding.UTF8.GetBytes(text)), "eng", true, true, null, true);

I got the following message:

Microsoft.CognitiveServices.ContentModerator.Models.APIErrorException : 'Operation returned an invalid status code 'NotFound''

Any Idea?

Saad

[Content Moderator] Can not trun off PII using SDK for text moderation

Please use [API Name] Brief description as title.

API Name (Kind)

TextModeration , ScreenText

Issue Description

When using the ScreenText from TextModeration class sending the request with PII flag to false, the response still contains the PII section in the JSON.
E.g:

var screenResult = client.TextModeration.ScreenText("text/plain", stream, "eng", false, false, null, true);

Visual Search SDK sample has exceptions/errors

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

In both the BingAllSearch solution ("VisualSearch" sample) and the BingVisualSearch solution, choosing an item that submits an image binary returns an error that […]\bin\Debug\netcoreapp2.0\TestImages\image.jpg cannot be found.

Also, in the same two solutions, choosing an item that sends an image URL or image insights token fails with an “Operation returned an invalid status code 'Unauthorized'” exception even though I'm using a BingSearchv7 app key.

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 10

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Docker support, container doesn't want to start

Hi,

I trained a model in Custom vision. I exported this model to support Docker. I build an image a start a container.

But the container exited. After I attach to the container I see this error:

File "/usr/local/lib/python3.5/site-packages/tensorflow/python/framework/importer.py", line 541, in import_graph_def
raise ValueError('No op named %s in defined operations.' % node.op)
ValueError: No op named LeakyRelu in defined operations.

This looks like Tensorflow exception, but I am not able to resolve it.

CustomVision/ObjectDetection throws

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

var project = trainingApi.CreateProject("My New Project", null, objDetectionDomain.Id);

throws: 'Forbidden'

Replace objDetectionDomain.Id with null and project creation is successful but the returned BoundingBox's are null. Prediction is valid.

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 10

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

CognitiveServices LUIS Authoring unable to deserialize response

API Name (Kind)

LUIS Authoring issue

Issue Description

Hi,

I get an "Unable to deserialize the response." error when calling the following ListAsync method.
var examples = await client.Examples.ListAsync(appId, app.ActiveVersion);
I am able to get intents and app details but not examples, this is the inner exception message:
' Message "JSON integer 2293959864 is too large or small for an Int32. Path '[0].id', line 1, position 17." string'

I am using version 3.1.0-preview.1 as mentioned in the documentation (https://docs.microsoft.com/en-us/azure/cognitive-services/luis/client-libraries-rest-api?tabs=windows&pivots=programming-language-csharp#add-example-utterance-to-intent)

Thanks.

Example in README.MD doesn't compile

The README states:

var client = new LUISRuntimeClient(new Uri([EndPointURL])`

But the two signatures available are:

public LUISRuntimeClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers);
public LUISRuntimeClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers);

Neither accept a URI.

Cannot get more than 20 images returned?

Please use [API Name] Brief description as title.

API Name (Kind)

Microsoft.Azure.CognitiveServices.Search.WebSearch;

Issue Description

I changed my Search code to this:
var webData = await client.Web.SearchAsync(query: "Stop Sign", count: 500);

but I read the Max return is 50, so I changed to:
var webData = await client.Web.SearchAsync(query: "Stop Sign", count: 50);
and either way the most I get back is 20 images??

Is there a way to return say 1000 results and page through the results?

Domain-specific content API call returns raw response

Computer Vision

API Name (Kind)

ComputerVision

Issue Description

The AnalyzeImageByDomainAsync() function returns a DomainModelResults.Results, but it is raw JSON response, meaning the user does not know what it can get from this response, until they print the whole response as a JSON dump.

The other API calls do not have this, they have properties that represent the keys.
Requesting a fix so the user is not confused and this function is consistent with the other API calls.

Suggestion: return the properties of the results similar to the following examples:

results.Result.name - the name of the landmark or celebrity
results.Result.confidence - confidence of the correct name or face rectangle
results.Result.faceRectangle.width - gets the dimensions of the found face of a celebrity

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cognitiveservices.vision.computervision.computervisionclientextensions.analyzeimagebydomainasync?view=azure-dotnet#Microsoft_Azure_CognitiveServices_Vision_ComputerVision_ComputerVisionClientExtensions_AnalyzeImageByDomainAsync_Microsoft_Azure_CognitiveServices_Vision_ComputerVision_IComputerVisionClient_System_String_System_String_System_String_System_Threading_CancellationToken_

[ComputerVision] maxRetry error in sample code

API Name (Kind)

ComputerVision

Issue Description

The following sample contains wrong code to retry fetching the results of the async operation:
https://github.com/Azure-Samples/cognitive-services-dotnet-sdk-samples/blob/master/documentation-samples/quickstarts/ComputerVision/Program.cs

Original code:
int i = 0; int maxRetries = 10; ReadOperationResult results; do { results = await client.GetReadOperationResultAsync(operationId); Console.WriteLine("Server status: {0}, waiting {1} seconds...", results.Status, i); await Task.Delay(1000); if (maxRetries == 9) { Console.WriteLine("Server timed out."); } } while ((results.Status == TextOperationStatusCodes.Running || results.Status == TextOperationStatusCodes.NotStarted) && i++ < maxRetries);

Errors:

  1. maxRetries should be a const (in order to catch the following errors).
  2. The Console.WriteLine message shows "waiting {1} seconds", which is equivalent to showing $"waiting {i} seconds". However, the variable i gets increased in every iteration, but the code always waits 1 second, it doesn't vary.
  3. The line "if (maxRetries == 9)" should use i instead of maxRetries, because i gets increased, not maxRetries.

Corrected code:
`
int i = 0;
const int MAX_RETRIES = 10;
ReadOperationResult results;
do
{
results = await visionService.GetReadOperationResultAsync(operationId);

if (results.Status != TextOperationStatusCodes.Succeeded)
{
    Console.WriteLine($"Server status: {results.Status}, waiting 1 s ...");
    await Task.Delay(1000);
    if (i == 9)
    {
        Console.WriteLine("Server timed out");
    }
}

}
while ((results.Status == TextOperationStatusCodes.Running ||
results.Status == TextOperationStatusCodes.NotStarted) && i++ < MAX_RETRIES);
`

Cognitive services for Dot.Net Framework

Hi!
are these services only for console app?

Trying to use Azure cognitive services.

Microsoft.Azure.CognitiveServices.Vision.ComputerVision

The function runs when try it on console app (tried both C# & VB), however when trying to run it on windows app get errors. Basically I want to return value after calling an azure service, and use it in windows app.

Same code running on console app, but not returning any value on windows framework app.

gets stuck at below lines. the thread is processed asynchronously with no response

Dim results As DetectResult = Await client.DetectObjectsInStreamAsync(stream)

Dim textHeaders = Await client.ReadInStreamAsync(File.OpenRead(localFile), language:="en"

I don't think there should be any limitation of Azure use only on windows app

API Name Microsoft.Azure.CognitiveServices.Vision.ComputerVision

Working only on console app, not on windows app

...

[Image Search API] It could not return plenty of results from multiple requests.

API Name (Kind)

Image Search API: https://api.cognitive.microsoft.com/bing/v7.0/images/search

Issue Description

When I call Image Search API to collect images with a search term, say "car", I get only about 1000 results in total from all requests. I know there is a limitation for at most 150 results in each response, so I call the API multiple times with incremental offset. I don't understand which params I missed and I failed to find it from the official filter/option params list. Any idea for help? Thanks so much.

Detail

The console log as below is from the script I wrote, which tries to collect 10000 image records with the search term "car". The offset comes from the nextOffset value in the API response. The request querying images from offset 1000 returns 87 records and the nextOffset is still 1000, which means the future request will be the same as the current. Thus my script comes to the exit. I tried several times even with other search terms but I never get a little more image records returned. Apparently, there must be much more images than a thousand for a general search term.

Searched 150 records from offset 0
Saved 121 new photos, now 121/10000
Searched 150 records from offset 173
Saved 142 new photos, now 263/10000
Searched 150 records from offset 345
Saved 149 new photos, now 412/10000
Searched 137 records from offset 537
Saved 137 new photos, now 549/10000
Searched 150 records from offset 719
Saved 138 new photos, now 687/10000
Searched 94 records from offset 892
Saved 93 new photos, now 780/10000
Searched 87 records from offset 1000
Saved 0 new photos, now 780/10000
Unable to collect more images. Done.

The query params in the request URL is like,

count=1000&freshness=month&imageType=photo&license=all&offset=0&q=car

Bing Visual Search API - Image not found

API Name (Kind)

Bing Visual Search

Issue Description

Minimal steps to reproduce
In both the BingAllSearch solution ("VisualSearch" sample) and the BingVisualSearch solution, choosing an item that submits an image binary returns an error that […]\bin\Debug\netcoreapp2.0\TestImages\image.jpg cannot be found.

Workaround/Mitigation

Need to add image name image.jpg in these folders:

  • cognitive-services-dotnet-sdk-samples\BingSearchv7\BingVisualSearch\bin\Debug\netcoreapp2.0
  • cognitive-services-dotnet-sdk-samples\BingSearchv7\BingVisualSearch\bin\Debug\netcoreapp1.1

MISC

I'm a FTE at Microsoft and can also report this to our Product Group if necessary

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.