Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
py-3d-face-reconstruction
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard Torenvliet
py-3d-face-reconstruction
Commits
1578f00a
Commit
1578f00a
authored
Aug 02, 2016
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement logging system and support debug levels, closes #6
parent
f718b904
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
105 additions
and
77 deletions
+105
-77
actions.mk
actions.mk
+4
-0
src/aam.py
src/aam.py
+2
-9
src/main.py
src/main.py
+6
-9
src/pca.py
src/pca.py
+36
-17
src/reconstruct.py
src/reconstruct.py
+0
-37
src/server.py
src/server.py
+2
-3
src/settings.py
src/settings.py
+53
-0
src/test/aam_test.py
src/test/aam_test.py
+2
-2
No files found.
actions.mk
View file @
1578f00a
...
...
@@ -63,14 +63,18 @@ graph_reconstruction:
--shape_type
imm
\
--n_components
6
.PHONY
:=
test
test
:
python
-m
py.test
-f
src/test/
*
_test.py
.PHONY
:=
server
server
:
(
cd
src/
;
python
-m
tornado.autoreload server.py
)
.PHONY
:=
ember
ember
:
(
cd
viewer
;
ember server
)
;
.PHONY
:=
ctags
ctags
:
ctags
-R
--python-kinds
=
-i
src
src/aam.py
View file @
1578f00a
"""
.. module:: active_appearance_model
:platform: Unix
, Windows
:platform: Unix
:synopsis: Contains the aam data format abstraction layer
"""
import
logging
import
numpy
as
np
from
matplotlib.tri
import
Triangulation
import
cv2
...
...
@@ -13,13 +12,7 @@ import cv2
# local imports
import
pca
import
reconstruction.texture
as
tx
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'%(asctime)s %(levelname)s %(name)s: %(message)s'
)
logger
=
logging
.
getLogger
(
__name__
)
from
settings
import
logger
class
AAMPoints
():
...
...
src/main.py
View file @
1578f00a
#!/usr/local/bin/python
# python std
import
argparse
import
logging
import
importlib
# installed packages
...
...
@@ -14,9 +13,7 @@ import aam
from
reconstruction
import
reconstruction
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'%(asctime)s %(levelname)s %(name)s: %(message)s'
)
logger
=
logging
.
getLogger
(
__name__
)
from
settings
import
logger
def
add_parser_options
():
...
...
@@ -104,7 +101,7 @@ def save_pca_model_texture(args):
assert
args
.
shape_type
,
'--shape_type the type of dataset, see datasets module'
dataset_module
=
import_dataset_module
(
args
.
shape_type
)
shape_model
=
pca
.
P
ca
Model
(
args
.
model_shape_file
)
shape_model
=
pca
.
P
CA
Model
(
args
.
model_shape_file
)
mean_points
=
dataset_module
.
IMMPoints
(
points_list
=
shape_model
.
mean_values
)
textures
=
aam
.
build_texture_feature_vectors
(
...
...
@@ -174,8 +171,8 @@ def generate_call_graph(args):
graphviz
=
GraphvizOutput
(
output_file
=
'filter_none.png'
)
with
PyCallGraph
(
output
=
graphviz
):
shape_model
=
pca
.
P
ca
Model
(
args
.
model_shape_file
)
texture_model
=
pca
.
P
ca
Model
(
args
.
model_texture_file
)
shape_model
=
pca
.
P
CA
Model
(
args
.
model_shape_file
)
texture_model
=
pca
.
P
CA
Model
(
args
.
model_texture_file
)
input_points
=
dataset_module
.
IMMPoints
(
filename
=
'data/imm_face_db/40-3m.asf'
)
input_image
=
input_points
.
get_image
()
...
...
@@ -198,8 +195,8 @@ def show_reconstruction(args):
dataset_module
=
import_dataset_module
(
args
.
shape_type
)
shape_model
=
pca
.
P
ca
Model
(
args
.
model_shape_file
)
texture_model
=
pca
.
P
ca
Model
(
args
.
model_texture_file
)
shape_model
=
pca
.
P
CA
Model
(
args
.
model_shape_file
)
texture_model
=
pca
.
P
CA
Model
(
args
.
model_texture_file
)
input_points
=
dataset_module
.
IMMPoints
(
filename
=
'data/imm_face_db/40-3m.asf'
...
...
src/pca.py
View file @
1578f00a
import
numpy
as
np
from
settings
import
logger
class
PcaModel
:
class
PCAModel
:
"""
Abstraction for a pca model file. The pca model is stored in a numpy file
using numpy.save. The following information is stored:
...
...
@@ -15,7 +17,7 @@ class PcaModel:
Examples:
pca = P
ca
Model(path_to_numpy_model_file)
pca = P
CA
Model(path_to_numpy_model_file)
"""
def
__init__
(
self
,
filename
=
None
):
self
.
filename
=
filename
...
...
@@ -51,8 +53,7 @@ class PcaModel:
assert
hasattr
(
self
,
'mean_values'
)
assert
hasattr
(
self
,
'triangles'
)
saving
=
np
.
asarray
(
[
saving
=
np
.
asarray
([
self
.
Vt
,
self
.
s
,
self
.
n_components
,
...
...
@@ -65,23 +66,23 @@ class PcaModel:
def
load
(
self
):
"""
Loads the numpy file, see P
ca
Model whichs uses this function to load
Loads the numpy file, see P
CA
Model whichs uses this function to load
the PCA Model data.
Returns:
(tuple): Vt, s, n_components, mean_values and triangles
Vt (numpy ndarray): Two dimensional array with dimensions
(n_features, n_features)
n_components: number of components needed to cover .90 percent of
the
variance
mean_values (numpy ndarray): mean values of the features of the
model,
this should have dimensions (n_featur
s, )
n_components: number of components needed to cover .90 percent of
the
variance
mean_values (numpy ndarray): mean values of the features of the
model, this should have dimensions (n_feature
s, )
triangles: a list of lists of indices that form a triangles in the
AAM list.
Examples:
We would advise not to use this function directly but to use the
P
caModel. See the :class:`Pca
Model`
P
CAModel. See the :class:`PCA
Model`
"""
pca_model
=
np
.
load
(
self
.
filename
)
...
...
@@ -94,12 +95,29 @@ class PcaModel:
def
pca
(
data
,
mean_values
,
variance_percentage
=
90
):
"""
Perform Singlar Value Decomposition
Perform Singlar Value Decomposition which we see as a PCA analysis
We calculate how many components are needed to get `variance_percentage`
(default is 90 percent).
Args:
data(ndarray): list of flattened feature vectors.
mean_values(ndarray): mean of all data flattened feature vectors,
in the same order.
Kwargs:
variance_percentage(int): is to calculate how many components you would
need to keep 90 (default is 90) percent of the variance. Note that we
do not alter any data, just return extra information in the form of
`n_components`, so that the user knows how much components it could
keep or to discard to still have 90 percent of the variance.
Returns:
U (ndarray): U matrix
s (ndarray): 1d singular values (diagonal in array form)
Vt (ndarray): Vt matrix
tuple of:
U (ndarray): U matrix
s (ndarray): 1d singular values in flattened form.
Vt (ndarray): Vt matrix
n_components(int): The amount of components that (together) form
`variance_percentage` of variance.
"""
# subtract mean
zero_mean
=
data
-
mean_values
...
...
@@ -115,6 +133,7 @@ def pca(data, mean_values, variance_percentage=90):
i
+=
1
n_components
=
i
logger
.
debug
(
'%s components form %s of the variance'
,
n_components
,
variance_percentage
)
return
U
,
s
,
Vt
,
n_components
...
...
@@ -124,13 +143,13 @@ def reconstruct(feature_vector, Vt, mean_values, n_components=None):
Reconstruct with U, s, Vt
Args:
U (numpy ndarray): One feature vector from the
reduced
SVD.
U (numpy ndarray): One feature vector from the SVD.
U should have shape (n_features,), (i.e., one dimensional)
s (numpy ndarray): The singular values as a one dimensional array
Vt (numpy ndarray): Two dimensional array with dimensions
(n_features, n_features)
mean_values (numpy ndarray): mean values of the features of the
model,
this should have dimensions (n_features, )
mean_values (numpy ndarray): mean values of the features of the
model,
this should have dimensions (n_features, )
"""
...
...
src/reconstruct.py
deleted
100644 → 0
View file @
f718b904
def
reconstruct
(
model_shape_file
,
model_texture_file
,
image
,
asf_file
):
#assert args.model_shape_file, '--model_texture_file needs to be provided to save the pca model'
#assert args.model_texture_file, '--model_texture_file needs to be provided to save the pca model'
Vt_shape
,
s
,
n_shape_components
,
mean_value_points
,
triangles
=
pca
.
load
(
args
.
model_shape_file
)
Vt_texture
,
s_texture
,
n_texture_components
,
mean_values_texture
,
_
=
pca
.
load
(
args
.
model_texture_file
)
InputPoints
=
imm
.
IMMPoints
(
filename
=
asf_file
)
input_image
=
InputPoints
.
get_image
()
MeanPoints
=
imm
.
IMMPoints
(
points_list
=
mean_value_points
)
MeanPoints
.
get_scaled_points
(
input_image
.
shape
)
while
True
:
utils
.
reconstruct_texture
(
input_image
,
# src image
input_image
,
# dst image
Vt_texture
,
# Vt
InputPoints
,
# shape points input
MeanPoints
,
# shape points mean
mean_values_texture
,
# mean texture
triangles
,
# triangles
n_texture_components
# learned n_texture_components
)
dst
=
utils
.
get_texture
(
MeanPoints
,
mean_values_texture
)
cv2
.
imshow
(
'original'
,
InputPoints
.
get_image
())
cv2
.
imshow
(
'reconstructed'
,
input_image
)
cv2
.
imshow
(
'main face'
,
dst
)
k
=
cv2
.
waitKey
(
0
)
&
0xFF
if
k
==
27
:
break
cv2
.
destroyAllWindows
()
src/server.py
View file @
1578f00a
import
json
import
os.path
import
base64
from
cStringIO
import
StringIO
from
glob
import
glob
import
cv2
...
...
@@ -31,8 +30,8 @@ class ImageWebSocketHandler(websocket.WebSocketHandler):
model_texture_file
=
'{}/pca_texture_model.npy'
.
format
(
FILES_DIR
)
model_shape_file
=
'{}/pca_shape_model.npy'
.
format
(
FILES_DIR
)
self
.
shape_model
=
pca
.
P
ca
Model
(
model_shape_file
)
self
.
texture_model
=
pca
.
P
ca
Model
(
model_texture_file
)
self
.
shape_model
=
pca
.
P
CA
Model
(
model_shape_file
)
self
.
texture_model
=
pca
.
P
CA
Model
(
model_texture_file
)
websocket
.
WebSocketHandler
.
__init__
(
self
,
*
args
,
**
kwargs
)
...
...
src/settings.py
0 → 100644
View file @
1578f00a
"""
.. module:: settings_module
:platform: Unix
:synopsis: This module contains global settings.
"""
import
logging
import
logging.config
import
os
#logging.basicConfig(level=logging.INFO,
# format='%(asctime)s %(levelname)s %(name)s: %(message)s')
logging
.
config
.
dictConfig
({
'version'
:
1
,
'disable_existing_loggers'
:
False
,
# this fixes the problem
'formatters'
:
{
'standard'
:
{
'format'
:
'%(asctime)s %(levelname)s %(module)s: %(message)s'
},
},
'handlers'
:
{
'default'
:
{
'level'
:
logging
.
INFO
,
'formatter'
:
'standard'
,
'class'
:
'logging.StreamHandler'
,
},
'debug'
:
{
'level'
:
logging
.
DEBUG
,
'formatter'
:
'standard'
,
'class'
:
'logging.StreamHandler'
,
},
},
'loggers'
:
{
'root'
:
{
'handlers'
:
[
'default'
],
'level'
:
logging
.
INFO
,
'propagate'
:
True
},
'debug'
:
{
'handlers'
:
[
'debug'
],
'level'
:
logging
.
DEBUG
,
'propagate'
:
False
}
}
})
logger
=
logging
.
getLogger
(
'root'
)
#logger.setLevel(logging.DEBUG)
if
os
.
environ
.
get
(
'DEBUG'
,
False
):
logger
=
logging
.
getLogger
(
'debug'
)
src/test/aam_test.py
View file @
1578f00a
...
...
@@ -48,8 +48,8 @@ def test_zero_mean_aan():
def
test_build_texture_feature_vectors
():
shape_model
=
pca
.
P
ca
Model
(
'data/test_data/pca_shape_model.npy'
)
texture_model
=
pca
.
P
ca
Model
(
'data/test_data/pca_texture_model.npy'
)
shape_model
=
pca
.
P
CA
Model
(
'data/test_data/pca_shape_model.npy'
)
texture_model
=
pca
.
P
CA
Model
(
'data/test_data/pca_texture_model.npy'
)
input_points
=
imm
.
IMMPoints
(
filename
=
'data/imm_face_db/40-3m.asf'
)
input_image
=
input_points
.
get_image
()
...
...
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