mirror of
https://github.com/wassname/sloth.git
synced 2026-07-06 05:16:56 +08:00
Add support for reading annotations in msgpack format
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user