Move compararing function from common_layers to argmax_layer
authorKai Li <kaili_kloud@163.com>
Thu, 10 Jul 2014 01:06:11 +0000 (09:06 +0800)
committerKai Li <kaili_kloud@163.com>
Sat, 19 Jul 2014 16:26:41 +0000 (00:26 +0800)
include/caffe/common_layers.hpp
src/caffe/layers/argmax_layer.cpp

index 26bfb5d..395ea7d 100644 (file)
 
 namespace caffe {
 
-template<typename Dtype>
-bool int_Dtype_pair_greater(std::pair<int, Dtype> a,
-                            std::pair<int, Dtype> b) {
-  return a.second > b.second || (a.second == b.second && a.first > b.first);
-}
-
 /* ArgmaxLayer
   Compute the index of the max value across all (channels x height x width).
   [In the future, can take specific dimension.]
index f4d9b45..44476cc 100644 (file)
@@ -3,6 +3,7 @@
 #include <algorithm>
 #include <cfloat>
 #include <queue>
+#include <utility>
 #include <vector>
 
 #include "caffe/layer.hpp"
@@ -28,6 +29,12 @@ void ArgMaxLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
   }
 }
 
+template<typename Dtype>
+bool int_Dtype_pair_greater(std::pair<int, Dtype> a,
+                            std::pair<int, Dtype> b) {
+  return a.second > b.second;
+}
+
 template <typename Dtype>
 Dtype ArgMaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
     vector<Blob<Dtype>*>* top) {
@@ -38,7 +45,8 @@ Dtype ArgMaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
   for (int i = 0; i < num; ++i) {
     std::vector<std::pair<int, Dtype> > bottom_data_vector;
     for (int j = 0; j < dim; ++j) {
-      bottom_data_vector.push_back(std::make_pair(j, bottom_data[i * dim + j]));
+      bottom_data_vector.push_back(
+          std::make_pair(j, bottom_data[i * dim + j]));
     }
     std::partial_sort(
         bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_,