cvhciKIT / sloth

Sloth is a tool for labeling image and video data for computer vision research.
Other
610 stars 198 forks source link

Cannot save annotations if files have additional property key-values #55

Closed tgehrig closed 12 years ago

tgehrig commented 13 years ago

When using the OkapiAnnotationContainer it is possible to have attributes directly assigned to the file, which should be fine as far as I could imagine;-). It is also correctly displayed as key-value pairs directly below the filename. But when trying to save the annotations I get the error: Error: Saving failed (KeyValueRowModelItem instance has no attribute 'getAnnotations')

It I remove all elements in the map for the file besides the filename, class, and the annotations it is working fine.

It can be fixed by patching the code like following, but that is actually not what I want:-/:

diff --git a/sloth/annotations/container.py b/sloth/annotations/container.py
index 32e4129..d0f8be6 100644
--- a/sloth/annotations/container.py
+++ b/sloth/annotations/container.py
@@ -216,11 +216,19 @@ class OkapiAnnotationContainer(AnnotationContainer):

         annotations = []
         for f in container.files():
-            fileitem = self.convertAnnotationPropertiesMapToDict(f.properties())
-            fileitem['class'] = fileitem['type']
-            del fileitem['type']
+            fileitem = {
+                'filename': f.filename(),
+                'class': f.type(),
+                'annotations': [],
+                }
+            for k, v in f.properties().iteritems():
+                if k != 'class' and k != 'filename' and k != 'type':
+                    ann = {
+                        'class': k,
+                        'value': v,
+                        }
+                    fileitem['annotations'].append(ann)
             if f.isImage():
-                fileitem['annotations'] = []
                 for annotation in f.annotations():
                     ann = self.convertAnnotationPropertiesMapToDict(annotation.properties())
                     fileitem['annotations'].append(ann)
baeuml commented 12 years ago

which key is it, that he doesn't like?

tgehrig commented 12 years ago

Any key that is directly associated to the fileitem which is not one of the standard keys like "class". So for example, if I have a fileitem and add as property the key "emotion" it results in the above mentioned error.

baeuml commented 12 years ago

Well, then I don't understand why this is happening. Can you attach a backtrace?

tgehrig commented 12 years ago

How should I generate a backtrace? The program does not crash. It just displays that error in the status bar:-/.

tgehrig commented 12 years ago
Traceback (most recent call last):
  File "/home/tgehrig/src/git/labeltool/sloth/gui/labeltool.py", line 357, in fileSaveAs
    return self.labeltool.saveAnnotations(str(fname))
  File "/home/tgehrig/src/git/labeltool/sloth/core/labeltool.py", line 247, in saveAnnotations
    ann = self._model.root().getAnnotations()
  File "/home/tgehrig/src/git/labeltool/sloth/annotations/model.py", line 281, in getAnnotations
    return [child.getAnnotations() for child in self.children()]
  File "/home/tgehrig/src/git/labeltool/sloth/annotations/model.py", line 452, in getAnnotations
    fi['annotations'] = [child.getAnnotations() for child in self.children()]
AttributeError: KeyValueRowModelItem instance has no attribute 'getAnnotations'