Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.pytorch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.pytorch
Merge requests
!30
Mc deep pixbis
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Mc deep pixbis
mc_deep_pixbis
into
master
Overview
0
Commits
4
Pipelines
1
Changes
5
Merged
Anjith GEORGE
requested to merge
mc_deep_pixbis
into
master
6 years ago
Overview
0
Commits
4
Pipelines
1
Changes
5
Expand
Adds a net architecture, extractor and tests
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
6d142c3b
4 commits,
6 years ago
5 files
+
234
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
bob/learn/pytorch/architectures/MCDeepPixBiS.py
0 → 100644
+
102
−
0
Options
import
torch
from
torch
import
nn
from
torchvision
import
models
import
numpy
as
np
class
MCDeepPixBiS
(
nn
.
Module
):
"""
The class defining Multi-Channel Deep Pixelwise Binary Supervision for Face Presentation
Attack Detection:
This extends the following paper to multi-channel/ multi-spectral images with cross modal pretraining.
Reference: Anjith George and Sébastien Marcel.
"
Deep Pixel-wise Binary Supervision for
Face Presentation Attack Detection.
"
In 2019 International Conference on Biometrics (ICB).IEEE, 2019.
The initialization uses `Cross modality pre-training` idea from the following paper:
Wang L, Xiong Y, Wang Z, Qiao Y, Lin D, Tang X, Van Gool L. Temporal segment networks:
Towards good practices for deep action recognition. InEuropean conference on computer
vision 2016 Oct 8 (pp. 20-36). Springer, Cham.
Attributes
----------
pretrained: bool
If set to `True` uses the pretrained DenseNet model as the base. If set to `False`, the network
will be trained from scratch.
default: True
num_channels: int
Number of channels in the input.
"""
def
__init__
(
self
,
pretrained
=
True
,
num_channels
=
4
):
"""
Init function
Parameters
----------
pretrained: bool
If set to `True` uses the pretrained densenet model as the base. Else, it uses the default network
default: True
num_channels: int
Number of channels in the input.
"""
super
(
MCDeepPixBiS
,
self
).
__init__
()
dense
=
models
.
densenet161
(
pretrained
=
pretrained
)
features
=
list
(
dense
.
features
.
children
())
temp_layer
=
features
[
0
]
# No bias in this architecture
mean_weight
=
np
.
mean
(
temp_layer
.
weight
.
data
.
detach
().
numpy
(),
axis
=
1
)
# for 96 filters
new_weight
=
np
.
zeros
((
96
,
num_channels
,
7
,
7
))
for
i
in
range
(
num_channels
):
new_weight
[:,
i
,:,:]
=
mean_weight
features
[
0
]
=
nn
.
Conv2d
(
num_channels
,
96
,
kernel_size
=
(
7
,
7
),
stride
=
(
2
,
2
),
padding
=
(
3
,
3
),
bias
=
False
)
features
[
0
].
weight
.
data
=
torch
.
Tensor
(
new_weight
)
self
.
enc
=
nn
.
Sequential
(
*
features
[
0
:
8
])
self
.
dec
=
nn
.
Conv2d
(
384
,
1
,
kernel_size
=
1
,
padding
=
0
)
self
.
linear
=
nn
.
Linear
(
14
*
14
,
1
)
def
forward
(
self
,
x
):
"""
Propagate data through the network
Parameters
----------
img: :py:class:`torch.Tensor`
The data to forward through the network. Expects Multi-channel images of size num_channelsx224x224
Returns
-------
dec: :py:class:`torch.Tensor`
Binary map of size 1x14x14
op: :py:class:`torch.Tensor`
Final binary score.
"""
enc
=
self
.
enc
(
x
)
dec
=
self
.
dec
(
enc
)
dec
=
nn
.
Sigmoid
()(
dec
)
dec_flat
=
dec
.
view
(
-
1
,
14
*
14
)
op
=
self
.
linear
(
dec_flat
)
op
=
nn
.
Sigmoid
()(
op
)
return
dec
,
op
Loading