Skip to content
Snippets Groups Projects
Commit 657af451 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[advanced][databases][atnt] Add new version following V2 implementation

parent eeafe22b
No related branches found
No related tags found
1 merge request!28Add protocoltemplates
{
"description": "The AT&T Database of Faces",
"root_folder": "/idiap/group/biometric/databases/orl",
"protocols": [
{
"name": "idiap",
"template": "simple_face_recognition/1",
"views": {
"train": {
"view": "Train",
"parameters": {}
},
"templates": {
"view": "Templates",
"parameters": {}
},
"probes": {
"view": "Probes",
"parameters": {}
}
}
},
{
"name": "idiap_test_eyepos",
"template": "advanced_face_recognition/1",
"views": {
"train": {
"view": "TrainEyePositions",
"parameters": {}
},
"dev_templates": {
"view": "TemplatesEyePositions",
"parameters": {
"group": "dev"
}
},
"dev_probes": {
"view": "ProbesEyePositions",
"parameters": {
"group": "dev"
}
},
"test_templates": {
"view": "TemplatesEyePositions",
"parameters": {
"group": "eval"
}
},
"test_probes": {
"view": "ProbesEyePositions",
"parameters": {
"group": "eval"
}
}
}
}
],
"schema_version": 2
}
\ No newline at end of file
###############################################################################
# #
# Copyright (c) 2018 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. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy as np
from collections import namedtuple
from beat.backend.python.database import View
import bob.io.base
import bob.io.image
import bob.ip.color
import bob.db.atnt
#----------------------------------------------------------
class Train(View):
"""Outputs:
- image: "{{ system_user.username }}/array_2d_uint8/1"
- file_id: "{{ system_user.username }}/uint64/1"
- client_id: "{{ system_user.username }}/uint64/1"
One "file_id" 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 |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| client_id | | client_id |
----------------------------------------------- -----------------------------------------------
"""
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['client_id', 'file_id', 'image'])
# Open the database and load the objects to provide via the outputs
db = bob.db.atnt.Database()
objs = sorted(db.objects(groups='world', purposes=None),
key=lambda x: (x.client_id, x.id))
return [ Entry(x.client_id, x.id, x.make_path(root_folder, '.pgm')) for x in objs ]
def get(self, output, index):
obj = self.objs[index]
if output == 'client_id':
return {
'value': np.uint64(obj.client_id)
}
elif output == 'file_id':
return {
'value': np.uint64(obj.file_id)
}
elif output == 'image':
return {
'value': bob.io.base.load(obj.image)
}
#----------------------------------------------------------
class Templates(View):
"""Outputs:
- image: "{{ system_user.username }}/array_2d_uint8/1"
- file_id: "{{ system_user.username }}/uint64/1"
- template_id: "{{ system_user.username }}/uint64/1"
- client_id: "{{ system_user.username }}/uint64/1"
One "file_id" 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 |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| template_id | | template_id |
----------------------------------------------- -----------------------------------------------
-----------------------------------------------------------------------------------------------
| client_id |
-----------------------------------------------------------------------------------------------
Note: for this particular database, there is only one "template_id"
per "client_id".
"""
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['client_id', 'template_id', 'file_id', 'image'])
# Open the database and load the objects to provide via the outputs
db = bob.db.atnt.Database()
template_ids = db.model_ids(groups='dev')
entries = []
for template_id in template_ids:
objs = db.objects(groups='dev', purposes='enroll',
model_ids=[template_id])
entries.extend([ Entry(x.client_id, template_id, x.id, x.make_path(root_folder, '.pgm'))
for x in objs ])
return sorted(entries, key=lambda x: (x.client_id, x.template_id, x.file_id))
def get(self, output, index):
obj = self.objs[index]
if output == 'client_id':
return {
'value': np.uint64(obj.client_id)
}
elif output == 'template_id':
return {
'value': np.uint64(obj.template_id)
}
elif output == 'file_id':
return {
'value': np.uint64(obj.file_id)
}
elif output == 'image':
return {
'value': bob.io.base.load(obj.image)
}
#----------------------------------------------------------
class Probes(View):
"""Outputs:
- image: "{{ system_user.username }}/array_2d_uint8/1"
- file_id: "{{ system_user.username }}/uint64/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 "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 index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['template_ids', 'client_id', 'probe_id', 'file_id', 'image'])
# Open the database and load the objects to provide via the outputs
db = bob.db.atnt.Database()
template_ids = np.array(sorted(db.model_ids(groups='dev'),
key=lambda x: int(x)),
dtype='uint64')
objs = sorted(db.objects(groups='dev', purposes='probe'),
key=lambda x: (x.client_id, x.id))
return [ Entry(template_ids, x.client_id, x.id, x.id, x.make_path(root_folder, '.pgm'))
for x in objs ]
def get(self, output, index):
obj = self.objs[index]
if output == 'template_ids':
return {
'value': obj.template_ids
}
elif output == 'client_id':
return {
'value': np.uint64(obj.client_id)
}
elif output == 'probe_id':
return {
'value': np.uint64(obj.probe_id)
}
elif output == 'file_id':
return {
'value': np.uint64(obj.file_id)
}
elif output == 'image':
return {
'value': bob.io.base.load(obj.image)
}
#----------------------------------------------------------
class TrainEyePositions(View):
"""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 index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['client_id', 'eye_centers', 'file_id', 'image'])
# Open the database and load the objects to provide via the outputs
db = bob.db.atnt.Database()
objs = sorted(db.objects(groups='world', purposes=None),
key=lambda x: (x.client_id, x.id))
eye_centers = {
'left': {
'y': np.int32(48),
'x': np.int32(63),
},
'right': {
'y': np.int32(48),
'x': np.int32(27),
}
}
return [ Entry(x.client_id, eye_centers, x.id, x.make_path(root_folder, '.pgm'))
for x in objs ]
def get(self, output, index):
obj = self.objs[index]
if output == 'client_id':
return {
'value': np.uint64(obj.client_id)
}
elif output == 'eye_centers':
return obj.eye_centers
elif output == 'file_id':
return {
'value': np.uint64(obj.file_id)
}
elif output == 'image':
return {
'value': bob.io.base.load(obj.image)
}
#----------------------------------------------------------
class TemplatesEyePositions(View):
"""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 index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['client_id', 'template_id', 'file_id', 'eye_centers', 'image'])
# Open the database and load the objects to provide via the outputs
db = bob.db.atnt.Database()
eye_centers = {
'left': {
'y': np.int32(48),
'x': np.int32(63),
},
'right': {
'y': np.int32(48),
'x': np.int32(27),
}
}
template_ids = db.model_ids(groups='dev')
entries = []
for template_id in template_ids:
objs = db.objects(groups='dev', purposes='enroll',
model_ids=[template_id])
entries.extend([ Entry(x.client_id, template_id, x.id, eye_centers, x.make_path(root_folder, '.pgm'))
for x in objs ])
return sorted(entries, key=lambda x: (x.client_id, x.template_id, x.file_id))
def get(self, output, index):
obj = self.objs[index]
if output == 'client_id':
return {
'value': np.uint64(obj.client_id)
}
elif output == 'template_id':
return {
'value': np.uint64(obj.template_id)
}
elif output == 'file_id':
return {
'value': np.uint64(obj.file_id)
}
elif output == 'eye_centers':
return obj.eye_centers
elif output == 'image':
return {
'value': bob.io.base.load(obj.image)
}
#----------------------------------------------------------
class ProbesEyePositions(View):
"""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".
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 |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers | | eye_centers |
--------------- --------------- --------------- --------------- --------------- ---------------
--------------- --------------- --------------- --------------- --------------- ---------------
| probe_id | | probe_id | | probe_id | | probe_id | | probe_id | | probe_id |
--------------- --------------- --------------- --------------- --------------- ---------------
----------------------------------------------- -----------------------------------------------
| client_id | | client_id |
----------------------------------------------- -----------------------------------------------
-----------------------------------------------------------------------------------------------
| template_ids |
-----------------------------------------------------------------------------------------------
"""
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['template_ids', 'client_id', 'probe_id', 'file_id',
'eye_centers', 'image'])
# Open the database and load the objects to provide via the outputs
db = bob.db.atnt.Database()
eye_centers = {
'left': {
'y': np.int32(48),
'x': np.int32(63),
},
'right': {
'y': np.int32(48),
'x': np.int32(27),
}
}
template_ids = np.array(sorted(db.model_ids(groups='dev'),
key=lambda x: int(x)),
dtype='uint64')
objs = sorted(db.objects(groups='dev', purposes='probe'),
key=lambda x: (x.client_id, x.id))
return [ Entry(template_ids, x.client_id, x.id, x.id, eye_centers,
x.make_path(root_folder, '.pgm'))
for x in objs ]
def get(self, output, index):
obj = self.objs[index]
if output == 'template_ids':
return {
'value': obj.template_ids
}
elif output == 'client_id':
return {
'value': np.uint64(obj.client_id)
}
elif output == 'probe_id':
return {
'value': np.uint64(obj.probe_id)
}
elif output == 'file_id':
return {
'value': np.uint64(obj.file_id)
}
elif output == 'eye_centers':
return obj.eye_centers
elif output == 'image':
return {
'value': bob.io.base.load(obj.image)
}
#----------------------------------------------------------
def setup_tests():
# Install a mock load function for the images
def mock_load(root_folder):
return np.ndarray((92, 112), dtype=np.uint8)
bob.io.base.load = mock_load
#----------------------------------------------------------
# Test the behavior of the views (on fake data)
if __name__ == '__main__':
setup_tests()
view = Train()
view.objs = view.index(root_folder='', parameters=dict())
view.get('client_id', 0)
view.get('file_id', 0)
view.get('image', 0)
view = Templates()
view.objs = view.index(root_folder='', parameters=dict())
view.get('client_id', 0)
view.get('template_id', 0)
view.get('file_id', 0)
view.get('image', 0)
view = Probes()
view.objs = view.index(root_folder='', parameters=dict())
view.get('template_ids', 0)
view.get('client_id', 0)
view.get('probe_id', 0)
view.get('file_id', 0)
view.get('image', 0)
view = TrainEyePositions()
view.objs = view.index(root_folder='', parameters=dict())
view.get('client_id', 0)
view.get('file_id', 0)
view.get('eye_centers', 0)
view.get('image', 0)
view = TemplatesEyePositions()
view.objs = view.index(root_folder='', parameters=dict())
view.get('client_id', 0)
view.get('template_id', 0)
view.get('file_id', 0)
view.get('eye_centers', 0)
view.get('image', 0)
view = ProbesEyePositions()
view.objs = view.index(root_folder='', parameters=dict())
view.get('template_ids', 0)
view.get('client_id', 0)
view.get('probe_id', 0)
view.get('file_id', 0)
view.get('eye_centers', 0)
view.get('image', 0)
The AT&T Database of Faces
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment