lint, except for rand/rand_r
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Tue, 18 Mar 2014 22:45:42 +0000 (15:45 -0700)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Tue, 18 Mar 2014 22:45:42 +0000 (15:45 -0700)
include/caffe/vision_layers.hpp
src/caffe/layers/bnll_layer.cpp
src/caffe/layers/dropout_layer.cpp
src/caffe/layers/hdf5_data_layer.cpp
src/caffe/layers/images_layer.cpp
src/caffe/layers/relu_layer.cpp
src/caffe/layers/sigmoid_layer.cpp
src/caffe/layers/softmax_layer.cpp
src/caffe/layers/softmax_loss_layer.cpp
src/caffe/test/test_images_layer.cpp
tools/compute_image_mean.cpp

index cb26c98..6225563 100644 (file)
@@ -3,8 +3,9 @@
 #ifndef CAFFE_VISION_LAYERS_HPP_
 #define CAFFE_VISION_LAYERS_HPP_
 
-#include <vector>
 #include <string>
+#include <utility>
+#include <vector>
 
 #include "leveldb/db.h"
 #include "pthread.h"
@@ -414,7 +415,7 @@ void* ImagesLayerPrefetch(void* layer_pointer);
 template <typename Dtype>
 class ImagesLayer : public Layer<Dtype> {
   // The function used to perform prefetching.
- friend void* ImagesLayerPrefetch<Dtype>(void* layer_pointer);
 friend void* ImagesLayerPrefetch<Dtype>(void* layer_pointer);
 
  public:
   explicit ImagesLayer(const LayerParameter& param)
index ab0e0f0..b769a35 100644 (file)
@@ -1,8 +1,10 @@
 // Copyright 2013 Yangqing Jia
 
+#include <algorithm>
+#include <vector>
+
 #include "caffe/layer.hpp"
 #include "caffe/vision_layers.hpp"
-#include <algorithm>
 
 using std::min;
 
index 4e1fbfa..f480853 100644 (file)
@@ -1,5 +1,7 @@
 // Copyright 2013 Yangqing Jia
 
+#include <vector>
+
 #include "caffe/common.hpp"
 #include "caffe/layer.hpp"
 #include "caffe/syncedmem.hpp"
index 60e25d0..e5b17fe 100644 (file)
@@ -14,7 +14,7 @@ TODO:
 #include <stdint.h>
 #include <string>
 #include <vector>
-#include <fstream>
+#include <fstream>  // NOLINT(readability/streams)
 
 #include "hdf5.h"
 #include "hdf5_hl.h"
index ab3f8b0..eb1b89e 100644 (file)
@@ -6,8 +6,8 @@
 
 #include <string>
 #include <vector>
-#include <iostream>
-#include <fstream>
+#include <iostream>  // NOLINT(readability/streams)
+#include <fstream>  // NOLINT(readability/streams)
 
 #include "caffe/layer.hpp"
 #include "caffe/util/io.hpp"
@@ -21,7 +21,8 @@ namespace caffe {
 template <typename Dtype>
 void* ImagesLayerPrefetch(void* layer_pointer) {
   CHECK(layer_pointer);
-  ImagesLayer<Dtype>* layer = reinterpret_cast<ImagesLayer<Dtype>*>(layer_pointer);
+  ImagesLayer<Dtype>* layer =
+      reinterpret_cast<ImagesLayer<Dtype>*>(layer_pointer);
   CHECK(layer);
   Datum datum;
   CHECK(layer->prefetch_data_);
@@ -42,16 +43,17 @@ void* ImagesLayerPrefetch(void* layer_pointer) {
   const int channels = layer->datum_channels_;
   const int height = layer->datum_height_;
   const int width = layer->datum_width_;
-  const int size = layer->datum_size_;  
+  const int size = layer->datum_size_;
   const int lines_size = layer->lines_.size();
   const Dtype* mean = layer->data_mean_.cpu_data();
   for (int itemid = 0; itemid < batchsize; ++itemid) {
     // get a blob
-    CHECK_GT(lines_size,layer->lines_id_);
-    if (!ReadImageToDatum(layer->lines_[layer->lines_id_].first, layer->lines_[layer->lines_id_].second, 
-      new_height, new_width, &datum)) {
+    CHECK_GT(lines_size, layer->lines_id_);
+    if (!ReadImageToDatum(layer->lines_[layer->lines_id_].first,
+          layer->lines_[layer->lines_id_].second,
+          new_height, new_width, &datum)) {
       continue;
-    };    
+    }
     const string& data = datum.data();
     if (cropsize) {
       CHECK(data.size()) << "Image cropping only support uint8 data";
@@ -115,14 +117,14 @@ void* ImagesLayerPrefetch(void* layer_pointer) {
     if (layer->lines_id_ >= lines_size) {
       // We have reached the end. Restart from the first.
       DLOG(INFO) << "Restarting data prefetching from start.";
-      layer->lines_id_=0;
+      layer->lines_id_ = 0;
       if (layer->layer_param_.shuffle_images()) {
         std::random_shuffle(layer->lines_.begin(), layer->lines_.end());
       }
     }
   }
 
-  return (void*)NULL;
+  return reinterpret_cast<void*>(NULL);
 }
 
 template <typename Dtype>
@@ -136,13 +138,15 @@ void ImagesLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
       vector<Blob<Dtype>*>* top) {
   CHECK_EQ(bottom.size(), 0) << "Input Layer takes no input blobs.";
   CHECK_EQ(top->size(), 2) << "Input Layer takes two blobs as output.";
-  const int new_height  = this->layer_param_.new_height();
-  const int new_width  = this->layer_param_.new_height();
-  CHECK((new_height==0 && new_width==0)||(new_height>0 && new_width > 0)) << 
-  "Current implementation requires new_height and new_width to be set at the same time.";
+  const int new_height = this->layer_param_.new_height();
+  const int new_width = this->layer_param_.new_height();
+  CHECK((new_height == 0 && new_width == 0) ||
+      (new_height > 0 && new_width > 0)) <<
+  "Current implementation requires new_height and new_width to be set"
+  "at the same time.";
   // Read the file with filenames and labels
   LOG(INFO) << "Opening file " << this->layer_param_.source();
-  std::ifstream infile(this->layer_param_.source().c_str());  
+  std::ifstream infile(this->layer_param_.source().c_str());
   string filename;
   int label;
   while (infile >> filename >> label) {
@@ -161,13 +165,13 @@ void ImagesLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
   if (this->layer_param_.rand_skip()) {
     unsigned int skip = rand() % this->layer_param_.rand_skip();
     LOG(INFO) << "Skipping first " << skip << " data points.";
-    CHECK_GT(lines_.size(),skip) << "Not enought points to skip";
+    CHECK_GT(lines_.size(), skip) << "Not enought points to skip";
     lines_id_ = skip;
   }
   // Read a data point, and use it to initialize the top blob.
   Datum datum;
   CHECK(ReadImageToDatum(lines_[lines_id_].first, lines_[lines_id_].second,
-                         new_height,new_width,&datum));
+                         new_height, new_width, &datum));
   // image
   int cropsize = this->layer_param_.cropsize();
   if (cropsize > 0) {
index 478ed31..27ae94b 100644 (file)
@@ -1,8 +1,10 @@
 // Copyright 2013 Yangqing Jia
 
+#include <algorithm>
+#include <vector>
+
 #include "caffe/layer.hpp"
 #include "caffe/vision_layers.hpp"
-#include <algorithm>
 
 using std::max;
 
index 112771f..ba6ec84 100644 (file)
@@ -1,9 +1,11 @@
 // Copyright 2014 Tobias Domhan
 
-#include "caffe/layer.hpp"
-#include "caffe/vision_layers.hpp"
 #include <algorithm>
 #include <cmath>
+#include <vector>
+
+#include "caffe/layer.hpp"
+#include "caffe/vision_layers.hpp"
 
 namespace caffe {
 
index 172094d..69e95ff 100644 (file)
@@ -1,4 +1,7 @@
 // Copyright 2013 Yangqing Jia
+//
+#include <algorithm>
+#include <vector>
 
 #include "caffe/layer.hpp"
 #include "caffe/vision_layers.hpp"
index 2ec7308..6fdaea5 100644 (file)
@@ -45,7 +45,8 @@ Dtype SoftmaxWithLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
   Dtype loss = 0;
   for (int i = 0; i < num; ++i) {
     bottom_diff[i * dim + static_cast<int>(label[i])] -= 1;
-    loss += -log(max(prob_data[i * dim + static_cast<int>(label[i])], Dtype(FLT_MIN)));
+    loss += -log(max(prob_data[i * dim + static_cast<int>(label[i])],
+                     Dtype(FLT_MIN)));
   }
   // Scale down gradient
   caffe_scal(prob_.count(), Dtype(1) / num, bottom_diff);
index af5f81d..755d47b 100644 (file)
@@ -1,10 +1,11 @@
 // Copyright 2014 Sergio Guadarrama
 
 #include <cuda_runtime.h>
-#include <iostream>
-#include <fstream>
 
+#include <iostream>  // NOLINT(readability/streams)
+#include <fstream>  // NOLINT(readability/streams)
 #include <string>
+#include <vector>
 
 #include "gtest/gtest.h"
 #include "caffe/blob.hpp"
@@ -26,19 +27,19 @@ class ImagesLayerTest : public ::testing::Test {
   ImagesLayerTest()
       : blob_top_data_(new Blob<Dtype>()),
         blob_top_label_(new Blob<Dtype>()),
-        filename(NULL) {};
+        filename(NULL) {}
   virtual void SetUp() {
     blob_top_vec_.push_back(blob_top_data_);
     blob_top_vec_.push_back(blob_top_label_);
     // Create a Vector of files with labels
-    filename = tmpnam(NULL); // get temp name
+    filename = tmpnam(NULL);  // get temp name
     std::ofstream outfile(filename, std::ofstream::out);
     LOG(INFO) << "Using temporary file " << filename;
     for (int i = 0; i < 5; ++i) {
       outfile << "data/cat.jpg " << i;
     }
     outfile.close();
-  };
+  }
 
   virtual ~ImagesLayerTest() { delete blob_top_data_; delete blob_top_label_; }
 
@@ -121,9 +122,10 @@ TYPED_TEST(ImagesLayerTest, TestShuffle) {
   for (int iter = 0; iter < 5; ++iter) {
     layer.Forward(this->blob_bottom_vec_, &this->blob_top_vec_);
     for (int i = 0; i < 5; ++i) {
-      EXPECT_GE(this->blob_top_label_->cpu_data()[i],0);
-      EXPECT_LE(this->blob_top_label_->cpu_data()[i],5);
+      EXPECT_GE(this->blob_top_label_->cpu_data()[i], 0);
+      EXPECT_LE(this->blob_top_label_->cpu_data()[i], 5);
     }
   }
 }
-}
+
+}  // namespace caffe
index d1739da..cb494f2 100644 (file)
@@ -1,8 +1,10 @@
 // Copyright 2013 Yangqing Jia
+
 #include <glog/logging.h>
 #include <leveldb/db.h>
 #include <stdint.h>
 
+#include <algorithm>
 #include <string>
 
 #include "caffe/proto/caffe.pb.h"
@@ -41,7 +43,8 @@ int main(int argc, char** argv) {
   sum_blob.set_height(datum.height());
   sum_blob.set_width(datum.width());
   const int data_size = datum.channels() * datum.height() * datum.width();
-  int size_in_datum = std::max<int>(datum.data().size(), datum.float_data_size());
+  int size_in_datum = std::max<int>(datum.data().size(),
+                                    datum.float_data_size());
   for (int i = 0; i < size_in_datum; ++i) {
     sum_blob.add_data(0.);
   }
@@ -51,14 +54,16 @@ int main(int argc, char** argv) {
     datum.ParseFromString(it->value().ToString());
     const string& data = datum.data();
     size_in_datum = std::max<int>(datum.data().size(), datum.float_data_size());
-    CHECK_EQ(size_in_datum, data_size) << "Incorrect data field size " << size_in_datum;
+    CHECK_EQ(size_in_datum, data_size) << "Incorrect data field size " <<
+        size_in_datum;
     if (data.size() != 0) {
       for (int i = 0; i < size_in_datum; ++i) {
         sum_blob.set_data(i, sum_blob.data(i) + (uint8_t)data[i]);
       }
     } else {
       for (int i = 0; i < size_in_datum; ++i) {
-        sum_blob.set_data(i, sum_blob.data(i) + (float)datum.float_data(i));
+        sum_blob.set_data(i, sum_blob.data(i) +
+            static_cast<float>(datum.float_data(i)));
       }
     }
     ++count;