diff --git a/advanced/databases/utfvp/5.json b/advanced/databases/utfvp/5.json new file mode 100644 index 0000000000000000000000000000000000000000..88fb1b4a2e648f6918e5c6ebed8306d613e495fb --- /dev/null +++ b/advanced/databases/utfvp/5.json @@ -0,0 +1,313 @@ +{ + "description": "Finger-Vein database from the University of Twente", + "root_folder": "/idiap/resource/database/UTFVP/data", + "protocols": [ + { + "name": "1vsall", + "template": "simple_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "1vsall" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "1vsall" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "1vsall" + } + } + } + }, + { + "name": "nom", + "template": "advanced_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "nom" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "nom" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "nom" + } + }, + "test_templates": { + "view": "Templates", + "parameters": { + "group": "eval", + "protocol": "nom" + } + }, + "test_probes": { + "view": "Probes", + "parameters": { + "group": "eval", + "protocol": "nom" + } + } + } + }, + { + "name": "nomLeftRing", + "template": "advanced_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "nomLeftRing" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "nomLeftRing" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "nomLeftRing" + } + }, + "test_templates": { + "view": "Templates", + "parameters": { + "group": "eval", + "protocol": "nomLeftRing" + } + }, + "test_probes": { + "view": "Probes", + "parameters": { + "group": "eval", + "protocol": "nomLeftRing" + } + } + } + }, + { + "name": "nomLeftMiddle", + "template": "advanced_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "nomLeftMiddle" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "nomLeftMiddle" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "nomLeftMiddle" + } + }, + "test_templates": { + "view": "Templates", + "parameters": { + "group": "eval", + "protocol": "nomLeftMiddle" + } + }, + "test_probes": { + "view": "Probes", + "parameters": { + "group": "eval", + "protocol": "nomLeftMiddle" + } + } + } + }, + { + "name": "nomLeftIndex", + "template": "advanced_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "nomLeftIndex" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "nomLeftIndex" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "nomLeftIndex" + } + }, + "test_templates": { + "view": "Templates", + "parameters": { + "group": "eval", + "protocol": "nomLeftIndex" + } + }, + "test_probes": { + "view": "Probes", + "parameters": { + "group": "eval", + "protocol": "nomLeftIndex" + } + } + } + }, + { + "name": "nomRightIndex", + "template": "advanced_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "nomRightIndex" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "nomRightIndex" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "nomRightIndex" + } + }, + "test_templates": { + "view": "Templates", + "parameters": { + "group": "eval", + "protocol": "nomRightIndex" + } + }, + "test_probes": { + "view": "Probes", + "parameters": { + "group": "eval", + "protocol": "nomRightIndex" + } + } + } + }, + { + "name": "nomRightMiddle", + "template": "advanced_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "nomRightMiddle" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "nomRightMiddle" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "nomRightMiddle" + } + }, + "test_templates": { + "view": "Templates", + "parameters": { + "group": "eval", + "protocol": "nomRightMiddle" + } + }, + "test_probes": { + "view": "Probes", + "parameters": { + "group": "eval", + "protocol": "nomRightMiddle" + } + } + } + }, + { + "name": "nomRightRing", + "template": "advanced_fingervein_recognition/1", + "views": { + "train": { + "view": "Train", + "parameters": { + "protocol": "nomRightRing" + } + }, + "dev_templates": { + "view": "Templates", + "parameters": { + "group": "dev", + "protocol": "nomRightRing" + } + }, + "dev_probes": { + "view": "Probes", + "parameters": { + "group": "dev", + "protocol": "nomRightRing" + } + }, + "test_templates": { + "view": "Templates", + "parameters": { + "group": "eval", + "protocol": "nomRightRing" + } + }, + "test_probes": { + "view": "Probes", + "parameters": { + "group": "eval", + "protocol": "nomRightRing" + } + } + } + } + ], + "schema_version": 2 +} \ No newline at end of file diff --git a/advanced/databases/utfvp/5.py b/advanced/databases/utfvp/5.py new file mode 100644 index 0000000000000000000000000000000000000000..f9c5c883b8904d6f69b74bb0dcf2cf3ea3887fd0 --- /dev/null +++ b/advanced/databases/utfvp/5.py @@ -0,0 +1,308 @@ +############################################################################### +# # +# 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.db.utfvp + + +#---------------------------------------------------------- + + +class Train(View): + """Outputs: + - image: "{{ system_user.username }}/array_2d_uint8/1" + - file_id: "{{ system_user.username }}/uint64/1" + - client_id: "{{ system_user.username }}/text/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.utfvp.Database() + + objs = sorted(db.objects(protocol=parameters['protocol'], + groups='world', + purposes='train'), + key=lambda x: (x.client_id, x.id)) + + return [ Entry(x.client_id, x.id, x.make_path(root_folder, '.png')) for x in objs ] + + + def get(self, output, index): + obj = self.objs[index] + + if output == 'client_id': + return { + 'text': str(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 }}/text/1" + - client_id: "{{ system_user.username }}/text/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.utfvp.Database() + + template_ids = db.model_ids(protocol=parameters['protocol'], + groups=parameters['group']) + + entries = [] + + for template_id in template_ids: + objs = db.objects(protocol=parameters['protocol'], + groups=parameters['group'], + purposes='enroll', + model_ids=[template_id]) + + entries.extend([ Entry(x.client_id, template_id, x.id, x.make_path(root_folder, '.png')) + 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 { + 'text': str(obj.client_id) + } + + elif output == 'template_id': + return { + 'text': str(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" + - probe_id: "{{ system_user.username }}/uint64/1" + - client_id: "{{ system_user.username }}/text/1" + - template_ids: "{{ system_user.username }}/array_1d_text/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.utfvp.Database() + + objs = sorted(db.objects(protocol=parameters['protocol'], + groups=parameters['group'], + purposes='probe'), + key=lambda x: (x.client_id, x.id)) + + objs = [ (sorted([ model.name for model in obj.models_probe + if model.sgroup == parameters['group'] ]), obj) + for obj in objs ] + + entries = [ Entry(x[0], x[1].client_id, x[1].id, x[1].id, x[1].make_path(root_folder, '.png')) + for x in objs ] + + return sorted(entries, key=lambda x: (len(x.template_ids), x.template_ids, + x.client_id, x.file_id)) + + + def get(self, output, index): + obj = self.objs[index] + + if output == 'template_ids': + return { + 'text': obj.template_ids + } + + elif output == 'client_id': + return { + 'text': str(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) + } + + +#---------------------------------------------------------- + + +def setup_tests(): + # Install a mock load function for the images + def mock_load(root_folder): + return np.ndarray((10, 20), 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( + protocol='1vsall', + ) + ) + view.get('client_id', 0) + view.get('file_id', 0) + view.get('image', 0) + + view = Templates() + view.objs = view.index( + root_folder='', + parameters=dict( + protocol='nomLeftRing', + group='dev', + ) + ) + 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( + protocol='nomLeftRing', + group='dev', + ) + ) + view.get('template_ids', 0) + view.get('client_id', 0) + view.get('probe_id', 0) + view.get('file_id', 0) + view.get('image', 0) diff --git a/advanced/databases/utfvp/5.rst b/advanced/databases/utfvp/5.rst new file mode 100644 index 0000000000000000000000000000000000000000..30e6ad41b6b9d2b917f9f66ba03b07e59a0583a8 --- /dev/null +++ b/advanced/databases/utfvp/5.rst @@ -0,0 +1 @@ +Finger-Vein database from the University of Twente \ No newline at end of file