Commit f0dc837ebe3254e5df80b531352be6b551953818

Authored by Scott Klum
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,6 +181,11 @@ struct CascadeBoostTrainData : CvDTreeTrainData
181 181
182 virtual CvDTreeNode* subsample_data(const CvMat* _subsample_idx); 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 virtual const int* getBufferValues(CvDTreeNode* n, int* labelsBuf, uint64_t vi); 189 virtual const int* getBufferValues(CvDTreeNode* n, int* labelsBuf, uint64_t vi);
185 virtual const int* get_class_labels(CvDTreeNode* n, int* labelsBuf); 190 virtual const int* get_class_labels(CvDTreeNode* n, int* labelsBuf);
186 virtual const int* get_cv_labels(CvDTreeNode* n, int* labelsBuf); 191 virtual const int* get_cv_labels(CvDTreeNode* n, int* labelsBuf);
@@ -254,7 +259,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx @@ -254,7 +259,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx
254 int* sidx = isubsample_idx->data.i; 259 int* sidx = isubsample_idx->data.i;
255 // co - array of count/offset pairs (to handle duplicated values in _subsample_idx) 260 // co - array of count/offset pairs (to handle duplicated values in _subsample_idx)
256 int* co, cur_ofs = 0; 261 int* co, cur_ofs = 0;
257 - int workVarCount = get_work_var_count(); 262 + uint64_t workVarCount = get_work_var_count();
258 int count = isubsample_idx->rows + isubsample_idx->cols - 1; 263 int count = isubsample_idx->rows + isubsample_idx->cols - 1;
259 264
260 root = new_node( 0, count, 1, 0 ); 265 root = new_node( 0, count, 1, 0 );
@@ -295,8 +300,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx @@ -295,8 +300,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx
295 300
296 if (is_buf_16u) 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 for( int i = 0; i < num_valid; i++ ) 304 for( int i = 0; i < num_valid; i++ )
301 { 305 {
302 idx = src_idx[i]; 306 idx = src_idx[i];
@@ -308,8 +312,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx @@ -308,8 +312,7 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx
308 } 312 }
309 else 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 for( int i = 0; i < num_valid; i++ ) 316 for( int i = 0; i < num_valid; i++ )
314 { 317 {
315 idx = src_idx[i]; 318 idx = src_idx[i];
@@ -325,14 +328,13 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx @@ -325,14 +328,13 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx
325 const int* src_lbls = get_cv_labels(data_root, (int*)(uchar*)inn_buf); 328 const int* src_lbls = get_cv_labels(data_root, (int*)(uchar*)inn_buf);
326 if (is_buf_16u) 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 for( int i = 0; i < count; i++ ) 332 for( int i = 0; i < count; i++ )
331 udst[i] = (unsigned short)src_lbls[sidx[i]]; 333 udst[i] = (unsigned short)src_lbls[sidx[i]];
332 } 334 }
333 else 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 (workVarCount-1)*sample_count + root->offset; 338 (workVarCount-1)*sample_count + root->offset;
337 for( int i = 0; i < count; i++ ) 339 for( int i = 0; i < count; i++ )
338 idst[i] = src_lbls[sidx[i]]; 340 idst[i] = src_lbls[sidx[i]];
@@ -342,15 +344,13 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx @@ -342,15 +344,13 @@ CvDTreeNode* CascadeBoostTrainData::subsample_data( const CvMat* _subsample_idx
342 const int* sample_idx_src = get_sample_indices(data_root, (int*)(uchar*)inn_buf); 344 const int* sample_idx_src = get_sample_indices(data_root, (int*)(uchar*)inn_buf);
343 if (is_buf_16u) 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 for( int i = 0; i < count; i++ ) 348 for( int i = 0; i < count; i++ )
348 sample_idx_dst[i] = (unsigned short)sample_idx_src[sidx[i]]; 349 sample_idx_dst[i] = (unsigned short)sample_idx_src[sidx[i]];
349 } 350 }
350 else 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 for( int i = 0; i < count; i++ ) 354 for( int i = 0; i < count; i++ )
355 sample_idx_dst[i] = sample_idx_src[sidx[i]]; 355 sample_idx_dst[i] = sample_idx_src[sidx[i]];
356 } 356 }
@@ -500,7 +500,7 @@ void CascadeBoostTrainData::setData( const FeatureEvaluator* _featureEvaluator, @@ -500,7 +500,7 @@ void CascadeBoostTrainData::setData( const FeatureEvaluator* _featureEvaluator,
500 500
501 buf_size = -1; // the member buf_size is obsolete 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 effective_buf_width = sample_count; 505 effective_buf_width = sample_count;
506 effective_buf_height = work_var_count+1; 506 effective_buf_height = work_var_count+1;
@@ -598,9 +598,9 @@ const int* CascadeBoostTrainData::getBufferValues(CvDTreeNode* n, int* indicesBu @@ -598,9 +598,9 @@ const int* CascadeBoostTrainData::getBufferValues(CvDTreeNode* n, int* indicesBu
598 { 598 {
599 const int* cat_values = 0; 599 const int* cat_values = 0;
600 if (!is_buf_16u) 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 else { 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 for (int i = 0; i < n->sample_count; i++) 604 for (int i = 0; i < n->sample_count; i++)
605 indicesBuf[i] = short_values[i]; 605 indicesBuf[i] = short_values[i];
606 cat_values = indicesBuf; 606 cat_values = indicesBuf;
@@ -630,9 +630,9 @@ void CascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ord @@ -630,9 +630,9 @@ void CascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ord
630 // have we precalculated (presorted) the training samples by their feature response? 630 // have we precalculated (presorted) the training samples by their feature response?
631 if (vi < numPrecalcIdx) { 631 if (vi < numPrecalcIdx) {
632 if (!is_buf_16u) 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 else { 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 for (int i = 0; i < nodeSampleCount; i++) 636 for (int i = 0; i < nodeSampleCount; i++)
637 sortedIndicesBuf[i] = shortIndices[i]; 637 sortedIndicesBuf[i] = shortIndices[i];
638 *sortedIndices = sortedIndicesBuf; 638 *sortedIndices = sortedIndicesBuf;
@@ -874,7 +874,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) @@ -874,7 +874,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node )
874 int* newIdx = data->split_buf->data.i; 874 int* newIdx = data->split_buf->data.i;
875 int newBufIdx = data->get_child_buf_idx( node ); 875 int newBufIdx = data->get_child_buf_idx( node );
876 CvMat* buf = data->buf; 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 cv::AutoBuffer<uchar> inn_buf(nodeSampleCount*(3*sizeof(int)+sizeof(float))); 878 cv::AutoBuffer<uchar> inn_buf(nodeSampleCount*(3*sizeof(int)+sizeof(float)));
879 int* tempBuf = (int*)(uchar*)inn_buf; 879 int* tempBuf = (int*)(uchar*)inn_buf;
880 880
@@ -1143,7 +1143,7 @@ void CascadeBoost::update_weights(CvBoostTree* tree) @@ -1143,7 +1143,7 @@ void CascadeBoost::update_weights(CvBoostTree* tree)
1143 } 1143 }
1144 1144
1145 CvMat* buf = data->buf; 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 if( !tree ) // before training the first tree, initialize weights and other parameters 1147 if( !tree ) // before training the first tree, initialize weights and other parameters
1148 { 1148 {
1149 int* classLabelsBuf = (int*)cur_inn_buf_pos; cur_inn_buf_pos = (uchar*)(classLabelsBuf + n); 1149 int* classLabelsBuf = (int*)cur_inn_buf_pos; cur_inn_buf_pos = (uchar*)(classLabelsBuf + n);