public void TestProcessChipResults() { var offset = new SKPointI(300, 600); var observations = new[] { new Observation(_categoryManager.GetOrCreate(1, "Car"), 0.9, new SKRect(0.1f, 0.2f, 0.3f, 0.4f)), new Observation(_categoryManager.GetOrCreate(2, "Building"), 0.78, new SKRect(.2f, 0.3f, 0.5f, 0.8f)) }; PostProcessingService.ProcessChipResults(offset, observations); AssertUtils.AreEqualIEnumerable(new[] { new Observation( _categoryManager.GetOrCreate(1, "Car"), 0.9, new SKRect(offset.X + 0.1f * SharedConstants.DefaultChipWidth, offset.Y + 0.2f * SharedConstants.DefaultChipHeight, offset.X + 0.3f * SharedConstants.DefaultChipWidth, offset.Y + 0.4f * SharedConstants.DefaultChipHeight)), new Observation( _categoryManager.GetOrCreate(2, "Building"), 0.78, new SKRect(offset.X + 0.2f * SharedConstants.DefaultChipWidth, offset.Y + 0.3f * SharedConstants.DefaultChipHeight, offset.X + 0.5f * SharedConstants.DefaultChipWidth, offset.Y + 0.8f * SharedConstants.DefaultChipHeight)), }, observations, AssertUtils.AreEqualObservation); }
/// <summary> /// Analyzes the specified <see cref="Chip"/> using the machine learning model. /// </summary> /// <param name="chip">The specified <see cref="Chip"/> of default size.</param> /// <returns>A <see cref="CategoryManager"/> that contains all <see cref="Category"/>s and <see cref="Observation"/>s detected in the specified <see cref="Chip"/>.</returns> public static CategoryManager AnalyzeChip(Chip chip) { if (chip == null) { throw new ArgumentNullException(); } try { using (var mlMultiArray = chip.ToMLMultiArray()) using (var model = new CoreMLModel()) { var categoryManager = model.Predict(mlMultiArray); var observations = categoryManager.Observations; var observationList = observations.ToList(); PostProcessingService.ProcessChipResults(chip.Region.Location, observationList); return(categoryManager); } } catch (FileNotFoundException) { return(new CategoryManager()); } }
public void TestNonMaximumSuppression_IOUGreaterThanThreshold() { var observation1 = new Observation(_category, 0.78, new SKRect(1f, 1f, 7f, 7f)); var observation2 = new Observation(_category, 0.9, new SKRect(0f, 0f, 6f, 6f)); var observations = new[] { observation1, observation2 }; var result = PostProcessingService.NonMaximumSuppression(observations, IOUThreshold, ConfidenceThreshold) .ToList(); AssertUtils.AreEqualIEnumerable(new[] { observation2 }, result); }
public void TestNonMaximumSuppression_NonOverlapping() { var observation1 = new Observation(_category, 0.9, new SKRect(0.1f, 0.2f, 0.3f, 0.4f)); var observation2 = new Observation(_category, 0.78, new SKRect(0.4f, 0.5f, 0.5f, 0.6f)); var observations = new[] { observation1, observation2 }; var result = PostProcessingService.NonMaximumSuppression(observations, IOUThreshold, ConfidenceThreshold) .ToList(); AssertUtils.AreEqualIEnumerable(observations, result); }
public void TestNonMaximumSuppression_CompletelyOverlappingIOUEqualToThreshold() { var observation1 = new Observation(_category, 0.9, new SKRect(1f, 2f, 5f, 8f)); var observation2 = new Observation(_category, 0.78, new SKRect(2f, 3f, 5f, 7f)); var observations = new[] { observation1, observation2 }; var result = PostProcessingService.NonMaximumSuppression(observations, IOUThreshold, ConfidenceThreshold) .ToList(); AssertUtils.AreEqualIEnumerable(observations, result); }
/// <summary> /// Starts the analysis for the uploaded images. /// </summary> private void StartAnalysis() { if (ImageEntries == null || ImageEntries.Count == 0) { LaunchImageUploadPage(); } _totalNumberOfChips = ImageEntries.Sum(imageEntry => GetNumberOfChips(imageEntry.Image)); _numberOfProcessedChips = 0; _task = Task.Factory.StartNew(() => { try { foreach (var imageEntry in ImageEntries) { var categoryManagers = ImageAnalysisService.AnalyzeImage(imageEntry.Image, ChipAnalysisService.AnalyzeChip, _ct, () => { Interlocked.Increment(ref _numberOfProcessedChips); BeginInvokeOnMainThread(() => { ProgressView.SetProgress((float)_numberOfProcessedChips / _totalNumberOfChips, true); }); }) .ToList(); var observations = PostProcessingService.SelectObservations( categoryManagers, SharedConstants.DefaultIOUThreshold, NSUserDefaults.StandardUserDefaults.DoubleForKey( Constants.ConfidenceThresholdUserDefaultName), _ct) .ToList(); imageEntry.Observations = observations; } if (_ts.IsCancellationRequested) { return; } Task.Delay(Constants.DelayBeforeResults / _numberOfProcessedChips, _ct).Wait(_ct); BeginInvokeOnMainThread(LaunchResultsView); } catch (OperationCanceledException) { // ignored } }, _ct); }