From 402ccb556e17611d3ef2ba4f060c4138fc0f0733 Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Mon, 10 Mar 2014 17:09:44 +0100 Subject: [PATCH] Add support for reading annotations in msgpack format --- sloth/annotations/container.py | 23 +++++++++++++++++++++++ sloth/conf/default_config.py | 1 + 2 files changed, 24 insertions(+) diff --git a/sloth/annotations/container.py b/sloth/annotations/container.py index a82a7b7..f081bad 100644 --- a/sloth/annotations/container.py +++ b/sloth/annotations/container.py @@ -318,6 +318,29 @@ class JsonContainer(AnnotationContainer): json.dump(annotations, f, indent=4, sort_keys=True) +class MsgpackContainer(AnnotationContainer): + """ + Simple container which writes the annotations to disk in Msgpack format. + """ + + def parseFromFile(self, fname): + """ + Overwritten to read Msgpack files. + """ + import msgpack + f = open(fname, "r") + return msgpack.load(f) + + def serializeToFile(self, fname, annotations): + """ + Overwritten to write Msgpack files. + """ + # TODO make all image filenames relative to the label file + import msgpack + f = open(fname, "w") + msgpack.dump(annotations, f) + + class YamlContainer(AnnotationContainer): """ Simple container which writes the annotations to disk in YAML format. diff --git a/sloth/conf/default_config.py b/sloth/conf/default_config.py index bf8db27..547f6c1 100644 --- a/sloth/conf/default_config.py +++ b/sloth/conf/default_config.py @@ -97,6 +97,7 @@ HOTKEYS = ( # to such a class. CONTAINERS = ( ('*.json', 'sloth.annotations.container.JsonContainer'), + ('*.msgpack', 'sloth.annotations.container.MsgpackContainer'), ('*.yaml', 'sloth.annotations.container.YamlContainer'), ('*.pickle', 'sloth.annotations.container.PickleContainer'), ('*.sloth-init', 'sloth.annotations.container.FileNameListContainer'),