-void binarize(const int n, const Dtype* real_valued_feature,
- Dtype* binary_codes) {
- // TODO: more advanced binarization algorithm such as bilinear projection
- // Yunchao Gong, Sanjiv Kumar, Henry A. Rowley, and Svetlana Lazebnik.
- // Learning Binary Codes for High-Dimensional Data Using Bilinear Projections.
- // In IEEE International Conference on Computer Vision and Pattern Recognition (CVPR), 2013.
- // http://www.unc.edu/~yunchao/bpbc.htm
- int size_of_code = sizeof(Dtype) * 8;
- int num_binary_codes = (n + size_of_code - 1) / size_of_code;
- uint64_t code;
- int offset;
- int count = 0;
- for (int i = 0; i < num_binary_codes; ++i) {
- offset = i * size_of_code;
- int j = 0;
- code = 0;
- for (; j < size_of_code && count++ < n; ++j) {
- code |= sign(real_valued_feature[offset + j]);
- code << 1;
+void binarize(const vector<shared_ptr<Blob<Dtype> > >& feature_blob_vector,
+ shared_ptr<Blob<Dtype> > binary_codes) {
+ CHECK_GT(feature_blob_vector.size(), 0);
+ Dtype sum;
+ size_t count = 0;
+ size_t num_features = 0;
+ for (int i = 0; i < feature_blob_vector.size(); ++i) {
+ num_features += feature_blob_vector[i]->num();
+ const Dtype* data = feature_blob_vector[i]->cpu_data();
+ for (int j = 0; j < feature_blob_vector[i]->count(); ++j) {
+ sum += data[j];
+ ++count;