Commit 67278800 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Always use custom annotations

parent 9b3d7154
from . import UVAD_FRAME_SHAPE from . import UVAD_FRAME_SHAPE
from bob.extension import rc from bob.extension import rc
from bob.io.video import reader from bob.io.video import reader
from bob.db.base.annotations import read_annotation_file
from bob.pad.base.database import FileListPadDatabase from bob.pad.base.database import FileListPadDatabase
from bob.pad.face.database import VideoPadFile from bob.pad.face.database import VideoPadFile
from pkg_resources import resource_filename from pkg_resources import resource_filename
...@@ -25,9 +26,9 @@ class File(VideoPadFile): ...@@ -25,9 +26,9 @@ class File(VideoPadFile):
h, w = numpy.shape(frame)[-2:] h, w = numpy.shape(frame)[-2:]
dh, dw = (h - 720) // 2, (w - 1024) // 2 dh, dw = (h - 720) // 2, (w - 1024) // 2
if dh != 0: if dh != 0:
frame = frame[:, dh:-dh, :] frame = frame[:, : -2 * dh, :]
if dw != 0: if dw != 0:
frame = frame[:, :, dw:-dw] frame = frame[:, :, : -2 * dw]
assert frame.shape == self.frame_shape, frame.shape assert frame.shape == self.frame_shape, frame.shape
yield frame yield frame
...@@ -56,49 +57,61 @@ class File(VideoPadFile): ...@@ -56,49 +57,61 @@ class File(VideoPadFile):
@property @property
def annotations(self): def annotations(self):
path = self.make_path( # The annotations shipped with uvad are totally wrong. We load custom
directory=self.original_directory, extension=None) # annotations here
# the annotations are in the uvad/release_1/face-locations-v3 folder path = self.make_path(self.annotation_directory, self.annotation_extension)
path = path.replace('release_1', 'release_1/face-locations-v3') annotations = read_annotation_file(path, annotation_type=self.annotation_type)
path = path[:-3] + 'face'
annotations = {}
with open(path) as f:
for line in f:
line = line.strip()
if not line:
continue
num_frame, x_eye_left, y_eye_left, x_eye_right, y_eye_right = \
line.split()
annotations[num_frame] = {
'reye': (int(y_eye_right), int(x_eye_right)),
'leye': (int(y_eye_left), int(x_eye_left)),
}
return annotations return annotations
class Database(FileListPadDatabase): class Database(FileListPadDatabase):
"""The database interface for the OULU-NPU dataset.""" """The database interface for the OULU-NPU dataset."""
def __init__(self, original_directory=rc['bob.db.uvad.directory'], def __init__(
name='uvad', pad_file_class=None, self,
original_extension=None, **kwargs): original_directory=rc["bob.db.uvad.directory"],
annotation_directory=rc["bob.db.uvad.annotation_dir"],
annotation_extension=".json",
annotation_type="json",
name="uvad",
pad_file_class=None,
original_extension=None,
**kwargs
):
if pad_file_class is None: if pad_file_class is None:
pad_file_class = File pad_file_class = File
filelists_directory = resource_filename(__name__, 'lists') filelists_directory = resource_filename(__name__, "lists")
super(Database, self).__init__( super(Database, self).__init__(
filelists_directory=filelists_directory, name=name, filelists_directory=filelists_directory,
name=name,
original_directory=original_directory, original_directory=original_directory,
pad_file_class=pad_file_class, pad_file_class=pad_file_class,
original_extension=original_extension, original_extension=original_extension,
**kwargs) **kwargs
)
def objects(self, groups=None, protocol=None, purposes=None,
model_ids=None, classes=None, **kwargs): def objects(
self,
groups=None,
protocol=None,
purposes=None,
model_ids=None,
classes=None,
**kwargs
):
files = super(Database, self).objects( files = super(Database, self).objects(
groups=groups, protocol=protocol, purposes=purposes, groups=groups,
model_ids=model_ids, classes=classes, **kwargs) protocol=protocol,
purposes=purposes,
model_ids=model_ids,
classes=classes,
**kwargs
)
for f in files: for f in files:
f.original_directory = self.original_directory f.original_directory = self.original_directory
f.annotation_directory = self.annotation_directory
f.annotation_extension = self.annotation_extension
f.annotation_type = self.annotation_type
return files return files
def frames(self, padfile): def frames(self, padfile):
......
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