Commit 5bf3dfbd authored by André Anjos's avatar André Anjos 💬
Browse files

[models] API to retrieve automatic annotations

parent 3cb0924b
......@@ -5,6 +5,7 @@
import os
import logging
import pkg_resources
import numpy
import bob.db.base
......@@ -221,6 +222,21 @@ class File(object):
return detections
def load_face_detections(self):
"""Loads face detections from locally stored files if they exist, fails
gracefully otherwise, returning `None`"""
data_dir = pkg_resources.resource_filename(__name__, 'data')
path = self.make_path(data_dir, '.hdf5')
if os.path.exists(path):
f = bob.io.base.HDF5File(path)
data = f.get('detections')
return dict([(k[0], k[1:]) for k in f.get('detections')])
return None
def estimate_heartrate_in_bpm(self, directory):
"""Estimates the person's heart rate using the ECG sensor data
......@@ -243,6 +259,20 @@ class File(object):
return chooser(estimates)
def load_heart_rate_in_bpm(self):
"""Loads the heart-rate from locally stored files if they exist, fails
gracefully otherwise, returning `None`"""
data_dir = pkg_resources.resource_filename(__name__, 'data')
path = self.make_path(data_dir, '.hdf5')
if os.path.exists(path):
f = bob.io.base.HDF5File(path)
return f.get_attribute('heartrate_bpm')
return None
def save(self, data, directory=None, extension='.hdf5'):
"""Saves the input data at the specified location and using the given
extension.
......
......@@ -8,8 +8,9 @@
import os, sys
import unittest
from . import Database
import pkg_resources
from . import Database
from .driver import DATABASE_LOCATION
......@@ -29,6 +30,22 @@ def db_available(test):
return wrapper
def meta_available(test):
"""Decorator for detecting if we're running the test on an annotated db"""
from nose.plugins.skip import SkipTest
import functools
@functools.wraps(test)
def wrapper(*args, **kwargs):
if os.path.exists(pkg_resources.resource_filename(__name__, 'data')):
return test(*args, **kwargs)
else:
raise SkipTest("Annotation files are not available")
return wrapper
class HCITaggingTest(unittest.TestCase):
"""Performs various tests on the HCI-Tagging database."""
......@@ -63,8 +80,9 @@ class HCITaggingTest(unittest.TestCase):
print('Physiological signal (%d seconds) is very different in size from estimated video duration (%d seconds) on sample `%s/%s\'' % (time, obj.duration, obj.basedir, obj.stem))
'''
@db_available
def test02_can_read_camera1_video(self):
def test03_can_read_camera1_video(self):
for obj in self.db.objects()[:5]:
......@@ -72,6 +90,19 @@ class HCITaggingTest(unittest.TestCase):
assert video.number_of_frames
@meta_available
def test04_can_read_meta(self):
for obj in self.db.objects()[:5]:
detections = obj.load_face_detections()
assert len(detections)
hr = obj.load_heart_rate_in_bpm()
assert hr
class CmdLineTest(unittest.TestCase):
"""Makes sure our command-line is working properly."""
......@@ -104,7 +135,7 @@ class CmdLineTest(unittest.TestCase):
@db_available
def test03_can_create_meta(self):
def notest03_can_create_meta(self):
from bob.db.base.script.dbmanage import main
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment