Add support for reading annotations in msgpack format

This commit is contained in:
Mika Fischer
2014-03-10 17:09:44 +01:00
parent a78591a9cd
commit 402ccb556e
2 changed files with 24 additions and 0 deletions
+23
View File
@@ -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.
+1
View File
@@ -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'),