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
Commits
0312870b
Commit
0312870b
authored
6 years ago
by
Anjith GEORGE
Committed by
Anjith GEORGE
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Cross modality pre-training for MS PAD
parent
61de6575
No related branches found
No related tags found
1 merge request
!24
Deep mspad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/pytorch/architectures/DeepMSPAD.py
+41
-12
41 additions, 12 deletions
bob/learn/pytorch/architectures/DeepMSPAD.py
with
41 additions
and
12 deletions
bob/learn/pytorch/architectures/DeepMSPAD.py
+
41
−
12
View file @
0312870b
import
torch
from
torch
import
nn
from
torchvision
import
models
import
numpy
as
np
class
DeepMSPAD
(
nn
.
Module
):
"""
Deep multispectral PAD algorithm
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 `True` loads the pretrained vgg16 model.
...
...
@@ -44,19 +52,40 @@ class DeepMSPAD(nn.Module):
features
=
list
(
vgg
.
features
.
children
())
features
[
0
]
=
nn
.
Conv2d
(
num_channels
,
64
,
kernel_size
=
(
3
,
3
),
stride
=
(
1
,
1
),
padding
=
(
1
,
1
))
# temp layer to extract weights
temp_layer
=
features
[
0
]
# Implements ``Cross modality pre-training``
# Mean of weight and bias for all filters
bias_values
=
temp_layer
.
bias
.
data
.
detach
().
numpy
()
mean_weight
=
np
.
mean
(
temp_layer
.
weight
.
data
.
detach
().
numpy
(),
axis
=
1
)
# for 64 filters
new_weight
=
np
.
zeros
((
64
,
num_channels
,
3
,
3
))
for
i
in
range
(
num_channels
):
new_weight
[:,
i
,:,:]
=
mean_weight
# initialize new layer with required number of channels `num_channels`
features
[
0
]
=
nn
.
Conv2d
(
num_channels
,
64
,
kernel_size
=
(
3
,
3
),
stride
=
(
1
,
1
),
padding
=
(
1
,
1
))
features
[
0
].
weight
.
data
=
torch
.
Tensor
(
new_weight
)
features
[
0
].
bias
.
data
=
torch
.
Tensor
(
bias_values
)
#check
self
.
enc
=
nn
.
Sequential
(
*
features
)
self
.
linear1
=
nn
.
Linear
(
25088
,
256
)
self
.
linear1
=
nn
.
Linear
(
25088
,
256
)
self
.
relu
=
nn
.
ReLU
()
self
.
relu
=
nn
.
ReLU
()
self
.
dropout
=
nn
.
Dropout
(
p
=
0.5
)
self
.
dropout
=
nn
.
Dropout
(
p
=
0.5
)
self
.
linear2
=
nn
.
Linear
(
256
,
1
)
self
.
linear2
=
nn
.
Linear
(
256
,
1
)
self
.
sigmoid
=
nn
.
Sigmoid
()
self
.
sigmoid
=
nn
.
Sigmoid
()
def
forward
(
self
,
x
):
...
...
@@ -76,16 +105,16 @@ class DeepMSPAD(nn.Module):
enc
=
self
.
enc
(
x
)
x
=
enc
.
view
(
-
1
,
25088
)
x
=
enc
.
view
(
-
1
,
25088
)
x
=
self
.
linear1
(
x
)
x
=
self
.
linear1
(
x
)
x
=
self
.
relu
(
x
)
x
=
self
.
relu
(
x
)
x
=
self
.
dropout
(
x
)
x
=
self
.
dropout
(
x
)
x
=
self
.
linear2
(
x
)
x
=
self
.
linear2
(
x
)
x
=
self
.
sigmoid
(
x
)
x
=
self
.
sigmoid
(
x
)
return
x
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment