private void PackageSelected(AnnotationPackage package) { this._changedPackage = true; this.annotationImageListControl.Hide(); this.downloadControl.Hide(); this.tagListControl.Hide(); this.annotationImageListControl.Reset(); this.annotationDrawControl.Reset(); if (package != null) { this.tagListControl.SetTags(package); if (package.Extracted) { this.annotationImageListControl.SetPackage(package); this.annotationImageListControl.Show(); this.annotationPackageListControl.RefreshData(); this.tagListControl.Show(); } else { this.downloadControl.ShowDownloadDialog(package); } } this._changedPackage = false; }
private async Task <bool> SyncPackageAsync(AnnotationPackage package) { var info = new AnnotationPackageDto { Id = package.ExternalId, IsAnnotated = package.IsAnnotated, AnnotationPercentage = package.AnnotationPercentage, Tags = package.Tags }; info.Images = new List <AnnotationImageDto>(); foreach (var image in package.Images.Where(o => o.BoundingBoxes != null)) { info.Images.Add(new AnnotationImageDto { ImageName = image.ImageName, BoundingBoxes = image.BoundingBoxes }); } try { using (var context = new DynamoDBContext(this._dynamoDbClient)) { await context.SaveAsync(info).ConfigureAwait(false); } } catch (Exception e) { } this._syncedPackages++; return(true); }
private async Task SyncPackageAsync(AnnotationPackage package) { var context = new DynamoDBContext(this._dynamoDbClient); await context.SaveAsync(package.Info); this._syncedPackages++; }
public void AnalyzeAnnotationStatus(AnnotationPackage package) { if (!package.Extracted) { return; } var allowedImageFormats = new string[] { ".png", ".jpg", ".bmp" }; var files = Directory.GetFiles(package.PackagePath, "*.*", SearchOption.TopDirectoryOnly).Select(file => new FileInfo(file)); var items = files.Where(file => allowedImageFormats.Contains(file.Extension)).Select(o => new AnnotationImage { FilePath = o.FullName, DisplayName = o.Name, BoundingBoxes = this._boundingBoxReader.GetBoxes(this._boundingBoxReader.GetDataPath(o.FullName)).ToList() }).ToList(); if (items.Count == 0) { return; } package.Images = items; this.UpdateAnnotationStatus(package); }
private async Task <bool> UpdatePackageAsync(AnnotationPackage package, CancellationToken token) { using (var context = new DynamoDBContext(this._dynamoDbClient)) { var dbConfig = new DynamoDBOperationConfig { OverrideTableName = this._dbTableName }; var info = await context.LoadAsync <AnnotationPackageDto>(package.ExternalId, dbConfig, token).ConfigureAwait(false); info.User = package.User; info.IsAnnotated = package.IsAnnotated; info.AnnotationPercentage = package.AnnotationPercentage; info.Tags = package.Tags; info.Images = new List <AnnotationImageDto>(); if (package.Images != null) { foreach (var image in package.Images.Where(o => o.BoundingBoxes != null)) { info.Images.Add(new AnnotationImageDto { ImageName = image.ImageName, BoundingBoxes = image.BoundingBoxes }); } } await context.SaveAsync(info, dbConfig, token).ConfigureAwait(false); this._syncProgress.TransferedFiles++; return(true); } }
private void PackageSelected(AnnotationPackage package) { this.annotationImageListControl.Hide(); this.downloadControl.Hide(); this.annotationImageListControl.SetImages(null); this.annotationImageControl.SetImage(null, null); if (package == null) { return; } this.tagListControl.SetTags(package.Info); if (package.Extracted) { if (package.Images == null) { this.annotationPackageListControl.AnalyzeAnnotationStatus(package); } this.annotationImageListControl.SetImages(package.Images); this.annotationImageListControl.DataGridView.Refresh(); this.annotationImageListControl.Show(); } else { //TODO: On selected item change in the datagrid always new tasks started... this.downloadControl.ShowDownloadDialog(package); } //TODO: Why refresh? this.annotationPackageListControl.DataGridView.Refresh(); }
public void SetPackage(AnnotationPackage package) { this._annotationImages = package.Images; this._bindingSource.DataSource = this._annotationImages; this._bindingSource.ResetBindings(false); this._bindingSource.CurrencyManager.Position = 0; }
private void PackageSelected(AnnotationPackage package, PackageSelectionBehavior behavior) { switch (behavior) { case PackageSelectionBehavior.RefreshOnly: if (this._selectedPackage != package) { return; } break; case PackageSelectionBehavior.SwitchOnly: if (this._selectedPackage == package) { return; } break; } // Cancel if multiple packages are selected if (this.annotationPackageListControl.GetSelectedPackageCount() > 1) { this.SetPackageEditingControlsEnabled(false); return; } this.SetPackageEditingControlsEnabled(true); this._changedPackage = true; this._selectedPackage = package; this.annotationImageListControl.Hide(); this.downloadControl.Hide(); this.annotationImageListControl.Reset(); this.annotationDrawControl.Reset(); this.labelUserName.Text = package?.User; if (package != null) { this.tagEditControl.SetTags(package); if (package.AvailableLocally) { this.annotationImageListControl.SetPackage(package); this.annotationImageListControl.Show(); this.annotationPackageListControl.RefreshDataGrid(); } else { this.downloadControl.ShowDownloadDialog(package); } } this._changedPackage = false; }
private async Task ExtractionRequestedAsync(AnnotationPackage package) { var downloadedPackage = await this._annotationPackageProvider.DownloadPackageAsync(package); this.annotationPackageListControl.UnzipPackage(downloadedPackage); // Select folder to apply the images after extraction this.PackageSelected(downloadedPackage); }
public void SetTags(AnnotationPackage package) { if (package == null) { return; } this._package = package; this.tagDisplayControl.SetTags(this._package.Tags?.ToArray()); }
public void SetTags(AnnotationPackage package) { if (package == null) { return; } this._package = package; this.RefreshDatagrid(); }
private async Task ShowDownloadProgress(AnnotationPackage package) { while (package.DownloadProgress < 100 && package.Downloading && this._packageToExtract == package) { await Task.Delay(20); this.labelPercentage.Invoke((MethodInvoker) delegate { this.labelPercentage.Text = $"{(int)package.DownloadProgress}%"; }); this.progressBarDownload.Invoke((MethodInvoker) delegate { this.progressBarDownload.Value = (int)package.DownloadProgress; }); } this.progressBarDownload.Value = 0; }
public void ShowDownloadDialog(AnnotationPackage package) { this.buttonDownload.Visible = !package.Downloading; this.progressBarDownload.Visible = package.Downloading; this.labelPercentage.Visible = package.Downloading; this.labelPercentage.BringToFront(); this._packageToExtract = package; this.Show(); Task.Run(() => this.ShowDownloadProgress(package)); }
private void AddImageDtos(AnnotationPackage package) { var info = package.Info; info.ImageDtos = new List <AnnotationImageDto>(); foreach (var image in package.Images) { info.ImageDtos.Add(new AnnotationImageDto { FilePath = image.FilePath, BoundingBoxes = image.BoundingBoxes }); } }
private async Task <bool> SyncPackageAsync(AnnotationPackage package) { if (package.Info == null) { return(false); } using (var context = new DynamoDBContext(this._dynamoDbClient)) { await context.SaveAsync(package.Info).ConfigureAwait(false); } this._syncedPackages++; return(true); }
public void ShowDownloadDialog(AnnotationPackage package) { this.buttonDownload.Visible = !package.Downloading; this.progressBarDownload.Visible = package.Downloading; this.labelPercentage.Visible = package.Downloading; this._packageToExtract = package; this.labelPercentage.Text = ""; this.labelDownload.Text = ""; this.progressBarDownload.Value = (int)package.DownloadProgress; this.Show(); Task.Run(() => this.ShowDownloadProgress(package)); }
private async Task ShowDownloadProgress(AnnotationPackage package) { while (package.DownloadProgress < 100 && package.Downloading && this._packageToExtract == package) { this.labelPercentage.Invoke((MethodInvoker) delegate { this.labelPercentage.Text = $"{(int)package.DownloadProgress}%"; }); this.labelDownload.Invoke((MethodInvoker) delegate { this.labelDownload.Text = $"{package.TransferredBytes / 1024.0 / 1024.0:0.00} MB of {package.TotalBytes / 1024.0 / 1024.0:0.00} MB"; }); this.progressBarDownload.Invoke((MethodInvoker) delegate { this.progressBarDownload.Value = (int)package.DownloadProgress; }); await Task.Delay(200); } }
public void ShowDownloadDialog(AnnotationPackage package) { this.buttonDownload.Visible = !package.Downloading; this.progressBarDownload.Visible = package.Downloading; this.labelPercentage.Visible = package.Downloading; this.labelNotification.Text = "The package is not available locally yet. Please download it first"; this.progressBarDownload.Value = (int)package.DownloadProgress; this.labelPercentage.Text = string.Empty; this.labelDownload.Text = string.Empty; this._packageToExtract = package; this.Show(); Task.Run(() => this.ShowDownloadProgress(package)); }
public void UnzipPackage(AnnotationPackage package) { var zipFilePath = package.PackagePath; var extractedPackagePath = Path.Combine(Path.GetDirectoryName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath)); if (Directory.Exists(extractedPackagePath)) { Directory.Delete(extractedPackagePath, true); } ZipFile.ExtractToDirectory(package.PackagePath, extractedPackagePath); File.Delete(zipFilePath); package.Extracted = true; package.PackagePath = extractedPackagePath; }
public void UpdateAnnotationStatus(AnnotationPackage package) { // Check if package is annotated or not. 50% of images require to be annotated var annotatedImageCount = 0; var requiredPercentage = 50; foreach (var image in package.Images) { if (image.BoundingBoxes?.Count > 0) { annotatedImageCount++; } } package.Info.AnnotationPercentage = annotatedImageCount / ((double)package.Images.Count) * 100; package.Info.IsAnnotated = package.Info.AnnotationPercentage >= requiredPercentage; }
public async Task <AnnotationPackage> DownloadPackageAsync(AnnotationPackage package) { if (!Directory.Exists(this._extractionFolder)) { Directory.CreateDirectory(this._extractionFolder); } var dir = new S3DirectoryInfo(this._client, this._bucketName); var file = dir.GetFile(package.PackagePath); var zipFilePath = Path.Combine(this._extractionFolder, file.Name); package.Downloading = true; //FileInfo fileInfo = null; //await Task.Run(() => //{ // fileInfo = file.CopyToLocal(zipFilePath, true); //}); var request = new GetObjectRequest { BucketName = this._bucketName, Key = file.Name }; using (var response = this._client.GetObject(request)) { this._currentlyDownloadedPackages.Add(package); response.WriteObjectProgressEvent += this.WriteObjectProgressEvent; await response.WriteResponseStreamToFileAsync(zipFilePath, false, new System.Threading.CancellationToken()); this._currentlyDownloadedPackages.Remove(package); response.WriteObjectProgressEvent -= this.WriteObjectProgressEvent; } package.Downloading = false; package.PackagePath = zipFilePath; package.DisplayName = Path.GetFileNameWithoutExtension(zipFilePath); return(await Task.FromResult(package)); }
public async Task <bool> DeletePackageAsync(AnnotationPackage package) { try { var successful = true; // Delete images on S3 foreach (var image in package.Images) { if (!await this.DeleteImageAsync(image).ConfigureAwait(false)) { successful = false; } } // Delete package from DynamoDB using (var context = new DynamoDBContext(this._dynamoDbClient)) { var dbConfig = new DynamoDBOperationConfig { OverrideTableName = this._dbTableName }; await context.DeleteAsync(new AnnotationPackageDto { Id = package.ExternalId }, dbConfig).ConfigureAwait(false); } // Delete local folder var path = Path.Combine(this._extractionFolder, package.PackageName); if (Directory.Exists(path)) { Directory.Delete(path, true); } return(successful); } catch (Exception e) { return(false); } }
private async Task <bool> DownloadMissingPackages(List <AnnotationPackage> packages) { var successful = true; this._downloading = true; this._downloadProgress = new AnnotationPackageTransferProgress { FileCount = packages.Count }; _ = Task.Run(() => this.UpdateProgressBar()); this._tokenSource = new CancellationTokenSource(); var token = this._tokenSource.Token; try { for (var i = 0; i < packages.Count; i++) { this._downloadedPackage = packages[i]; this._downloadProgress.CurrentFile = packages[i].PackageName; packages[i].Downloading = true; packages[i] = await this._annotationPackageProvider.DownloadPackageAsync(packages[i], token); this._downloadProgress.TransferedFiles++; this._downloadProgress.CurrentFilePercentDone = 0; this.dataGridViewResult.Refresh(); } } catch (Exception) { successful = false; MessageBox.Show("The download was cancelled.", "Download failed", MessageBoxButtons.OK, MessageBoxIcon.Information); } this._downloading = false; return(successful); }
private void ChangeObjectClassIndices(AnnotationPackage package, bool toYoloMark) { // Lookup table to convert Yolo Mark indices to our indices or vice-versa var oldNewIndexCollection = new Dictionary <int, int>(); for (var i = 0; i < this._objectClasses.Count; i++) { if (toYoloMark) { oldNewIndexCollection[this._objectClasses[i].Id] = i; } else { oldNewIndexCollection[i] = this._objectClasses[i].Id; } } var files = Directory.GetFiles(package.PackagePath).Where(o => o.EndsWith(".txt")); foreach (var file in files) { var lines = File.ReadAllLines(file); var sb = new StringBuilder(); foreach (var line in lines) { var index = line.GetFirstNumber(); try { sb.AppendLine(line.ReplaceFirst(index.ToString(), oldNewIndexCollection[index].ToString())); } catch (KeyNotFoundException exception) { Log.Error($"{nameof(ChangeObjectClassIndices)} - key: {index.ToString()}, toYoloMark: {toYoloMark}", exception); } } File.WriteAllText(file, sb.ToString()); } }
public void UnzipPackage(AnnotationPackage package) { var zipFilePath = package.PackagePath; var extractedPackagePath = Path.Combine(Path.GetDirectoryName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath)); if (Directory.Exists(extractedPackagePath)) { Directory.Delete(extractedPackagePath, true); } ZipFile.ExtractToDirectory(package.PackagePath, extractedPackagePath); File.Delete(zipFilePath); package.Extracted = true; package.PackagePath = extractedPackagePath; if (package.Info.ImageDtos != null) { var customCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; foreach (var imageDto in package.Info.ImageDtos.Where(o => o.BoundingBoxes?.Count > 0)) { var sb = new StringBuilder(); foreach (var boundingBox in imageDto.BoundingBoxes) { sb.Append(boundingBox.ObjectIndex).Append(" "); sb.Append(boundingBox.CenterX).Append(" "); sb.Append(boundingBox.CenterY).Append(" "); sb.Append(boundingBox.Width).Append(" "); sb.Append(boundingBox.Height).AppendLine(); } var dataPath = this._boundingBoxReader.GetDataPath(imageDto.FilePath); File.WriteAllText(dataPath, sb.ToString()); } } }
private async Task ShowDownloadProgress(AnnotationPackage package) { while (package.DownloadProgress < 100 && package.Downloading && this._packageToExtract == package) { this.labelNotification.Invoke((MethodInvoker) delegate { if (this._packageToExtract == package) { this.labelNotification.Text = package.Enqueued ? "Download queued... Wait for other downloads to finish first..." : $"Downloading {package.PackageName}. Please wait..."; } }); this.progressBarDownload.Invoke((MethodInvoker) delegate { if (this._packageToExtract == package) { this.progressBarDownload.Value = (int)package.DownloadProgress; } }); this.labelPercentage.Invoke((MethodInvoker) delegate { if (this._packageToExtract == package) { this.labelPercentage.Text = $"{(int)package.DownloadProgress}%"; } }); this.labelDownload.Invoke((MethodInvoker) delegate { if (this._packageToExtract == package) { this.labelDownload.Text = package.Enqueued ? "" : $"{package.TransferredBytes / 1024.0 / 1024.0:0.00} MB of {package.TotalBytes / 1024.0 / 1024.0:0.00} MB"; } }); await Task.Delay(200); } }
private async Task <bool> AddPackageAsync(AnnotationPackage package, CancellationToken token) { var info = new AnnotationPackageDto { Id = package.ExternalId, User = package.User, IsAnnotated = package.IsAnnotated, AnnotationPercentage = package.AnnotationPercentage, Tags = package.Tags, Images = new List <AnnotationImageDto>() }; using (var context = new DynamoDBContext(this._dynamoDbClient)) { var dbConfig = new DynamoDBOperationConfig { OverrideTableName = this._dbTableName }; await context.SaveAsync(info, dbConfig, token).ConfigureAwait(false); } return(true); }
public void OpenPackage(AnnotationPackage package) { if (!package.Extracted) { return; } var files = Directory.GetFiles(package.PackagePath, "*.*", SearchOption.TopDirectoryOnly); var items = files.Where(s => s.EndsWith(".png") || s.EndsWith(".jpg")).Select(o => new AnnotationImage { FilePath = o, DisplayName = new FileInfo(o).Name, BoundingBoxes = this._boundingBoxReader.GetBoxes(this._boundingBoxReader.GetDataPath(o)).ToList() }).ToList(); if (items.Count == 0) { return; } package.Images = items; this.UpdateAnnotationStatus(package); }
private async Task DownloadPackage(AnnotationPackage package) { if (package.Downloading) { return; } if (package.AvailableLocally) { return; } package.AvailableLocally = false; package.Downloading = true; package.DownloadProgress = 0; // Reset UI for this package this.Invoke((MethodInvoker) delegate { this.PackageSelected?.Invoke(package, PackageSelectionBehavior.RefreshOnly); }); var downloadedPackage = await this._annotationPackageProvider.DownloadPackageAsync(package); // Refresh UI once download is complete this.Invoke((MethodInvoker) delegate { this.PackageSelected?.Invoke(downloadedPackage, PackageSelectionBehavior.RefreshOnly); }); }
private void FolderSelected(AnnotationPackage package) { this.annotationImageListControl.Show(); this.downloadControl.Hide(); if (package == null) { this.annotationImageListControl.SetImages(null); this.annotationImageControl.SetImage(null, null); return; } if (package.Extracted) { if (package.Images == null) { this.annotationPackageListControl.OpenPackage(package); } this.annotationImageListControl.SetImages(package.Images); } else { this.annotationImageListControl.SetImages(null); this.annotationImageControl.SetImage(null, null); this.annotationImageListControl.Hide(); this.downloadControl.ShowDownloadDialog(package); } this.annotationPackageListControl.DataGridView.Refresh(); this.annotationImageListControl.DataGridView.Refresh(); this.tagListControl.SetTags(package.Info); }