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.learn.em
Commits
c9ae99c8
Commit
c9ae99c8
authored
Mar 01, 2015
by
Tiago de Freitas Pereira
Browse files
Solved more memory leaks
parent
e6470b33
Changes
10
Hide whitespace changes
Inline
Side-by-side
bob/learn/em/empca_trainer.cpp
View file @
c9ae99c8
...
...
@@ -155,7 +155,7 @@ PyObject* PyBobLearnEMEMPCATrainer_getRng(PyBobLearnEMEMPCATrainerObject* self,
(
PyBoostMt19937Object
*
)
PyBoostMt19937_Type
.
tp_alloc
(
&
PyBoostMt19937_Type
,
0
);
retval
->
rng
=
self
->
cxx
->
getRng
().
get
();
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"Rng method could not be read"
,
0
)
}
int
PyBobLearnEMEMPCATrainer_setRng
(
PyBobLearnEMEMPCATrainerObject
*
self
,
PyObject
*
value
,
void
*
)
{
...
...
bob/learn/em/isv_base.cpp
View file @
c9ae99c8
...
...
@@ -267,7 +267,7 @@ PyObject* PyBobLearnEMISVBase_getUBM(PyBobLearnEMISVBaseObject* self, void*){
(
PyBobLearnEMGMMMachineObject
*
)
PyBobLearnEMGMMMachine_Type
.
tp_alloc
(
&
PyBobLearnEMGMMMachine_Type
,
0
);
retval
->
cxx
=
ubm_gmmMachine
;
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"ubm could not be read"
,
0
)
}
int
PyBobLearnEMISVBase_setUBM
(
PyBobLearnEMISVBaseObject
*
self
,
PyObject
*
value
,
void
*
){
...
...
bob/learn/em/isv_machine.cpp
View file @
c9ae99c8
...
...
@@ -242,7 +242,7 @@ PyObject* PyBobLearnEMISVMachine_getISVBase(PyBobLearnEMISVMachineObject* self,
(
PyBobLearnEMISVBaseObject
*
)
PyBobLearnEMISVBase_Type
.
tp_alloc
(
&
PyBobLearnEMISVBase_Type
,
0
);
retval
->
cxx
=
isv_base_o
;
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"isv_base could not be read"
,
0
)
}
int
PyBobLearnEMISVMachine_setISVBase
(
PyBobLearnEMISVMachineObject
*
self
,
PyObject
*
value
,
void
*
){
...
...
bob/learn/em/isv_trainer.cpp
View file @
c9ae99c8
...
...
@@ -340,7 +340,7 @@ PyObject* PyBobLearnEMISVTrainer_getRng(PyBobLearnEMISVTrainerObject* self, void
(
PyBoostMt19937Object
*
)
PyBoostMt19937_Type
.
tp_alloc
(
&
PyBoostMt19937_Type
,
0
);
retval
->
rng
=
self
->
cxx
->
getRng
().
get
();
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"Rng method could not be read"
,
0
)
}
int
PyBobLearnEMISVTrainer_setRng
(
PyBobLearnEMISVTrainerObject
*
self
,
PyObject
*
value
,
void
*
)
{
...
...
bob/learn/em/jfa_base.cpp
View file @
c9ae99c8
...
...
@@ -302,7 +302,7 @@ PyObject* PyBobLearnEMJFABase_getUBM(PyBobLearnEMJFABaseObject* self, void*){
(
PyBobLearnEMGMMMachineObject
*
)
PyBobLearnEMGMMMachine_Type
.
tp_alloc
(
&
PyBobLearnEMGMMMachine_Type
,
0
);
retval
->
cxx
=
ubm_gmmMachine
;
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"ubm could not be read"
,
0
)
}
int
PyBobLearnEMJFABase_setUBM
(
PyBobLearnEMJFABaseObject
*
self
,
PyObject
*
value
,
void
*
){
...
...
bob/learn/em/jfa_machine.cpp
View file @
c9ae99c8
...
...
@@ -271,7 +271,7 @@ PyObject* PyBobLearnEMJFAMachine_getJFABase(PyBobLearnEMJFAMachineObject* self,
(
PyBobLearnEMJFABaseObject
*
)
PyBobLearnEMJFABase_Type
.
tp_alloc
(
&
PyBobLearnEMJFABase_Type
,
0
);
retval
->
cxx
=
jfa_base_o
;
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"jfa_base could not be read"
,
0
)
}
int
PyBobLearnEMJFAMachine_setJFABase
(
PyBobLearnEMJFAMachineObject
*
self
,
PyObject
*
value
,
void
*
){
...
...
bob/learn/em/jfa_trainer.cpp
View file @
c9ae99c8
...
...
@@ -446,7 +446,7 @@ PyObject* PyBobLearnEMJFATrainer_getRng(PyBobLearnEMJFATrainerObject* self, void
(
PyBoostMt19937Object
*
)
PyBoostMt19937_Type
.
tp_alloc
(
&
PyBoostMt19937_Type
,
0
);
retval
->
rng
=
self
->
cxx
->
getRng
().
get
();
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"Rng method could not be read"
,
0
)
}
int
PyBobLearnEMJFATrainer_setRng
(
PyBobLearnEMJFATrainerObject
*
self
,
PyObject
*
value
,
void
*
)
{
...
...
bob/learn/em/kmeans_trainer.cpp
View file @
c9ae99c8
...
...
@@ -281,7 +281,7 @@ PyObject* PyBobLearnEMKMeansTrainer_getRng(PyBobLearnEMKMeansTrainerObject* self
(
PyBoostMt19937Object
*
)
PyBoostMt19937_Type
.
tp_alloc
(
&
PyBoostMt19937_Type
,
0
);
retval
->
rng
=
self
->
cxx
->
getRng
().
get
();
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"Rng method could not be read"
,
0
)
}
int
PyBobLearnEMKMeansTrainer_setRng
(
PyBobLearnEMKMeansTrainerObject
*
self
,
PyObject
*
value
,
void
*
)
{
...
...
bob/learn/em/plda_machine.cpp
View file @
c9ae99c8
...
...
@@ -248,7 +248,7 @@ PyObject* PyBobLearnEMPLDAMachine_getPLDABase(PyBobLearnEMPLDAMachineObject* sel
(
PyBobLearnEMPLDABaseObject
*
)
PyBobLearnEMPLDABase_Type
.
tp_alloc
(
&
PyBobLearnEMPLDABase_Type
,
0
);
retval
->
cxx
=
plda_base_o
;
return
Py_BuildValue
(
"
O
"
,
retval
);
return
Py_BuildValue
(
"
N
"
,
retval
);
BOB_CATCH_MEMBER
(
"plda_base could not be read"
,
0
)
}
int
PyBobLearnEMPLDAMachine_setPLDABase
(
PyBobLearnEMPLDAMachineObject
*
self
,
PyObject
*
value
,
void
*
){
...
...
@@ -642,21 +642,28 @@ static PyObject* PyBobLearnEMPLDAMachine_computeLogLikelihood(PyBobLearnEMPLDAMa
BOB_TRY
char
**
kwlist
=
compute_log_likelihood
.
kwlist
(
0
);
PyBlitzArrayObject
*
samples
;
PyArrayObject
*
numpy_samples
;
PyObject
*
with_enrolled_samples
=
Py_True
;
/*Convert to PyObject first to access the number of dimensions*/
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O!|O!"
,
kwlist
,
&
PyArray_Type
,
&
numpy_samples
,
&
PyBool_Type
,
&
with_enrolled_samples
))
return
0
;
auto
numpy_samples_
=
make_safe
(
numpy_samples
);
Py_INCREF
(
numpy_samples
);
int
dim
=
PyArray_NDIM
(
numpy_samples
);
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O&|O!"
,
kwlist
,
&
PyBlitzArray_Converter
,
&
samples
,
&
PyBool_Type
,
&
with_enrolled
_samples
))
return
0
;
/*Now converting to PyBlitzArrayObject*/
samples
=
reinterpret_cast
<
PyBlitzArrayObject
*>
(
PyBlitzArray_FromNumpyArray
(
numpy
_samples
));
auto
samples_
=
make_safe
(
samples
);
blitz
::
Array
<
double
,
2
>
blitz_test
=
*
PyBlitzArrayCxx_AsBlitz
<
double
,
2
>
(
samples
);
//There are 2 methods in C++, one <double,1> and the another <double,2>
if
(
blitz_test
.
extent
(
1
)
==
0
)
/*Using the proper method according to the dimension*/
if
(
dim
==
1
)
return
Py_BuildValue
(
"d"
,
self
->
cxx
->
computeLogLikelihood
(
*
PyBlitzArrayCxx_AsBlitz
<
double
,
1
>
(
samples
),
f
(
with_enrolled_samples
)));
else
return
Py_BuildValue
(
"d"
,
self
->
cxx
->
computeLogLikelihood
(
*
PyBlitzArrayCxx_AsBlitz
<
double
,
2
>
(
samples
),
f
(
with_enrolled_samples
)));
BOB_CATCH_MEMBER
(
"`compute_log_likelihood` could not be read"
,
0
)
}
...
...
@@ -678,13 +685,20 @@ static PyObject* PyBobLearnEMPLDAMachine_forward(PyBobLearnEMPLDAMachineObject*
char
**
kwlist
=
forward
.
kwlist
(
0
);
PyBlitzArrayObject
*
samples
;
PyArrayObject
*
numpy_samples
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O&"
,
kwlist
,
&
PyBlitzArray_Converter
,
&
samples
))
return
0
;
/*Convert to PyObject first to access the number of dimensions*/
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O!"
,
kwlist
,
&
PyArray_Type
,
&
numpy_samples
))
return
0
;
auto
numpy_samples_
=
make_safe
(
numpy_samples
);
Py_INCREF
(
numpy_samples
);
int
dim
=
PyArray_NDIM
(
numpy_samples
);
/*Now converting to PyBlitzArrayObject*/
samples
=
reinterpret_cast
<
PyBlitzArrayObject
*>
(
PyBlitzArray_FromNumpyArray
(
numpy_samples
));
auto
samples_
=
make_safe
(
samples
);
blitz
::
Array
<
double
,
2
>
blitz_test
=
*
PyBlitzArrayCxx_AsBlitz
<
double
,
2
>
(
samples
);
//There are 2 methods in C++, one <double,1> and the another <double,2>
if
(
blitz_test
.
extent
(
1
)
==
0
)
if
(
dim
==
1
)
return
Py_BuildValue
(
"d"
,
self
->
cxx
->
forward
(
*
PyBlitzArrayCxx_AsBlitz
<
double
,
1
>
(
samples
)));
else
return
Py_BuildValue
(
"d"
,
self
->
cxx
->
forward
(
*
PyBlitzArrayCxx_AsBlitz
<
double
,
2
>
(
samples
)));
...
...
bob/learn/em/test/test_plda.py
View file @
c9ae99c8
...
...
@@ -480,6 +480,10 @@ def test_plda_machine_log_likelihood_Python():
ar_s
=
numpy
.
vstack
([
ar_e
,
ar_p
])
assert
abs
(
m
.
compute_log_likelihood
(
ar_s
,
False
)
-
compute_log_likelihood
(
ar_s
,
mu
,
C_F
,
C_G
,
sigma
))
<
1e-10
ar_p2d
=
numpy
.
reshape
(
ar_p
,
(
1
,
C_dim_d
))
print
ar_p
.
shape
a
=
m
.
compute_log_likelihood
(
ar_p
,
False
)
assert
abs
(
m
.
compute_log_likelihood
(
ar_p
,
False
)
-
compute_log_likelihood
(
ar_p2d
,
mu
,
C_F
,
C_G
,
sigma
))
<
1e-10
# Defines (random) samples and check forward method
...
...
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