CvEM::read_params() read wrongly? (Bug #1340)
Description
Hi, all:
It looks there is some problem with CvEM::write_params() and CvEM::read_params() .
Whenever I didn't "read after write" the CvEM parameters, the predict() function works fine. However, whenever I called read_params() after I write_params() of a CvEM model, the predict() function goes crash.
I called the function in this way:
gmmModel.read_params(fs, 0);
Then, I noticed in the documentation of CvEM::read_params(),
If it is NULL, the function searches a node with parameters in all the top-level nodes (streams), starting with the first one.
Does that mean that there is no simple way to load all parameters in all level modes, instead of just the top-level nodes ????
Anyway, my trained .xml file is copied in the following and attached as file color001.xml:
please do give me a hand on how to CvEM::read_params() successfully with all level parameters loaded using CvEM::read_params() ???
Best Regards
Pei
<opencv_storage>
<params>
<cov_mat_type>COV_MAT_DIAGONAL</cov_mat_type>
<start_step>START_AUTO_STEP</start_step>
<nclusters>3</nclusters>
<weights type_id="opencv-matrix">
<rows>1</rows>
<cols>3</cols>
<dt>d</dt>
<data>
4.7505367397911979e-001 4.0513001653020758e-001
1.1981630949067631e-001</data></weights>
<means type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
4.6735226574391647e-001 4.3428615328431247e-001
7.7229067746570723e-001 2.8662794138474235e-001
2.4997266948677280e-001 5.2728525926602976e-001 1. 1. 1.</data></means>
<covs>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
3.1503335914751878e-003 0. 0. 0. 3.2953545487618106e-003 0. 0.
0. 7.2003084647408845e-003</data></_>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
9.8828026607258000e-004 0. 0. 0. 1.3064142972168662e-003 0. 0.
0. 2.6975317757247349e-003</data></_>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
1.1920928955078125e-007 0. 0. 0. 1.1920928955078125e-007 0. 0.
0. 1.1920928955078125e-007</data></_></covs></params>
</opencv_storage>
Associated revisions
Merge pull request #1340 from SpecLad:python-updates
History
Updated by Pei JIA over 13 years ago
Hi, all:
Finally, I noticed that this is probably a bug of CvEM, because it's using dual systems to record the parameters. A CvEMParams already contains all parameter matrices. Please refer to what's the class definition in current CvEM and CvEMParams.
The following 6 lines are in CvEM
CvEMParams params;
....
CvMat* means;
CvMat** covs;
CvMat* weights;
CvMat* probs;
And CvEMParams is defined as:
struct CV_EXPORTS_W_MAP CvEMParams
{
CvEMParams();
CvEMParams( int nclusters, int cov_mat_type=1/*CvEM::COV_MAT_DIAGONAL*/,
int start_step=0/*CvEM::START_AUTO_STEP*/,
CvTermCriteria term_crit=cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, FLT_EPSILON),
const CvMat* probs=0, const CvMat* weights=0, const CvMat* means=0, const CvMat** covs=0 );
CV_PROP_RW int nclusters;
CV_PROP_RW int cov_mat_type;
CV_PROP_RW int start_step;
const CvMat* probs;
const CvMat* weights;
const CvMat* means;
const CvMat** covs;
CV_PROP_RW CvTermCriteria term_crit;
};
The reason why I failed to read_params() after write_params() is
when writing, the trained data were stored in matrices (CvMat* means;
CvMat** covs; CvMat* weights; CvMat* probs;) declared in CvEM;
while reading, the trained data are now loaded into the parameter CvEMParams params.
I'm guessing this is most probably a bug. Waiting for the fixing.
Best Regards
Pei
Replying to jiapei100:
Hi, all:
It looks there is some problem with CvEM::write_params() and CvEM::read_params() .
Whenever I didn't "read after write" the CvEM parameters, the predict() function works fine. However, whenever I called read_params() after I write_params() of a CvEM model, the predict() function goes crash.
I called the function in this way:
gmmModel.read_params(fs, 0);Then, I noticed in the documentation of CvEM::read_params(),
If it is NULL, the function searches a node with parameters in all the top-level nodes (streams), starting with the first one.
Does that mean that there is no simple way to load all parameters in all level modes, instead of just the top-level nodes ????Anyway, my trained .xml file is copied in the following and attached as file color001.xml:
please do give me a hand on how to CvEM::read_params() successfully with all level parameters loaded using CvEM::read_params() ???Best Regards
Pei
<opencv_storage>
<params>
<cov_mat_type>COV_MAT_DIAGONAL</cov_mat_type>
<start_step>START_AUTO_STEP</start_step>
<nclusters>3</nclusters>
<weights type_id="opencv-matrix">
<rows>1</rows>
<cols>3</cols>
<dt>d</dt>
<data>
4.7505367397911979e-001 4.0513001653020758e-001
1.1981630949067631e-001</data></weights>
<means type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
4.6735226574391647e-001 4.3428615328431247e-001
7.7229067746570723e-001 2.8662794138474235e-001
2.4997266948677280e-001 5.2728525926602976e-001 1. 1. 1.</data></means>
<covs>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
3.1503335914751878e-003 0. 0. 0. 3.2953545487618106e-003 0. 0.
0. 7.2003084647408845e-003</data></_>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
9.8828026607258000e-004 0. 0. 0. 1.3064142972168662e-003 0. 0.
0. 2.6975317757247349e-003</data></_>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
1.1920928955078125e-007 0. 0. 0. 1.1920928955078125e-007 0. 0.
0. 1.1920928955078125e-007</data></_></covs></params>
</opencv_storage>
Updated by Pei JIA over 13 years ago
Problem is now bypassed by using CvStatModel::save() and CvStatModel::load() .
But, personally speaking, that doesn't mean CvEM::write_params() and CvEM::read_params() are a functionally corresponding pair.
Apparently, they are not.
Still think this is a bug.
Looking forward to the fixing.
Best Regards
Pei
Replying to jiapei100:
Hi, all:
It looks there is some problem with CvEM::write_params() and CvEM::read_params() .
Whenever I didn't "read after write" the CvEM parameters, the predict() function works fine. However, whenever I called read_params() after I write_params() of a CvEM model, the predict() function goes crash.
I called the function in this way:
gmmModel.read_params(fs, 0);Then, I noticed in the documentation of CvEM::read_params(),
If it is NULL, the function searches a node with parameters in all the top-level nodes (streams), starting with the first one.
Does that mean that there is no simple way to load all parameters in all level modes, instead of just the top-level nodes ????Anyway, my trained .xml file is copied in the following and attached as file color001.xml:
please do give me a hand on how to CvEM::read_params() successfully with all level parameters loaded using CvEM::read_params() ???Best Regards
Pei
<opencv_storage>
<params>
<cov_mat_type>COV_MAT_DIAGONAL</cov_mat_type>
<start_step>START_AUTO_STEP</start_step>
<nclusters>3</nclusters>
<weights type_id="opencv-matrix">
<rows>1</rows>
<cols>3</cols>
<dt>d</dt>
<data>
4.7505367397911979e-001 4.0513001653020758e-001
1.1981630949067631e-001</data></weights>
<means type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
4.6735226574391647e-001 4.3428615328431247e-001
7.7229067746570723e-001 2.8662794138474235e-001
2.4997266948677280e-001 5.2728525926602976e-001 1. 1. 1.</data></means>
<covs>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
3.1503335914751878e-003 0. 0. 0. 3.2953545487618106e-003 0. 0.
0. 7.2003084647408845e-003</data></_>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
9.8828026607258000e-004 0. 0. 0. 1.3064142972168662e-003 0. 0.
0. 2.6975317757247349e-003</data></_>
<_ type_id="opencv-matrix">
<rows>3</rows>
<cols>3</cols>
<dt>d</dt>
<data>
1.1920928955078125e-007 0. 0. 0. 1.1920928955078125e-007 0. 0.
0. 1.1920928955078125e-007</data></_></covs></params>
</opencv_storage>
Updated by Vadim Pisarevsky over 13 years ago
looks like it's normal bug. Lowering the priority to major.
Updated by Alexander Shishkov about 13 years ago
- Description changed from Hi, all: It looks there is some problem with [[CvEM]]::write_params() and ... to Hi, all: It looks there is some problem with CvEM::write_params() and CvEM:... More
Updated by Alexander Shishkov almost 13 years ago
- Priority changed from High to Normal
- Target version deleted ()
- Description changed from Hi, all: It looks there is some problem with CvEM::write_params() and CvEM:... to Hi, all: It looks there is some problem with CvEM::write_params() and CvEM::... More
Updated by Alexander Shishkov almost 13 years ago
- Assignee deleted (
Maria Dimashova)
Updated by Maria Dimashova almost 13 years ago
- Assignee set to Maria Dimashova
Updated by Alexander Shishkov almost 13 years ago
- Target version deleted ()
Updated by Maria Dimashova almost 13 years ago
Thank you for the report. CvEM write method had a bug, it saved all matrices twice. It was fixed, but be careful due to we had to change the storing format to fix it.
Note, we added new c++ implementation cv::EM and moved CvEM to the legacy module (cv::EM will be available in coming opencv2.4). So you should change include file from ml to legacy module. The implementation of CvEM methods was replaced by the call of cv::EM ones. CvEM writes the trained model in new format now (as mentioned above).
cv::EM should solve many issues of the previous implementation. We added several new tests to check this. If you'll have some other problems from r8075, please open an issue.
Updated by Maria Dimashova almost 13 years ago
- Status changed from Open to Done
Updated by Andrey Kamaev almost 13 years ago
- Target version set to 2.4.0