Skip to content
Snippets Groups Projects

MLPAlgorithm PAD algorithm V1 version

Merged Olegs NIKISINS requested to merge mlp_algorithm into master
Files
6
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 
"""
 
@author: Olegs Nikisins
 
"""
 
#==============================================================================
 
# Import here:
 
 
import numpy as np
 
 
import torch
 
 
 
#==============================================================================
 
# Define parameters here:
 
 
"""
 
Transformations to be applied to the input 1D numpy arrays (feature vectors).
 
Here, for demonstrative purposes, the transformation is mean std-normalization,
 
where mean and std values are just numpy generated vectors. In real applications,
 
normalizers must be computed in the meaningfull way. This config is just for
 
test purposes.
 
"""
 
 
def transform(x):
 
"""
 
Transformation function applying dummy mean-std normalization and converting
 
input numpy feature vectors to PyTorch tensors, making them compatible with
 
MLP.
 
 
Arguments
 
---------
 
x : numpy array
 
1D numpy array / feature vector.
 
 
Return
 
------
 
x_transform : Tensor
 
Torch tensor, transformed ``x`` to be used as MLP input.
 
"""
 
 
features_mean = np.zeros(x.shape)
 
 
features_std = np.ones(x.shape)
 
 
x_norm = (x - features_mean) / features_std
 
 
x_norm.squeeze()
 
 
return torch.Tensor(x_norm).unsqueeze(0)
 
 
 
"""
 
Define the network to be trained as a class, named ``Network``.
 
Note: Do not change the name of the below class, always import as ``Network``.
 
"""
 
 
from bob.learn.pytorch.architectures import TwoLayerMLP as Network
 
 
 
"""
 
kwargs to be used for ``Network`` initialization. The name must be ``network_kwargs``.
 
"""
 
network_kwargs = {}
 
network_kwargs['in_features'] = 100
 
network_kwargs['n_hidden_relu'] = 10
 
network_kwargs['apply_sigmoid'] = False # don't use sigmoid to make the scores more even
 
 
Loading