Skip to content
Snippets Groups Projects
Commit de1de71d authored by Ketan Kotwal's avatar Ketan Kotwal
Browse files

script, corrected protocols

parent e82dfd56
Branches
No related tags found
No related merge requests found
Showing
with 57 additions and 39 deletions
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
*.swp *.swp
*.pyc *.pyc
bin bin
build
eggs eggs
parts parts
.installed.cfg .installed.cfg
......
...@@ -15,25 +15,24 @@ sub_directory = "pooling_lr" ...@@ -15,25 +15,24 @@ sub_directory = "pooling_lr"
from bob.pad.face.preprocessor import FaceCropAlign from bob.pad.face.preprocessor import FaceCropAlign
from bob.bio.video.preprocessor import Wrapper from bob.bio.video.preprocessor import Wrapper
from bob.bio.video.utils import FrameSelector from bob.bio.video.utils import FrameSelector
from bob.pad.face.preprocessor.FaceCropAlign import auto_norm_image as _norm_func
# parameters and constants # parameters and constants
FACE_SIZE = 128 FACE_SIZE = 128
RGB_OUTPUT_FLAG = False RGB_OUTPUT_FLAG = False
USE_FACE_ALIGNMENT = True USE_FACE_ALIGNMENT = True
ALIGNMENT_TYPE = "lightcnn" ALIGNMENT_TYPE = "lightcnn"
MAX_IMAGE_SIZE = None
FACE_DETECTION_METHOD = None
MIN_FACE_SIZE = 50 MIN_FACE_SIZE = 50
NORMALIZATION_FUNCTION = _norm_func
NORMALIZATION_FUNCTION_KWARGS = {'n_sigma':3.0, 'norm_method':'MAD'}
_image_preprocessor = FaceCropAlign(face_size=FACE_SIZE, _image_preprocessor = FaceCropAlign(face_size=FACE_SIZE,
rgb_output_flag=RGB_OUTPUT_FLAG, rgb_output_flag=RGB_OUTPUT_FLAG,
use_face_alignment=USE_FACE_ALIGNMENT, use_face_alignment=USE_FACE_ALIGNMENT,
alignment_type=ALIGNMENT_TYPE, alignment_type=ALIGNMENT_TYPE,
max_image_size=MAX_IMAGE_SIZE,
face_detection_method=FACE_DETECTION_METHOD,
min_face_size=MIN_FACE_SIZE, min_face_size=MIN_FACE_SIZE,
) normalization_function = NORMALIZATION_FUNCTION,
normalization_function_kwargs = NORMALIZATION_FUNCTION_KWARGS)
_frame_selector = FrameSelector(selection_style = "all") _frame_selector = FrameSelector(selection_style = "all")
...@@ -49,7 +48,7 @@ from bob.bio.video.extractor import Wrapper ...@@ -49,7 +48,7 @@ from bob.bio.video.extractor import Wrapper
from bob.extension import rc from bob.extension import rc
import os import os
_model_directory = rc["lightcnn9.model.directory"] _model_directory = rc["lightcnn9.model_directory"]
_model_name = "LightCNN_9Layers_checkpoint.pth.tar" _model_name = "LightCNN_9Layers_checkpoint.pth.tar"
_model_file = os.path.join(_model_directory, _model_name) _model_file = os.path.join(_model_directory, _model_name)
......
#!/bin/bash
set -ex
echo "Run experiments from ICIP 2020 paper"
echo "-----------------------------------"
expt="wmca"
base_directory="/idiap/temp/kkotwal/icip20/expt"
# expt: WMCA
if [[ "${expt}" == "wmca" ]]; then
output_directory="${base_directory}/wmca"
db_config="wmca_mask.py"
protocol="grandtest"
elif [[ "${expt}" == "mlfp" ]]; then
output_directory="${base_directory}/mlfp"
db_config="mlfp.py"
protocol="cv1"
else
echo "Unknown expt"
exit -1
fi
cmd="spoof.py ${db_config} patch_pooling_lr.py -s ${output_directory} -vv --grid idiap"
#echo ${cmd}
$cmd
cmd="bob pad metriics -v -e ${output_directory}/${protocol}/scores/scores-{dev,eval}"
echo ${cmd}
#$cmd
#--------------
from .wmca_mask import WMCAMask
from .mlfp import MLFPDatabase
...@@ -12,11 +12,9 @@ from bob.pad.face.database.batl import BatlPadFile ...@@ -12,11 +12,9 @@ from bob.pad.face.database.batl import BatlPadFile
from bob.db.batl.models import VideoFile from bob.db.batl.models import VideoFile
from bob.extension import rc from bob.extension import rc
from bob.bio.video.utils import FrameSelector from bob.bio.video.utils import FrameSelector
from bob.pad.face.preprocessor.FaceCropAlign import detect_face_landmarks_in_image
import os import os
import json import json
from bob.io.base import create_directories_safe
import pkg_resources import pkg_resources
...@@ -57,7 +55,6 @@ class WMCAMask(FileListPadDatabase): ...@@ -57,7 +55,6 @@ class WMCAMask(FileListPadDatabase):
original_extension = ".h5", original_extension = ".h5",
protocol = "grandtest", protocol = "grandtest",
annotation_directory = None, annotation_directory = None,
landmark_detect_method = "mtcnn",
pad_file_class = BatlPadFile, pad_file_class = BatlPadFile,
low_level_pad_file_class = File, low_level_pad_file_class = File,
**kwargs, **kwargs,
...@@ -149,7 +146,7 @@ class WMCAMask(FileListPadDatabase): ...@@ -149,7 +146,7 @@ class WMCAMask(FileListPadDatabase):
# create objects for each file where the class is BATLPadFile # create objects for each file where the class is BATLPadFile
# aux information # aux information
stream_type = "nir" stream_type = "infrared" # nir => infrared
num_frames = 50 num_frames = 50
files = [self.pad_file_class(f=f, stream_type=stream_type, files = [self.pad_file_class(f=f, stream_type=stream_type,
...@@ -162,8 +159,7 @@ class WMCAMask(FileListPadDatabase): ...@@ -162,8 +159,7 @@ class WMCAMask(FileListPadDatabase):
def annotations(self, f): def annotations(self, f):
""" """
Returns annotations for a given file object ``f``. Returns annotations for a given file object ``f``.
If annotations do not exist, these will be computed and saved in annotation_ Annotations must be precomputed.
directory.
**Parameters:** **Parameters:**
...@@ -187,38 +183,19 @@ class WMCAMask(FileListPadDatabase): ...@@ -187,38 +183,19 @@ class WMCAMask(FileListPadDatabase):
file_path = os.path.join(self.annotation_directory, f.f.path + ".json") file_path = os.path.join(self.annotation_directory, f.f.path + ".json")
# if annotations exist, load from file_path
if os.path.isfile(file_path): if os.path.isfile(file_path):
with open(file_path, "r") as json_file: with open(file_path, "r") as json_file:
annotations = json.load(json_file) annotations = json.load(json_file)
else: if not annotations: # if dictionary is empty
logger.warning("Empty annotations for %s", f.path)
# find and save annotations return None
annotations = {}
video = f.load(directory=self.original_directory, extension=self.original_extension)
for idx, image in enumerate(video.as_array()):
frame_annotations = detect_face_landmarks_in_image(image, method=self.landmark_detect_method)
if frame_annotations:
annotations[str(idx)] = frame_annotations
# save to file_path
create_directories_safe(directory=os.path.split(file_path)[0], dryrun=False)
with open(file_path, 'w+') as json_file:
json_file.write(json.dumps(annotations))
return annotations
if not annotations: # if dictionary is empty else:
logger.warning("Empty annotations for {}".format(f.path)) logger.warning("Annotation file for %s does not exist. (Overall path: %s)", f.path, file_path)
return None return None
return annotations
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
from .patch_pooling_cnn import PatchPoolingCNN
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment