From d3be692badc5f341c00308525849acfe25594072 Mon Sep 17 00:00:00 2001
From: Samuel Gaist <samuel.gaist@idiap.ch>
Date: Wed, 3 Oct 2018 09:28:22 +0200
Subject: [PATCH] [advanced][databases][mobio] Fix root path handling

The root path of a database must be the top level folder where
its data can be found. All other paths should be going from there.

This patch fixes that by adding the image folder as a parameter of
a set and therefore making root_path a real root_path.
---
 advanced/databases/mobio/4.json | 32 +++++++++++++++++++++-----------
 advanced/databases/mobio/4.py   |  6 +++++-
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/advanced/databases/mobio/4.json b/advanced/databases/mobio/4.json
index ce946bc..574d34b 100644
--- a/advanced/databases/mobio/4.json
+++ b/advanced/databases/mobio/4.json
@@ -1,6 +1,6 @@
 {
     "description": "The MOBIO Database of Faces",
-    "root_folder": "/idiap/resource/database/mobio/IMAGES_PNG",
+    "root_folder": "/idiap/resource/database/mobio",
     "protocols": [
         {
             "name": "male",
@@ -12,7 +12,8 @@
                     "view": "Train",
                     "parameters": {
                         "protocol": "male",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -28,7 +29,8 @@
                     "parameters": {
                         "protocol": "male",
                         "group": "dev",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -45,7 +47,8 @@
                     "parameters": {
                         "protocol": "male",
                         "group": "dev",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -63,7 +66,8 @@
                     "parameters": {
                         "protocol": "male",
                         "group": "eval",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -80,7 +84,8 @@
                     "parameters": {
                         "protocol": "male",
                         "group": "eval",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -103,7 +108,8 @@
                     "view": "Train",
                     "parameters": {
                         "protocol": "female",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -119,7 +125,8 @@
                     "parameters": {
                         "protocol": "female",
                         "group": "dev",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -136,7 +143,8 @@
                     "parameters": {
                         "protocol": "female",
                         "group": "dev",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -154,7 +162,8 @@
                     "parameters": {
                         "protocol": "female",
                         "group": "eval",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
@@ -171,7 +180,8 @@
                     "parameters": {
                         "protocol": "female",
                         "group": "eval",
-                        "annotations": "../IMAGE_ANNOTATIONS"
+                        "images": "IMAGES_PNG",
+                        "annotations": "IMAGE_ANNOTATIONS"
                     },
                     "outputs": {
                         "file_id": "{{ system_user.username }}/uint64/1",
diff --git a/advanced/databases/mobio/4.py b/advanced/databases/mobio/4.py
index 1dbcd61..f2c94b1 100644
--- a/advanced/databases/mobio/4.py
+++ b/advanced/databases/mobio/4.py
@@ -69,6 +69,10 @@ class Train(View):
         if not os.path.isabs(annotations):
             annotations = os.path.join(root_folder, annotations)
 
+        images = parameters['images']
+        if not os.path.isabs(images):
+            images = os.path.join(root_folder, images)
+
         db = bob.db.mobio.Database(annotation_directory=annotations)
 
         objs = sorted(db.objects(protocol=parameters['protocol'],
@@ -76,7 +80,7 @@ class Train(View):
                                  purposes='train'),
                       key=lambda x: (x.client_id, x.id))
 
-        return [ Entry(x.client_id, x.id, db.annotations(x), x.make_path(root_folder, '.png'))
+        return [ Entry(x.client_id, x.id, db.annotations(x), x.make_path(images, '.png'))
                  for x in objs ]
 
 
-- 
GitLab