Commit 212d30aa authored by Philip ABBET's avatar Philip ABBET

Various fixes (detected on the platform)

parent a81d1638
......@@ -48,7 +48,7 @@
{
"name": "train",
"template": "train",
"view": "Train",
"view": "TrainEyePositions",
"outputs": {
"file_id": "{{ system_user.username }}/uint64/1",
"client_id": "{{ system_user.username }}/uint64/1",
......@@ -59,7 +59,7 @@
{
"name": "dev_templates",
"template": "templates",
"view": "Templates",
"view": "TemplatesEyePositions",
"parameters": {
"group": "dev"
},
......@@ -74,7 +74,7 @@
{
"name": "dev_probes",
"template": "probes",
"view": "Probes",
"view": "ProbesEyePositions",
"parameters": {
"group": "dev"
},
......@@ -90,7 +90,7 @@
{
"name": "test_templates",
"template": "templates",
"view": "Templates",
"view": "TemplatesEyePositions",
"parameters": {
"group": "eval"
},
......@@ -105,7 +105,7 @@
{
"name": "test_probes",
"template": "probes",
"view": "Probes",
"view": "ProbesEyePositions",
"parameters": {
"group": "eval"
},
......
......@@ -25,6 +25,7 @@
import numpy as np
import bob.io.base
import bob.io.image
import bob.ip.color
import bob.db.atnt
......@@ -75,10 +76,8 @@ class Train:
- image: "{{ system_user.username }}/array_2d_uint8/1"
- file_id: "{{ system_user.username }}/uint64/1"
- client_id: "{{ system_user.username }}/uint64/1"
- (optional) eye_centers: "{{ system_user.username }}/eye_positions/1"
One "file_id" is associated with a given "image".
One "eye_centers" is associated with a given "image".
Several "image" are associated with a given "client_id".
--------------- --------------- --------------- --------------- --------------- ---------------
......@@ -87,9 +86,6 @@ class Train:
--------------- --------------- --------------- --------------- --------------- ---------------
| file_id | | file_id | | file_id | | file_id | | file_id | | file_id |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| client_id | | client_id |
----------------------------------------------- -----------------------------------------------
......@@ -191,10 +187,8 @@ class Templates:
- file_id: "{{ system_user.username }}/uint64/1"
- template_id: "{{ system_user.username }}/uint64/1"
- client_id: "{{ system_user.username }}/uint64/1"
- (optional) eye_centers: "{{ system_user.username }}/eye_positions/1"
One "file_id" is associated with a given "image".
One "eye_centers" is associated with a given "image".
Several "image" are associated with a given "template_id".
Several "template_id" are associated with a given "client_id".
......@@ -204,9 +198,6 @@ class Templates:
--------------- --------------- --------------- --------------- --------------- ---------------
| file_id | | file_id | | file_id | | file_id | | file_id | | file_id |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| template_id | | template_id |
----------------------------------------------- -----------------------------------------------
......@@ -346,7 +337,424 @@ class Probes:
- client_id: "{{ system_user.username }}/uint64/1"
- probe_id: "{{ system_user.username }}/uint64/1"
- template_ids: "{{ system_user.username }}/array_1d_uint64/1"
- (optional) eye_centers: "{{ system_user.username }}/eye_positions/1"
One "file_id" is associated with a given "image".
One "probe_id" is associated with a given "image".
Several "image" are associated with a given "client_id".
Several "client_id" are associated with a given "template_ids".
--------------- --------------- --------------- --------------- --------------- ---------------
| image | | image | | image | | image | | image | | image |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| file_id | | file_id | | file_id | | file_id | | file_id | | file_id |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| probe_id | | probe_id | | probe_id | | probe_id | | probe_id | | probe_id |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| client_id | | client_id |
----------------------------------------------- -----------------------------------------------
-----------------------------------------------------------------------------------------------
| template_ids |
-----------------------------------------------------------------------------------------------
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.root_folder = root_folder
self.outputs = outputs
# Open the database and load the objects to provide via the outputs
self.db = bob.db.atnt.Database()
self.objs = sorted(self.db.objects(groups='dev', purposes='probe'),
key=lambda x: (x.client_id, x.id))
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else len(self.objs) - 1
self.objs = self.objs[self.start_index : self.end_index + 1]
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
obj = self.objs[self.next_index - self.start_index]
# Output: template_ids (only provide data when the template_ids change)
if self.outputs['template_ids'].isConnected() and \
self.outputs['template_ids'].last_written_data_index < self.next_index:
self.outputs['template_ids'].write(
{
'value': np.array(sorted(self.db.model_ids(groups='dev'),
key=lambda x: int(x)),
dtype='uint64')
},
self.end_index
)
# Output: client_id (only provide data when the client_id change)
if self.outputs['client_id'].isConnected() and \
self.outputs['client_id'].last_written_data_index < self.next_index:
client_end_index = get_client_end_index(self.objs, obj.client_id,
self.next_index,
self.start_index,
self.end_index)
self.outputs['client_id'].write(
{
'value': np.uint64(obj.client_id)
},
client_end_index
)
# Output: probe_id (provide data at each iteration)
if self.outputs['probe_id'].isConnected():
self.outputs['probe_id'].write(
{
'value': np.uint64(obj.id)
},
self.next_index
)
# Output: file_id (provide data at each iteration)
if self.outputs['file_id'].isConnected():
self.outputs['file_id'].write(
{
'value': np.uint64(obj.id)
},
self.next_index
)
# Output: image (provide data at each iteration)
if self.outputs['image'].isConnected():
self.outputs['image'].write(
{
'value': bob.io.base.load(obj.make_path(self.root_folder, '.pgm'))
},
self.next_index
)
# Optional output: eye_centers (provide data at each iteration)
if (self.outputs['eye_centers'] is not None) and self.outputs['eye_centers'].isConnected():
self.outputs['eye_centers'].write({
'left': {
'y': np.int32(48),
'x': np.int32(63),
},
'right': {
'y': np.int32(48),
'x': np.int32(27),
}
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
class TrainEyePositions:
"""Outputs:
- image: "{{ system_user.username }}/array_3d_uint8/1"
- file_id: "{{ system_user.username }}/uint64/1"
- eye_centers: "{{ system_user.username }}/eye_positions/1"
- client_id: "{{ system_user.username }}/uint64/1"
One "file_id" is associated with a given "image".
One "eye_centers" is associated with a given "image".
Several "image" are associated with a given "client_id".
--------------- --------------- --------------- --------------- --------------- ---------------
| image | | image | | image | | image | | image | | image |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| file_id | | file_id | | file_id | | file_id | | file_id | | file_id |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| client_id | | client_id |
----------------------------------------------- -----------------------------------------------
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.root_folder = root_folder
self.outputs = outputs
# Open the database and load the objects to provide via the outputs
self.db = bob.db.atnt.Database()
self.objs = sorted(self.db.objects(groups='world', purposes=None),
key=lambda x: (x.client_id, x.id))
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else len(self.objs) - 1
self.objs = self.objs[self.start_index : self.end_index + 1]
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
obj = self.objs[self.next_index - self.start_index]
# Output: client_id (only provide data when the client_id change)
if self.outputs['client_id'].isConnected() and \
self.outputs['client_id'].last_written_data_index < self.next_index:
client_end_index = get_client_end_index(self.objs, obj.client_id,
self.next_index,
self.start_index,
self.end_index)
self.outputs['client_id'].write(
{
'value': np.uint64(obj.client_id)
},
client_end_index
)
# Output: file_id (provide data at each iteration)
if self.outputs['file_id'].isConnected():
self.outputs['file_id'].write(
{
'value': np.uint64(obj.id)
},
self.next_index
)
# Output: image (provide data at each iteration)
if self.outputs['image'].isConnected():
self.outputs['image'].write(
{
'value': bob.ip.color.gray_to_rgb(bob.io.base.load(obj.make_path(self.root_folder, '.pgm')))
},
self.next_index
)
# Output: eye_centers (provide data at each iteration)
if self.outputs['eye_centers'].isConnected():
self.outputs['eye_centers'].write({
'left': {
'y': np.int32(48),
'x': np.int32(63),
},
'right': {
'y': np.int32(48),
'x': np.int32(27),
}
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
class TemplatesEyePositions:
"""Outputs:
- image: "{{ system_user.username }}/array_3d_uint8/1"
- file_id: "{{ system_user.username }}/uint64/1"
- eye_centers: "{{ system_user.username }}/eye_positions/1"
- template_id: "{{ system_user.username }}/uint64/1"
- client_id: "{{ system_user.username }}/uint64/1"
One "file_id" is associated with a given "image".
One "eye_centers" is associated with a given "image".
Several "image" are associated with a given "template_id".
Several "template_id" are associated with a given "client_id".
--------------- --------------- --------------- --------------- --------------- ---------------
| image | | image | | image | | image | | image | | image |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| file_id | | file_id | | file_id | | file_id | | file_id | | file_id |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| template_id | | template_id |
----------------------------------------------- -----------------------------------------------
-----------------------------------------------------------------------------------------------
| client_id |
-----------------------------------------------------------------------------------------------
Note: for this particular database, there is only one "template_id"
per "client_id".
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.root_folder = root_folder
self.outputs = outputs
# Open the database and load the objects to provide via the outputs
self.db = bob.db.atnt.Database()
template_ids = self.db.model_ids(groups='dev')
self.objs = []
for template_id in template_ids:
objs = self.db.objects(groups='dev', purposes='enroll',
model_ids=[template_id])
self.objs.extend([ (template_id, obj) for obj in objs ])
self.objs = sorted(self.objs, key=lambda x: (x[1].client_id, x[0], x[1].id))
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else len(self.objs) - 1
self.objs = self.objs[self.start_index : self.end_index + 1]
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
(template_id, obj) = self.objs[self.next_index - self.start_index]
# Output: template_id (only provide data when the template_id change)
if self.outputs['template_id'].isConnected() and \
self.outputs['template_id'].last_written_data_index < self.next_index:
template_end_index = get_template_end_index(self.objs, template_id,
self.next_index,
self.start_index,
self.end_index)
self.outputs['template_id'].write(
{
'value': np.uint64(template_id)
},
template_end_index
)
# Output: client_id (only provide data when the client_id change)
if self.outputs['client_id'].isConnected() and \
self.outputs['client_id'].last_written_data_index < self.next_index:
client_end_index = get_client_end_index(self.objs, obj.client_id,
self.next_index,
self.start_index,
self.end_index)
self.outputs['client_id'].write(
{
'value': np.uint64(obj.client_id)
},
client_end_index
)
# Output: file_id (provide data at each iteration)
if self.outputs['file_id'].isConnected():
self.outputs['file_id'].write(
{
'value': np.uint64(obj.id)
},
self.next_index
)
# Output: image (provide data at each iteration)
if self.outputs['image'].isConnected():
self.outputs['image'].write(
{
'value': bob.ip.color.gray_to_rgb(bob.io.base.load(obj.make_path(self.root_folder, '.pgm')))
},
self.next_index
)
# Output: eye_centers (provide data at each iteration)
if self.outputs['eye_centers'].isConnected():
self.outputs['eye_centers'].write({
'left': {
'y': np.int32(48),
'x': np.int32(63),
},
'right': {
'y': np.int32(48),
'x': np.int32(27),
}
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
class ProbesEyePositions:
"""Outputs:
- image: "{{ system_user.username }}/array_3d_uint8/1"
- file_id: "{{ system_user.username }}/uint64/1"
- eye_centers: "{{ system_user.username }}/eye_positions/1"
- client_id: "{{ system_user.username }}/uint64/1"
- probe_id: "{{ system_user.username }}/uint64/1"
- template_ids: "{{ system_user.username }}/array_1d_uint64/1"
One "file_id" is associated with a given "image".
One "eye_centers" is associated with a given "image".
......@@ -459,14 +867,14 @@ class Probes:
if self.outputs['image'].isConnected():
self.outputs['image'].write(
{
'value': bob.io.base.load(obj.make_path(self.root_folder, '.pgm'))
'value': bob.ip.color.gray_to_rgb(bob.io.base.load(obj.make_path(self.root_folder, '.pgm')))
},
self.next_index
)
# Optional output: eye_centers (provide data at each iteration)
if (self.outputs['eye_centers'] is not None) and self.outputs['eye_centers'].isConnected():
# Output: eye_centers (provide data at each iteration)
if self.outputs['eye_centers'].isConnected():
self.outputs['eye_centers'].write({
'left': {
'y': np.int32(48),
......@@ -519,30 +927,30 @@ if __name__ == '__main__':
parameters=dict(),
)
DatabaseTester('Train (with eye centers)', Train,
DatabaseTester('Templates', Templates,
[
'client_id',
'template_id',
'file_id',
'eye_centers',
'image',
],
parameters=dict(),
)
DatabaseTester('Templates', Templates,
DatabaseTester('Probes', Probes,
[
'template_ids',
'client_id',
'template_id',
'probe_id',
'file_id',
'image',
],
parameters=dict(),
)
DatabaseTester('Templates (with eye centers)', Templates,
DatabaseTester('TrainEyePositions', TrainEyePositions,
[
'client_id',
'template_id',
'file_id',
'eye_centers',
'image',
......@@ -550,18 +958,18 @@ if __name__ == '__main__':
parameters=dict(),
)
DatabaseTester('Probes', Probes,
DatabaseTester('TemplatesEyePositions', TemplatesEyePositions,
[
'template_ids',
'client_id',
'probe_id',
'template_id',
'file_id',
'eye_centers',
'image',
],
parameters=dict(),
)
DatabaseTester('Probes (with eye centers)', Probes,
DatabaseTester('ProbesEyePositions', ProbesEyePositions,
[
'template_ids',
'client_id',
......
......@@ -445,7 +445,7 @@ class Probes:
self.outputs['template_ids'].write(
{
'value': template_ids
'value': np.uint64(template_ids)
},
template_ids_end_index
)
......
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
......
......@@ -397,7 +397,7 @@ class Probes:
self.outputs['template_ids'].write(
{
'value': template_ids
'value': np.uint64(template_ids)
},
template_ids_end_index
)
......
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
......
......@@ -104,7 +104,7 @@ class View:
# Open the database and load the objects to provide via the outputs
self.db = bob.db.casme2.Database()
self.objs = sorted(self.db.objects(protocol=parameters['protocol'],
self.objs = sorted(self.db.objects(protocol=str(parameters['protocol']),
groups=parameters['group']),
key=lambda x: (x.emotion, x.client_id, x.id))
......@@ -171,7 +171,11 @@ class View:
if self.outputs['image'].isConnected():
frames = obj.frames
filename = str(os.path.join(obj.make_path(self.root_folder), frames[0].filename))
filename = str(os.path.join(obj.make_path(), frames[0].filename))
# Bugfix: the database returns invalid paths...
filename = filename.replace('/idiap/resource/database/CASME2/Cropped', self.root_folder)
frame = bob.io.base.load(filename)
data = np.zeros(shape=(len(frames), frame.shape[0], frame.shape[1], frame.shape[2]), dtype="uint8")
......@@ -179,6 +183,10 @@ class View:
for i in range(1, len(frames)):
filename = str(os.path.join(obj.make_path(self.root_folder), frames[i].filename))
# Bugfix: the database returns invalid paths...
filename = filename.replace('/idiap/resource/database/CASME2/Cropped', self.root_folder)
data[i] = bob.io.base.load(filename)
self.outputs['image'].write(
......
......@@ -23,7 +23,7 @@
###############################################################################
import os
import numpy
import numpy as np
import bob.io.base
import bob.io.image
import bob.db.cbsr_nir_vis_2
......@@ -459,7 +459,7 @@ class Probes:
self.outputs['template_ids'].write(
{
'value': template_ids
'text': template_ids
},
template_ids_end_index
)
......
......@@ -23,7 +23,7 @@
###############################################################################
import os
import numpy
import numpy as np
import bob.io.base
import bob.io.image
import bob.db.frgc
......@@ -104,7 +104,7 @@ class Train:
self.outputs = outputs
# Open the database and load the objects to provide via the outputs
self.db = bob.db.frgc.Database()
self.db = bob.db.frgc.Database(original_directory=root_folder)
self.objs = sorted(self.db.objects(protocol=parameters['protocol'],
groups='world',
......@@ -157,7 +157,7 @@ class Train:
# Output: image (provide data at each iteration)
if self.outputs['image'].isConnected():
filename = obj.make_path(self.root_folder, '.jpg')
if not os.path.exists(path):
if not os.path.exists(filename):
path = obj.make_path(self.root_folder, '.JPG')
self.outputs['image'].write(
......@@ -200,7 +200,7 @@ class Templates:
- image: "{{ system_user.username }}/array_3d_uint8/1"
- file_id: "{{ system_user.username }}/text/1"
- eye_centers: "{{ system_user.username }}/eye_positions/1"
- template_id: "{{ system_user.username }}/text/1"
- template_id: "{{ system_user.username }}/uint64/1"