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
!26
WIP: Generic trainer
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
WIP: Generic trainer
generic_trainer
into
master
Overview
4
Commits
11
Pipelines
4
Changes
3
Closed
Anjith GEORGE
requested to merge
generic_trainer
into
master
6 years ago
Overview
4
Commits
11
Pipelines
4
Changes
3
Expand
Adds a generic trainer class and trainer script
Moved the model specific stuff to config files; example config added
uses
.to(device)
throughout
0
0
Merge request reports
Viewing commit
a8f3eca1
Prev
Next
Show latest version
3 files
+
263
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
a8f3eca1
more configs
· a8f3eca1
Anjith GEORGE
authored
6 years ago
bob/learn/pytorch/config/generic/extractor_configs/wmca_deep_mspad.py
0 → 100644
+
116
−
0
Options
# =============================================================================
# define instance of the preprocessor:
from
bob.pad.face.preprocessor
import
VideoFaceCropAlignBlockPatch
from
bob.pad.face.preprocessor
import
FaceCropAlign
from
bob.bio.video.preprocessor
import
Wrapper
from
bob.bio.video.utils
import
FrameSelector
from
torchvision
import
transforms
import
numpy
as
np
from
bob.pad.face.database
import
BatlPadDatabase
from
bob.learn.pytorch.datasets
import
ChannelSelect
,
RandomHorizontalFlipImage
FACE_SIZE
=
224
# The size of the resulting face
RGB_OUTPUT_FLAG
=
True
# RGB output
USE_FACE_ALIGNMENT
=
True
# use annotations
MAX_IMAGE_SIZE
=
None
# no limiting here
FACE_DETECTION_METHOD
=
'
mtcnn
'
# use annotations
MIN_FACE_SIZE
=
50
# skip small faces
ALIGNMENT_TYPE
=
'
default
'
_image_preprocessor
=
FaceCropAlign
(
face_size
=
FACE_SIZE
,
rgb_output_flag
=
RGB_OUTPUT_FLAG
,
use_face_alignment
=
USE_FACE_ALIGNMENT
,
alignment_type
=
ALIGNMENT_TYPE
,
max_image_size
=
MAX_IMAGE_SIZE
,
face_detection_method
=
FACE_DETECTION_METHOD
,
min_face_size
=
MIN_FACE_SIZE
)
_frame_selector
=
FrameSelector
(
selection_style
=
"
all
"
)
preprocessor
=
Wrapper
(
preprocessor
=
_image_preprocessor
,
frame_selector
=
_frame_selector
)
#====================================================================================
# DeepPixBiS Extractor
from
bob.learn.pytorch.extractor.image
import
GenericExtractor
from
bob.learn.pytorch.architectures
import
DeepMSPAD
from
bob.bio.video.extractor
import
Wrapper
MODEL_FILE
=
'
/idiap/temp/ageorge/Pytorch_WMCA/Generic-DeepMSPAD/model_0_0.pth
'
####################################################################
SCORING_METHOD
=
'
pixel_mean
'
# 'pixel_mean','binary','combined'
SELECTED_CHANNELS
=
[
0
,
1
,
2
,
3
]
####################################################################
_img_transform
=
transforms
.
Compose
([
ChannelSelect
(
selected_channels
=
SELECTED_CHANNELS
),
transforms
.
ToPILImage
(),
transforms
.
Resize
((
224
,
224
),
interpolation
=
2
),
transforms
.
ToTensor
()])
def
extractor_function
(
output
,
kwargs
):
output_pixel
=
output
.
data
.
numpy
().
flatten
()
score
=
np
.
mean
(
output_pixel
)
return
score
network
=
DeepMSPAD
(
pretrained
=
True
,
num_channels
=
4
)
_image_extracor
=
GenericExtractor
(
network
=
network
,
extractor_function
=
extractor_function
,
transforms
=
_img_transform
,
model_file
=
MODEL_FILE
,
scoring_method
=
'
pixel_mean
'
)
_frame_selector
=
FrameSelector
(
selection_style
=
"
all
"
)
extractor
=
Wrapper
(
_image_extracor
,
frame_selector
=
_frame_selector
)
#=======================================================================================
# define algorithm:
# Dummy algorithm
from
bob.pad.base.algorithm
import
Algorithm
class
DummyAlgorithm
(
Algorithm
):
"""
An algorithm that takes the precomputed predictions and uses them for
scoring.
"""
def
__init__
(
self
,
**
kwargs
):
super
(
DummyAlgorithm
,
self
).
__init__
(
**
kwargs
)
def
project
(
self
,
feature
):
# print("feature",feature.as_array())
return
feature
.
as_array
().
reshape
(
-
1
,
1
)
def
score_for_multiple_projections
(
self
,
predictions
):
# one node at the output
return
list
(
predictions
)
def
score
(
self
,
predictions
):
return
list
(
predictions
)
algorithm
=
DummyAlgorithm
(
performs_projection
=
True
,
requires_projector_training
=
False
)
Loading