From e6927cbc04da84de7e1ebf731ada6694f8fd61de Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Wed, 9 Apr 2014 20:15:37 +0200 Subject: [PATCH] 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)