Commit cf6ae36bb1492d22029cdbc3ba085b06713836ec
1 parent
a3840e54
More cleanup
Showing
1 changed file
with
15 additions
and
13 deletions
openbr/core/boost.cpp
| @@ -464,10 +464,12 @@ void CascadeBoostTrainData::setData( const FeatureEvaluator* _featureEvaluator, | @@ -464,10 +464,12 @@ void CascadeBoostTrainData::setData( const FeatureEvaluator* _featureEvaluator, | ||
| 464 | 464 | ||
| 465 | // 1048576 is the number of bytes in a megabyte | 465 | // 1048576 is the number of bytes in a megabyte |
| 466 | numPrecalcVal = min( cvRound((double)_precalcValBufSize*1048576. / (sizeof(float)*sample_count)), var_count ); | 466 | numPrecalcVal = min( cvRound((double)_precalcValBufSize*1048576. / (sizeof(float)*sample_count)), var_count ); |
| 467 | - qDebug("Features Cached: %f", float(numPrecalcVal)/var_count); | 467 | + qDebug("MB required to cache all %d features: %d", var_count, (sizeof(float)*(uint64_t)sample_count*var_count)/1048576); |
| 468 | + qDebug("Features cached: %.2f", float(numPrecalcVal)/var_count); | ||
| 468 | 469 | ||
| 469 | numPrecalcIdx = min( cvRound((double)_precalcIdxBufSize*1048576. / ((is_buf_16u ? sizeof(unsigned short) : sizeof (int))*sample_count)), var_count ); | 470 | numPrecalcIdx = min( cvRound((double)_precalcIdxBufSize*1048576. / ((is_buf_16u ? sizeof(unsigned short) : sizeof (int))*sample_count)), var_count ); |
| 470 | - qDebug("Indices Cached: %f", float(numPrecalcIdx)/var_count); | 471 | + qDebug("MB required to cache all %d sorted indices: %d", var_count, ((is_buf_16u ? sizeof(unsigned short) : sizeof (int))*(uint64_t)sample_count*var_count)/1048576); |
| 472 | + qDebug("Indices cached: %.2f", float(numPrecalcIdx)/var_count); | ||
| 471 | 473 | ||
| 472 | assert( numPrecalcIdx >= 0 && numPrecalcVal >= 0 ); | 474 | assert( numPrecalcIdx >= 0 && numPrecalcVal >= 0 ); |
| 473 | 475 | ||
| @@ -883,7 +885,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -883,7 +885,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 883 | 885 | ||
| 884 | complete_node_dir(node); | 886 | complete_node_dir(node); |
| 885 | 887 | ||
| 886 | - for (int i = nLeft = nRight = 0; i < nodeSampleCount; i++) | 888 | + for (uint64_t i = nLeft = nRight = 0; i < nodeSampleCount; i++) |
| 887 | { | 889 | { |
| 888 | int d = dir[i]; | 890 | int d = dir[i]; |
| 889 | // initialize new indices for splitting ordered variables | 891 | // initialize new indices for splitting ordered variables |
| @@ -912,7 +914,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -912,7 +914,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 912 | 914 | ||
| 913 | data->get_ord_var_data(node, vi, src_val_buf, src_sorted_idx_buf, &src_val, &src_sorted_idx, src_sample_idx_buf); | 915 | data->get_ord_var_data(node, vi, src_val_buf, src_sorted_idx_buf, &src_val, &src_sorted_idx, src_sample_idx_buf); |
| 914 | 916 | ||
| 915 | - for(int i = 0; i < nodeSampleCount; i++) | 917 | + for(uint64_t i = 0; i < nodeSampleCount; i++) |
| 916 | tempBuf[i] = src_sorted_idx[i]; | 918 | tempBuf[i] = src_sorted_idx[i]; |
| 917 | 919 | ||
| 918 | if (data->is_buf_16u) { | 920 | if (data->is_buf_16u) { |
| @@ -933,7 +935,6 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -933,7 +935,6 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 933 | ldst++; | 935 | ldst++; |
| 934 | } | 936 | } |
| 935 | } | 937 | } |
| 936 | - CV_Assert( n1 == nodeSampleCount ); | ||
| 937 | } | 938 | } |
| 938 | else | 939 | else |
| 939 | { | 940 | { |
| @@ -958,7 +959,6 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -958,7 +959,6 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 958 | ldst++; | 959 | ldst++; |
| 959 | } | 960 | } |
| 960 | } | 961 | } |
| 961 | - CV_Assert( n1 == nodeSampleCount ); | ||
| 962 | } | 962 | } |
| 963 | } | 963 | } |
| 964 | 964 | ||
| @@ -966,14 +966,14 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -966,14 +966,14 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 966 | int *src_lbls_buf = tempBuf + nodeSampleCount; | 966 | int *src_lbls_buf = tempBuf + nodeSampleCount; |
| 967 | const int* src_lbls = data->get_cv_labels(node, src_lbls_buf); | 967 | const int* src_lbls = data->get_cv_labels(node, src_lbls_buf); |
| 968 | 968 | ||
| 969 | - for(int i = 0; i < nodeSampleCount; i++) | 969 | + for(uint64_t i = 0; i < nodeSampleCount; i++) |
| 970 | tempBuf[i] = src_lbls[i]; | 970 | tempBuf[i] = src_lbls[i]; |
| 971 | 971 | ||
| 972 | if (data->is_buf_16u) { | 972 | if (data->is_buf_16u) { |
| 973 | unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + left->offset); | 973 | unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + left->offset); |
| 974 | unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + right->offset); | 974 | unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + right->offset); |
| 975 | 975 | ||
| 976 | - for( int i = 0; i < nodeSampleCount; i++ ) { | 976 | + for( uint64_t i = 0; i < nodeSampleCount; i++ ) { |
| 977 | int idx = tempBuf[i]; | 977 | int idx = tempBuf[i]; |
| 978 | if (dir[i]) { | 978 | if (dir[i]) { |
| 979 | *rdst = (unsigned short)idx; | 979 | *rdst = (unsigned short)idx; |
| @@ -990,7 +990,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -990,7 +990,7 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 990 | int *ldst = buf->data.i + left->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + left->offset; | 990 | int *ldst = buf->data.i + left->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + left->offset; |
| 991 | int *rdst = buf->data.i + right->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + right->offset; | 991 | int *rdst = buf->data.i + right->buf_idx*length_buf_row + (workVarCount-1)*sampleCount + right->offset; |
| 992 | 992 | ||
| 993 | - for( int i = 0; i < nodeSampleCount; i++ ) | 993 | + for( uint64_t i = 0; i < nodeSampleCount; i++ ) |
| 994 | { | 994 | { |
| 995 | int idx = tempBuf[i]; | 995 | int idx = tempBuf[i]; |
| 996 | if (dir[i]) | 996 | if (dir[i]) |
| @@ -1010,13 +1010,13 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -1010,13 +1010,13 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 1010 | int *sampleIdx_src_buf = tempBuf + nodeSampleCount; | 1010 | int *sampleIdx_src_buf = tempBuf + nodeSampleCount; |
| 1011 | const int* sampleIdx_src = data->get_sample_indices(node, sampleIdx_src_buf); | 1011 | const int* sampleIdx_src = data->get_sample_indices(node, sampleIdx_src_buf); |
| 1012 | 1012 | ||
| 1013 | - for(int i = 0; i < nodeSampleCount; i++) | 1013 | + for(uint64_t i = 0; i < nodeSampleCount; i++) |
| 1014 | tempBuf[i] = sampleIdx_src[i]; | 1014 | tempBuf[i] = sampleIdx_src[i]; |
| 1015 | 1015 | ||
| 1016 | if (data->is_buf_16u) { | 1016 | if (data->is_buf_16u) { |
| 1017 | unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*length_buf_row + workVarCount*sampleCount + left->offset); | 1017 | unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*length_buf_row + workVarCount*sampleCount + left->offset); |
| 1018 | unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*length_buf_row + workVarCount*sampleCount + right->offset); | 1018 | unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*length_buf_row + workVarCount*sampleCount + right->offset); |
| 1019 | - for (int i = 0; i < nodeSampleCount; i++) { | 1019 | + for (uint64_t i = 0; i < nodeSampleCount; i++) { |
| 1020 | unsigned short idx = (unsigned short)tempBuf[i]; | 1020 | unsigned short idx = (unsigned short)tempBuf[i]; |
| 1021 | if (dir[i]) { | 1021 | if (dir[i]) { |
| 1022 | *rdst = idx; | 1022 | *rdst = idx; |
| @@ -1031,11 +1031,12 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -1031,11 +1031,12 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 1031 | { | 1031 | { |
| 1032 | int* ldst = buf->data.i + left->buf_idx*length_buf_row + workVarCount*sampleCount + left->offset; | 1032 | int* ldst = buf->data.i + left->buf_idx*length_buf_row + workVarCount*sampleCount + left->offset; |
| 1033 | int* rdst = buf->data.i + right->buf_idx*length_buf_row + workVarCount*sampleCount + right->offset; | 1033 | int* rdst = buf->data.i + right->buf_idx*length_buf_row + workVarCount*sampleCount + right->offset; |
| 1034 | - for (int i = 0; i < nodeSampleCount; i++) | 1034 | + for (uint64_t i = 0; i < nodeSampleCount; i++) |
| 1035 | { | 1035 | { |
| 1036 | int idx = tempBuf[i]; | 1036 | int idx = tempBuf[i]; |
| 1037 | if (dir[i]) | 1037 | if (dir[i]) |
| 1038 | { | 1038 | { |
| 1039 | + | ||
| 1039 | *rdst = idx; | 1040 | *rdst = idx; |
| 1040 | rdst++; | 1041 | rdst++; |
| 1041 | } | 1042 | } |
| @@ -1061,7 +1062,8 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | @@ -1061,7 +1062,8 @@ void CascadeBoostTree::split_node_data( CvDTreeNode* node ) | ||
| 1061 | 1062 | ||
| 1062 | void CascadeBoost::train(const FeatureEvaluator* _featureEvaluator, | 1063 | void CascadeBoost::train(const FeatureEvaluator* _featureEvaluator, |
| 1063 | int _numSamples, | 1064 | int _numSamples, |
| 1064 | - int _precalcValBufSize, int _precalcIdxBufSize, | 1065 | + int _precalcValBufSize, |
| 1066 | + int _precalcIdxBufSize, | ||
| 1065 | int _channels, | 1067 | int _channels, |
| 1066 | const CascadeBoostParams& _params) | 1068 | const CascadeBoostParams& _params) |
| 1067 | { | 1069 | { |