public async Task <IEnumerable <LabelConfidence> > Tags(byte[] image, CustomVisionSettings settings) { // Create a prediction endpoint, passing in obtained prediction key var endpoint = new PredictionEndpoint() { ApiKey = settings.CustomVisionPredictionKey }; Cognitive.CustomVision.Prediction.Models.ImagePredictionResultModel result; using (var testImage = new MemoryStream(image)) { // Make a prediction against the prediction project // IMPORTANT: the prediction project should have an iteration marked as default. // Otherwise, you need to specify an iteration ID result = await endpoint.PredictImageWithNoStoreAsync(settings.CustomVisionProjectId, testImage); } return(result.Predictions.Select(t => new LabelConfidence() { Label = t.Tag, Probability = (float)t.Probability }) .Where(c => c.Probability >= settings.Threshold) .OrderByDescending(c => c.Probability)); }
public CustomVisionOnlinePrediction(IOptionsSnapshot <AppSettings> settings, ICustomVisionClient customVisionClient) { this.customVisionClient = customVisionClient; Guid projectId; if (settings.Value.CustomVision == null || string.IsNullOrEmpty(settings.Value.CustomVision.ProjectId) || !Guid.TryParse(settings.Value.CustomVision.ProjectId, out projectId)) { projectId = Guid.Empty; } //TODO: move these settings to setting file customVisionSettings = new CustomVisionSettings { CustomVisionPredictionKey = settings.Value.CustomVision?.PredictionKey, CustomVisionProjectId = projectId, Threshold = 0.85f, MaxLength = 5 }; }