Commit f0dc837ebe3254e5df80b531352be6b551953818
1 parent
d37ecaa4
More 64 bit changes
Showing
1 changed file
with
19 additions
and
19 deletions
openbr/core/boost.cpp
| ... | ... | @@ -181,6 +181,11 @@ struct CascadeBoostTrainData : CvDTreeTrainData |
| 181 | 181 | |
| 182 | 182 | virtual CvDTreeNode* subsample_data(const CvMat* _subsample_idx); |
| 183 | 183 | |
| 184 | + inline uint64_t getLength() const | |
| 185 | + { | |
| 186 | + return ((uint64_t)work_var_count + 1) * sample_count; | |
| 187 | + } | |
| 188 | + | |
| 184 | 189 | virtual const int* getBufferValues(CvDTreeNode* n, int* labelsBuf, uint64_t vi); |
| 185 | 190 | virtual const int* get_class_labels(CvDTreeNode* n, int* labelsBuf); |
| 186 | 191 | virtual const int* get_cv_labels(CvDTreeNode* n, int* labelsBuf); |
| ... | ... | @@ -254,7 +259,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx |
| 254 | 259 | int* sidx = isubsample_idx->data.i; |
| 255 | 260 | // co - array of count/offset pairs (to handle duplicated values in _subsample_idx) |
| 256 | 261 | int* co, cur_ofs = 0; |
| 257 | - int workVarCount = get_work_var_count(); | |
| 262 | + uint64_t workVarCount = get_work_var_count(); | |
| 258 | 263 | int count = isubsample_idx->rows + isubsample_idx->cols - 1; |
| 259 | 264 | |
| 260 | 265 | root = new_node( 0, count, 1, 0 ); |
| ... | ... | @@ -295,8 +300,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx |
| 295 | 300 | |
| 296 | 301 | if (is_buf_16u) |
| 297 | 302 | { |
| 298 | - unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() + | |
| 299 | - vi*sample_count + data_root->offset); | |
| 303 | + unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*getLength() + (uint64_t)vi*sample_count + data_root->offset); | |
| 300 | 304 | for( int i = 0; i < num_valid; i++ ) |
| 301 | 305 | { |
| 302 | 306 | idx = src_idx[i]; |
| ... | ... | @@ -308,8 +312,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx |
| 308 | 312 | } |
| 309 | 313 | else |
| 310 | 314 | { |
| 311 | - int* idst_idx = buf->data.i + root->buf_idx*get_length_subbuf() + | |
| 312 | - vi*sample_count + root->offset; | |
| 315 | + int* idst_idx = buf->data.i + root->buf_idx*getLength() + (uint64_t)vi*sample_count + root->offset; | |
| 313 | 316 | for( int i = 0; i < num_valid; i++ ) |
| 314 | 317 | { |
| 315 | 318 | idx = src_idx[i]; |
| ... | ... | @@ -325,14 +328,13 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx |
| 325 | 328 | const int* src_lbls = get_cv_labels(data_root, (int*)(uchar*)inn_buf); |
| 326 | 329 | if (is_buf_16u) |
| 327 | 330 | { |
| 328 | - unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() + | |
| 329 | - (workVarCount-1)*sample_count + root->offset); | |
| 331 | + unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*getLength() + (workVarCount-1)*sample_count + root->offset); | |
| 330 | 332 | for( int i = 0; i < count; i++ ) |
| 331 | 333 | udst[i] = (unsigned short)src_lbls[sidx[i]]; |
| 332 | 334 | } |
| 333 | 335 | else |
| 334 | 336 | { |
| 335 | - int* idst = buf->data.i + root->buf_idx*get_length_subbuf() + | |
| 337 | + int* idst = buf->data.i + root->buf_idx*getLength() + | |
| 336 | 338 | (workVarCount-1)*sample_count + root->offset; |
| 337 | 339 | for( int i = 0; i < count; i++ ) |
| 338 | 340 | idst[i] = src_lbls[sidx[i]]; |
| ... | ... | @@ -342,15 +344,13 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx |
| 342 | 344 | const int* sample_idx_src = get_sample_indices(data_root, (int*)(uchar*)inn_buf); |
| 343 | 345 | if (is_buf_16u) |
| 344 | 346 | { |
| 345 | - unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() + | |
| 346 | - workVarCount*sample_count + root->offset); | |
| 347 | + unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*getLength() + workVarCount*sample_count + root->offset); | |
| 347 | 348 | for( int i = 0; i < count; i++ ) |
| 348 | 349 | sample_idx_dst[i] = (unsigned short)sample_idx_src[sidx[i]]; |
| 349 | 350 | } |
| 350 | 351 | else |
| 351 | 352 | { |
| 352 | - int* sample_idx_dst = buf->data.i + root->buf_idx*get_length_subbuf() + | |
| 353 | - workVarCount*sample_count + root->offset; | |
| 353 | + int* sample_idx_dst = buf->data.i + root->buf_idx*getLength() + workVarCount*sample_count + root->offset; | |
| 354 | 354 | for( int i = 0; i < count; i++ ) |
| 355 | 355 | sample_idx_dst[i] = sample_idx_src[sidx[i]]; |
| 356 | 356 | } |
| ... | ... | @@ -500,7 +500,7 @@ void CascadeBoostTrainData::setData( const FeatureEvaluator* _featureEvaluator, |
| 500 | 500 | |
| 501 | 501 | buf_size = -1; // the member buf_size is obsolete |
| 502 | 502 | |
| 503 | - effective_buf_size = (work_var_count + 1)*sample_count * buf_count; // this is the total size of "CvMat buf" to be allocated | |
| 503 | + effective_buf_size = getLength()*buf_count; | |
| 504 | 504 | |
| 505 | 505 | effective_buf_width = sample_count; |
| 506 | 506 | effective_buf_height = work_var_count+1; |
| ... | ... | @@ -598,9 +598,9 @@ const int* CascadeBoostTrainData::getBufferValues(CvDTreeNode* n, int* indicesBu |
| 598 | 598 | { |
| 599 | 599 | const int* cat_values = 0; |
| 600 | 600 | if (!is_buf_16u) |
| 601 | - cat_values = buf->data.i + n->buf_idx*get_length_subbuf() + vi*sample_count + n->offset; | |
| 601 | + cat_values = buf->data.i + n->buf_idx*getLength() + vi*sample_count + n->offset; | |
| 602 | 602 | else { |
| 603 | - const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*get_length_subbuf() + vi*sample_count + n->offset); | |
| 603 | + const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*getLength() + vi*sample_count + n->offset); | |
| 604 | 604 | for (int i = 0; i < n->sample_count; i++) |
| 605 | 605 | indicesBuf[i] = short_values[i]; |
| 606 | 606 | cat_values = indicesBuf; |
| ... | ... | @@ -630,9 +630,9 @@ void CascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ord |
| 630 | 630 | // have we precalculated (presorted) the training samples by their feature response? |
| 631 | 631 | if (vi < numPrecalcIdx) { |
| 632 | 632 | if (!is_buf_16u) |
| 633 | - *sortedIndices = buf->data.i + n->buf_idx*get_length_subbuf() + (uint64_t)vi*sample_count + n->offset; | |
| 633 | + *sortedIndices = buf->data.i + n->buf_idx*getLength() + (uint64_t)vi*sample_count + n->offset; | |
| 634 | 634 | else { |
| 635 | - const unsigned short* shortIndices = (const unsigned short*)(buf->data.s + n->buf_idx*get_length_subbuf() + (uint64_t)vi*sample_count + n->offset ); | |
| 635 | + const unsigned short* shortIndices = (const unsigned short*)(buf->data.s + n->buf_idx*getLength() + (uint64_t)vi*sample_count + n->offset ); | |
| 636 | 636 | for (int i = 0; i < nodeSampleCount; i++) |
| 637 | 637 | sortedIndicesBuf[i] = shortIndices[i]; |
| 638 | 638 | *sortedIndices = sortedIndicesBuf; |
| ... | ... | @@ -874,7 +874,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) |
| 874 | 874 | int* newIdx = data->split_buf->data.i; |
| 875 | 875 | int newBufIdx = data->get_child_buf_idx( node ); |
| 876 | 876 | CvMat* buf = data->buf; |
| 877 | - size_t length_buf_row = data->get_length_subbuf(); | |
| 877 | + size_t length_buf_row = ((CascadeBoostTrainData*)data)->getLength(); | |
| 878 | 878 | cv::AutoBuffer<uchar> inn_buf(nodeSampleCount*(3*sizeof(int)+sizeof(float))); |
| 879 | 879 | int* tempBuf = (int*)(uchar*)inn_buf; |
| 880 | 880 | |
| ... | ... | @@ -1143,7 +1143,7 @@ void CascadeBoost::update_weights(CvBoostTree* tree) |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | CvMat* buf = data->buf; |
| 1146 | - size_t length_buf_row = data->get_length_subbuf(); | |
| 1146 | + uint64_t length_buf_row = ((CascadeBoostTrainData*)data)->getLength(); | |
| 1147 | 1147 | if( !tree ) // before training the first tree, initialize weights and other parameters |
| 1148 | 1148 | { |
| 1149 | 1149 | int* classLabelsBuf = (int*)cur_inn_buf_pos; cur_inn_buf_pos = (uchar*)(classLabelsBuf + n); | ... | ... |