From 8ce9236af47257ce483c18056521f58598f5b5af Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Tue, 18 Mar 2014 15:45:42 -0700 Subject: [PATCH] lint, except for rand/rand_r --- include/caffe/vision_layers.hpp | 5 +++-- src/caffe/layers/bnll_layer.cpp | 4 +++- src/caffe/layers/dropout_layer.cpp | 2 ++ src/caffe/layers/hdf5_data_layer.cpp | 2 +- src/caffe/layers/images_layer.cpp | 38 ++++++++++++++++++--------------- src/caffe/layers/relu_layer.cpp | 4 +++- src/caffe/layers/sigmoid_layer.cpp | 6 ++++-- src/caffe/layers/softmax_layer.cpp | 3 +++ src/caffe/layers/softmax_loss_layer.cpp | 3 ++- src/caffe/test/test_images_layer.cpp | 18 +++++++++------- tools/compute_image_mean.cpp | 11 +++++++--- 11 files changed, 60 insertions(+), 36 deletions(-) diff --git a/include/caffe/vision_layers.hpp b/include/caffe/vision_layers.hpp index cb26c98..6225563 100644 --- a/include/caffe/vision_layers.hpp +++ b/include/caffe/vision_layers.hpp @@ -3,8 +3,9 @@ #ifndef CAFFE_VISION_LAYERS_HPP_ #define CAFFE_VISION_LAYERS_HPP_ -#include #include +#include +#include #include "leveldb/db.h" #include "pthread.h" @@ -414,7 +415,7 @@ void* ImagesLayerPrefetch(void* layer_pointer); template class ImagesLayer : public Layer { // The function used to perform prefetching. - friend void* ImagesLayerPrefetch(void* layer_pointer); + friend void* ImagesLayerPrefetch(void* layer_pointer); public: explicit ImagesLayer(const LayerParameter& param) diff --git a/src/caffe/layers/bnll_layer.cpp b/src/caffe/layers/bnll_layer.cpp index ab0e0f0..b769a35 100644 --- a/src/caffe/layers/bnll_layer.cpp +++ b/src/caffe/layers/bnll_layer.cpp @@ -1,8 +1,10 @@ // Copyright 2013 Yangqing Jia +#include +#include + #include "caffe/layer.hpp" #include "caffe/vision_layers.hpp" -#include using std::min; diff --git a/src/caffe/layers/dropout_layer.cpp b/src/caffe/layers/dropout_layer.cpp index 4e1fbfa..f480853 100644 --- a/src/caffe/layers/dropout_layer.cpp +++ b/src/caffe/layers/dropout_layer.cpp @@ -1,5 +1,7 @@ // Copyright 2013 Yangqing Jia +#include + #include "caffe/common.hpp" #include "caffe/layer.hpp" #include "caffe/syncedmem.hpp" diff --git a/src/caffe/layers/hdf5_data_layer.cpp b/src/caffe/layers/hdf5_data_layer.cpp index 60e25d0..e5b17fe 100644 --- a/src/caffe/layers/hdf5_data_layer.cpp +++ b/src/caffe/layers/hdf5_data_layer.cpp @@ -14,7 +14,7 @@ TODO: #include #include #include -#include +#include // NOLINT(readability/streams) #include "hdf5.h" #include "hdf5_hl.h" diff --git a/src/caffe/layers/images_layer.cpp b/src/caffe/layers/images_layer.cpp index ab3f8b0..eb1b89e 100644 --- a/src/caffe/layers/images_layer.cpp +++ b/src/caffe/layers/images_layer.cpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include // NOLINT(readability/streams) +#include // NOLINT(readability/streams) #include "caffe/layer.hpp" #include "caffe/util/io.hpp" @@ -21,7 +21,8 @@ namespace caffe { template void* ImagesLayerPrefetch(void* layer_pointer) { CHECK(layer_pointer); - ImagesLayer* layer = reinterpret_cast*>(layer_pointer); + ImagesLayer* layer = + reinterpret_cast*>(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(NULL); } template @@ -136,13 +138,15 @@ void ImagesLayer::SetUp(const vector*>& bottom, vector*>* 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::SetUp(const vector*>& 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) { diff --git a/src/caffe/layers/relu_layer.cpp b/src/caffe/layers/relu_layer.cpp index 478ed31..27ae94b 100644 --- a/src/caffe/layers/relu_layer.cpp +++ b/src/caffe/layers/relu_layer.cpp @@ -1,8 +1,10 @@ // Copyright 2013 Yangqing Jia +#include +#include + #include "caffe/layer.hpp" #include "caffe/vision_layers.hpp" -#include using std::max; diff --git a/src/caffe/layers/sigmoid_layer.cpp b/src/caffe/layers/sigmoid_layer.cpp index 112771f..ba6ec84 100644 --- a/src/caffe/layers/sigmoid_layer.cpp +++ b/src/caffe/layers/sigmoid_layer.cpp @@ -1,9 +1,11 @@ // Copyright 2014 Tobias Domhan -#include "caffe/layer.hpp" -#include "caffe/vision_layers.hpp" #include #include +#include + +#include "caffe/layer.hpp" +#include "caffe/vision_layers.hpp" namespace caffe { diff --git a/src/caffe/layers/softmax_layer.cpp b/src/caffe/layers/softmax_layer.cpp index 172094d..69e95ff 100644 --- a/src/caffe/layers/softmax_layer.cpp +++ b/src/caffe/layers/softmax_layer.cpp @@ -1,4 +1,7 @@ // Copyright 2013 Yangqing Jia +// +#include +#include #include "caffe/layer.hpp" #include "caffe/vision_layers.hpp" diff --git a/src/caffe/layers/softmax_loss_layer.cpp b/src/caffe/layers/softmax_loss_layer.cpp index 2ec7308..6fdaea5 100644 --- a/src/caffe/layers/softmax_loss_layer.cpp +++ b/src/caffe/layers/softmax_loss_layer.cpp @@ -45,7 +45,8 @@ Dtype SoftmaxWithLossLayer::Backward_cpu(const vector*>& top, Dtype loss = 0; for (int i = 0; i < num; ++i) { bottom_diff[i * dim + static_cast(label[i])] -= 1; - loss += -log(max(prob_data[i * dim + static_cast(label[i])], Dtype(FLT_MIN))); + loss += -log(max(prob_data[i * dim + static_cast(label[i])], + Dtype(FLT_MIN))); } // Scale down gradient caffe_scal(prob_.count(), Dtype(1) / num, bottom_diff); diff --git a/src/caffe/test/test_images_layer.cpp b/src/caffe/test/test_images_layer.cpp index af5f81d..755d47b 100644 --- a/src/caffe/test/test_images_layer.cpp +++ b/src/caffe/test/test_images_layer.cpp @@ -1,10 +1,11 @@ // Copyright 2014 Sergio Guadarrama #include -#include -#include +#include // NOLINT(readability/streams) +#include // NOLINT(readability/streams) #include +#include #include "gtest/gtest.h" #include "caffe/blob.hpp" @@ -26,19 +27,19 @@ class ImagesLayerTest : public ::testing::Test { ImagesLayerTest() : blob_top_data_(new Blob()), blob_top_label_(new Blob()), - 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 diff --git a/tools/compute_image_mean.cpp b/tools/compute_image_mean.cpp index d1739da..cb494f2 100644 --- a/tools/compute_image_mean.cpp +++ b/tools/compute_image_mean.cpp @@ -1,8 +1,10 @@ // Copyright 2013 Yangqing Jia + #include #include #include +#include #include #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(datum.data().size(), datum.float_data_size()); + int size_in_datum = std::max(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(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(datum.float_data(i))); } } ++count; -- 2.7.4