Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.pad.face
Commits
a66e1f3c
Commit
a66e1f3c
authored
Apr 25, 2018
by
Amir MOHAMMADI
Browse files
Add more options to the giant video loader
parent
72035ee5
Pipeline
#19437
failed with stage
in 24 minutes and 22 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/pad/face/utils/__init__.py
View file @
a66e1f3c
from
.load_utils
import
(
frames
,
number_of_frames
,
yield_frames
,
yield_faces
,
scale_face
,
blocks
,
bbx_cropper
,
min_face_size_normalizer
,
the_giant_video_loader
)
bbx_cropper
,
min_face_size_normalizer
,
color_augmentation
,
the_giant_video_loader
)
# gets sphinx autodoc done right - don't remove it
__all__
=
[
_
for
_
in
dir
()
if
not
_
.
startswith
(
'_'
)]
bob/pad/face/utils/load_utils.py
View file @
a66e1f3c
...
...
@@ -2,6 +2,7 @@ from bob.bio.face.annotator import min_face_size_validator
from
bob.bio.video.annotator
import
normalize_annotations
from
bob.io.video
import
reader
from
bob.ip.base
import
scale
,
block
,
block_output_shape
from
bob.ip.color
import
rgb_to_yuv
,
rgb_to_hsv
from
bob.ip.facedetect
import
bounding_box_from_annotation
from
functools
import
partial
import
numpy
...
...
@@ -192,16 +193,73 @@ def blocks(data, block_size, block_overlap=(0, 0)):
return
output
def
color_augmentation
(
image
,
channels
=
(
'rgb'
,)):
"""Converts an RGB image to different color channels.
Parameters
----------
image : numpy.array
The image in RGB Bob format.
channels : tuple, optional
List of channels to convert the image to. It can be any of ``rgb``,
``yuv``, ``hsv``.
Returns
-------
numpy.array
The image that contains several channels:
``(3*len(channels), height, width)``.
"""
final_image
=
[]
if
'rgb'
in
channels
:
final_image
.
append
(
image
)
if
'yuv'
in
channels
:
final_image
.
append
(
rgb_to_yuv
(
image
))
if
'hsv'
in
channels
:
final_image
.
append
(
rgb_to_hsv
(
image
))
return
numpy
.
concatenate
(
final_image
,
axis
=
0
)
def
_random_sample
(
A
,
size
):
return
A
[
numpy
.
random
.
choice
(
A
.
shape
[
0
],
size
,
replace
=
False
),
...]
def
the_giant_video_loader
(
paddb
,
padfile
,
region
=
'whole'
,
scaling_factor
=
None
,
cropper
=
None
,
normalizer
=
None
):
generator
=
None
normalizer
=
None
,
patches
=
False
,
block_size
=
(
96
,
96
),
block_overlap
=
(
0
,
0
),
random_patches_per_frame
=
None
,
augment
=
None
,
multiple_bonafide_patches
=
1
):
if
region
==
'whole'
:
generator
=
yield_frames
(
paddb
,
padfile
)
elif
region
==
'crop'
:
generator
=
yield_faces
(
paddb
,
padfile
,
cropper
=
cropper
,
normalizer
=
normalizer
)
else
:
raise
ValueError
(
"Invalid region value: `{}'"
.
format
(
region
))
if
scaling_factor
is
not
None
:
generator
=
(
scale
(
frame
,
scaling_factor
)
for
frame
in
generator
)
if
patches
:
if
random_patches_per_frame
is
None
:
generator
=
(
patch
for
frame
in
generator
for
patch
in
blocks
(
frame
,
block_size
,
block_overlap
))
else
:
if
padfile
.
attack_type
is
None
:
random_patches_per_frame
*=
multiple_bonafide_patches
generator
=
(
patch
for
frame
in
generator
for
patch
in
_random_sample
(
blocks
(
frame
,
block_size
,
block_overlap
),
random_patches_per_frame
))
if
augment
is
not
None
:
generator
=
(
augment
(
frame
)
for
frame
in
generator
)
return
generator
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment