From e6927cbc04da84de7e1ebf731ada6694f8fd61de Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Wed, 9 Apr 2014 20:15:37 +0200 Subject: [PATCH 1/2] Append only new files When appending files, check if that file is already in the label file. Do not append it if it's already there. --- sloth/core/commands.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sloth/core/commands.py b/sloth/core/commands.py index 8cf86a6..28f6c66 100644 --- a/sloth/core/commands.py +++ b/sloth/core/commands.py @@ -80,8 +80,9 @@ class DumpLabelsCommand(BaseCommand): class AppendFilesCommand(BaseCommand): """ - Append image or video files to a label file. Creates the label - file if it does not exist before. + Append image or video files to a label file. Creates the label file if it + does not exist before. If the image or video file is already in the label + file, it will not be appended again. """ args = ' [ ...]' help = __doc__.strip() @@ -101,6 +102,8 @@ class AppendFilesCommand(BaseCommand): raise CommandError("Expect at least 2 arguments.") self.labeltool.loadAnnotations(args[0]) + present_filenames = {a["filename"] for a in self.labeltool.annotations()} + for filename in args[1:]: rel_filename = filename try: @@ -109,6 +112,10 @@ class AppendFilesCommand(BaseCommand): except: pass + if rel_filename in present_filenames: + logger.info("Not adding file again: %s" % rel_filename) + continue + _, ext = os.path.splitext(rel_filename) if (not options['image'] and ext.lower() in self.video_extensions) or options['video']: logger.debug("Adding video file: %s" % rel_filename) From af0829baf5bfe5679984133655634bf0659f64b0 Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Thu, 28 Aug 2014 17:33:59 +0200 Subject: [PATCH 2/2] Don't append duplicate files on cmd line multiple times If a file is specified multiple time on the command line, do not append it multiple times. --- sloth/core/commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sloth/core/commands.py b/sloth/core/commands.py index 28f6c66..23851c9 100644 --- a/sloth/core/commands.py +++ b/sloth/core/commands.py @@ -123,6 +123,7 @@ class AppendFilesCommand(BaseCommand): else: logger.debug("Adding image file: %s" % rel_filename) item = self.labeltool.addImageFile(rel_filename) + present_filenames.add(rel_filename) if options['unlabeled']: item.setUnlabeled(True)