From ac857090defd4eb48faf23f03a527de9cbdb5262 Mon Sep 17 00:00:00 2001 From: tujie-jiangye <3293375273@qq.com> Date: Sat, 5 May 2018 19:28:44 +0800 Subject: [PATCH 1/8] Modifications are made for improvements in non-standard images or labels, and regression problems are applied. The improved Caffe can handle the standard image multi label regression problem and is very adaptable to non-standard image data. Compared to the support of native Caffe to the regression problem, this modification not only makes the use more simple, but also has a good performance in the slow convergence or non convergence of loss on some regression problems. --- include/caffe/util/io.hpp | 9 ++++ src/caffe/layers/data_layer.cpp | 95 ++++++++++++++++----------------- src/caffe/util/io.cpp | 36 +++++++++++++ tools/convert_imageset.cpp | 44 ++++++++++++--- 4 files changed, 126 insertions(+), 58 deletions(-) diff --git a/include/caffe/util/io.hpp b/include/caffe/util/io.hpp index 376b67ee4..58cad1de7 100644 --- a/include/caffe/util/io.hpp +++ b/include/caffe/util/io.hpp @@ -169,6 +169,15 @@ bool ReadImageToDatum(const string& filename, const int label, const int height, const int width, const bool is_color, const std::string & encoding, Datum* datum); +/* +** overload function ReadImageDatum +** the overloaded function aimed to solve the regression problem +** here is shown to be able to handle unlabeled data, such as float data +*/ +bool ReadImageToDatum(const string& filename, const vector labels, + const int height, const int width, const bool is_color, + const std::string & encoding, Datum* datum); + inline bool ReadImageToDatum(const string& filename, const int label, const int height, const int width, const bool is_color, Datum* datum) { return ReadImageToDatum(filename, label, height, width, is_color, diff --git a/src/caffe/layers/data_layer.cpp b/src/caffe/layers/data_layer.cpp index e889ca51f..426db7e91 100644 --- a/src/caffe/layers/data_layer.cpp +++ b/src/caffe/layers/data_layer.cpp @@ -35,11 +35,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #ifdef USE_OPENCV #include #endif // USE_OPENCV #include -#include + #include #include "caffe/data_transformer.hpp" @@ -64,15 +65,13 @@ void DataLayer::DataLayerSetUp(const vector*>& bottom, const vector*>& top) { const int batch_size = this->layer_param_.data_param().batch_size(); // Read a data point, and use it to initialize the top blob. - Datum datum; - datum.ParseFromString(*(reader_.full().peek())); + Datum& datum = *(reader_.full().peek()); // Use data_transformer to infer the expected blob shape from datum. vector top_shape = this->data_transformer_->InferBlobShape(datum); this->transformed_data_.Reshape(top_shape); // Reshape top[0] and prefetch_data according to the batch_size. top_shape[0] = batch_size; - top[0]->Reshape(top_shape); for (int i = 0; i < this->PREFETCH_COUNT; ++i) { this->prefetch_[i].data_.Reshape(top_shape); @@ -80,9 +79,26 @@ void DataLayer::DataLayerSetUp(const vector*>& bottom, LOG(INFO) << "output data size: " << top[0]->num() << "," << top[0]->channels() << "," << top[0]->height() << "," << top[0]->width(); + // label + //### + // if (this->output_labels_) { + // vector label_shape(1, batch_size); + // top[1]->Reshape(label_shape); + // for (int i = 0; i < this->PREFETCH_COUNT; ++i) { + // this->prefetch_[i].label_.Reshape(label_shape); + // } + // } + + //### + int labelNum = 4; if (this->output_labels_) { - vector label_shape(1, batch_size); + + vector label_shape; + label_shape.push_back(batch_size); + label_shape.push_back(labelNum); + label_shape.push_back(1); + label_shape.push_back(1); top[1]->Reshape(label_shape); for (int i = 0; i < this->PREFETCH_COUNT; ++i) { this->prefetch_[i].label_.Reshape(label_shape); @@ -98,23 +114,16 @@ void DataLayer::load_batch(Batch* batch) { double read_time = 0; double trans_time = 0; CPUTimer timer; - CPUTimer trans_timer; CHECK(batch->data_.count()); - -#ifndef _OPENMP CHECK(this->transformed_data_.count()); -#endif // Reshape according to the first datum of each batch // on single input batches allows for inputs of varying dimension. const int batch_size = this->layer_param_.data_param().batch_size(); - Datum datum; - datum.ParseFromString(*(reader_.full().peek())); + Datum& datum = *(reader_.full().peek()); // Use data_transformer to infer the expected blob shape from datum. vector top_shape = this->data_transformer_->InferBlobShape(datum); -#ifndef _OPENMP this->transformed_data_.Reshape(top_shape); -#endif // Reshape batch according to the batch_size. top_shape[0] = batch_size; batch->data_.Reshape(top_shape); @@ -125,52 +134,38 @@ void DataLayer::load_batch(Batch* batch) { if (this->output_labels_) { top_label = batch->label_.mutable_cpu_data(); } - - trans_timer.Start(); -#ifdef _OPENMP - #pragma omp parallel if (batch_size > 1) - #pragma omp single nowait -#endif for (int item_id = 0; item_id < batch_size; ++item_id) { timer.Start(); // get a datum - string* data = (reader_.full().pop("Waiting for data")); - timer.Stop(); + Datum& datum = *(reader_.full().pop("Waiting for data")); read_time += timer.MicroSeconds(); + timer.Start(); // Apply data transformations (mirror, scale, crop...) int offset = batch->data_.offset(item_id); - -#ifdef _OPENMP - PreclcRandomNumbers precalculated_rand_numbers; - this->data_transformer_->GenerateRandNumbers(precalculated_rand_numbers); - #pragma omp task firstprivate(offset, precalculated_rand_numbers, data, item_id) -#endif - { - Datum datum; - datum.ParseFromString(*data); - (reader_.free()).push(data); - // Copy label. We need to copy it before we release datum - if (this->output_labels_) { - top_label[item_id] = datum.label(); + this->transformed_data_.set_cpu_data(top_data + offset); + this->data_transformer_->Transform(datum, &(this->transformed_data_)); + + // Copy label. + //### + // if (this->output_labels_) { + // top_label[item_id] = datum.label(); + // } + + //### + int labelNum = 4; + if (this->output_labels_) { + for(int i=0;i tmp_data; - tmp_data.Reshape(top_shape); - tmp_data.set_cpu_data(top_data + offset); - this->data_transformer_->Transform(datum, &tmp_data, - precalculated_rand_numbers); -#else - this->transformed_data_.set_cpu_data(top_data + offset); - this->data_transformer_->Transform(datum, &(this->transformed_data_)); -#endif } + + + trans_time += timer.MicroSeconds(); + + reader_.free().push(const_cast(&datum)); } - trans_timer.Stop(); + timer.Stop(); batch_timer.Stop(); - // Due to multithreaded nature of transformation, - // time it takes to execute them we get from subtracting - // read batch of images time from total batch read&transform time - trans_time = trans_timer.MicroSeconds() - read_time; DLOG(INFO) << "Prefetch batch: " << batch_timer.MilliSeconds() << " ms."; DLOG(INFO) << " Read time: " << read_time / 1000 << " ms."; DLOG(INFO) << "Transform time: " << trans_time / 1000 << " ms."; @@ -179,4 +174,4 @@ void DataLayer::load_batch(Batch* batch) { INSTANTIATE_CLASS(DataLayer); REGISTER_LAYER_CLASS(Data); -} // namespace caffe +} // namespace caffe \ No newline at end of file diff --git a/src/caffe/util/io.cpp b/src/caffe/util/io.cpp index ba70dc744..35a8d4add 100644 --- a/src/caffe/util/io.cpp +++ b/src/caffe/util/io.cpp @@ -254,6 +254,42 @@ bool ReadImageToDatum(const string& filename, const int label, } } +/* +** here is the realization of reloaded function +*/ +bool ReadImageToDatum(const string& filename, const vector labels, + const int height, const int width, const bool is_color, + const std::string & encoding, Datum* datum) { + cv::Mat cv_img = ReadImageToCVMat(filename, height, width, is_color); + if (cv_img.data) { + // if (encoding.size()) { + // if ( (cv_img.channels() == 3) == is_color && !height && !width && + // matchExt(filename, encoding) ) + // return ReadFileToDatum(filename, label, datum); + // std::vector buf; + // cv::imencode("."+encoding, cv_img, buf); + // datum->set_data(std::string(reinterpret_cast(&buf[0]), + // buf.size())); + // datum->set_label(label); + // datum->set_encoded(true); + // return true; + // } + + CVMatToDatum(cv_img, datum); + //datum->set_label(label); + + //### + for (int i = 0; i < labels.size(); ++i) + { + datum->add_float_data(labels.at(i)); + } + + return true; + } else { + return false; + } +} + void GetImageSize(const string& filename, int* height, int* width) { cv::Mat cv_img = cv::imread(filename); if (!cv_img.data) { diff --git a/tools/convert_imageset.cpp b/tools/convert_imageset.cpp index d11c15c41..e635cc94a 100644 --- a/tools/convert_imageset.cpp +++ b/tools/convert_imageset.cpp @@ -61,10 +61,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "caffe/util/io.hpp" #include "caffe/util/rng.hpp" +#include //### To use tokenizer +#include //### + using namespace caffe; // NOLINT(build/namespaces) using std::pair; using boost::scoped_ptr; +using namespace std; //### + DEFINE_bool(gray, false, "When this option is on, treat images as grayscale ones"); DEFINE_bool(shuffle, false, @@ -107,16 +112,39 @@ int main(int argc, char** argv) { const bool check_size = FLAGS_check_size; const bool encoded = FLAGS_encoded; const string encode_type = FLAGS_encode_type; - + std::ifstream infile(argv[2]); - std::vector > lines; + //std::vector > lines; //### + /* + ** change the label value from int to vector + ** the purpose of this change is to enable the regression problem + ** the integer value does not support multiple label or the float value + */ + std::vector > > lines; std::string line; - size_t pos; - int label; + //size_t pos; + //int label; //### + std::vector labels; + while (std::getline(infile, line)) { - pos = line.find_last_of(' '); - label = atoi(line.substr(pos + 1).c_str()); - lines.push_back(std::make_pair(line.substr(0, pos), label)); + // pos = line.find_last_of(' '); + // label = atoi(line.substr(pos + 1).c_str()); + // lines.push_back(std::make_pair(line.substr(0, pos), label)); + //### + std::vector tokens; + boost::char_separator sep(" "); + boost::tokenizer > tok(line, sep); + tokens.clear(); + std::copy(tok.begin(), tok.end(), std::back_inserter(tokens)); + + for (int i = 1; i < tokens.size(); ++i) + { + labels.push_back(atof(tokens.at(i).c_str())); + } + + lines.push_back(std::make_pair(tokens.at(0), labels)); + //###To clear the vector labels + labels.clear(); } if (FLAGS_shuffle) { // randomly shuffle data @@ -155,7 +183,7 @@ int main(int argc, char** argv) { enc = fn.substr(p); std::transform(enc.begin(), enc.end(), enc.begin(), ::tolower); } - status = ReadImageToDatum(root_folder + lines[line_id].first, + status = ReadImageToDatum(root_folder + lines[line_id].first, //### lines[line_id].second, resize_height, resize_width, is_color, enc, &datum); if (status == false) continue; From b635748b3291642f95d66a97ab983cdcb83aefd4 Mon Sep 17 00:00:00 2001 From: tujie-jiangye <3293375273@qq.com> Date: Sun, 6 May 2018 10:36:40 +0800 Subject: [PATCH 2/8] Repair some of the bug --- tools/convert_imageset.cpp | 46 ++++++++------------------------------ 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/tools/convert_imageset.cpp b/tools/convert_imageset.cpp index e635cc94a..7a5dea88e 100644 --- a/tools/convert_imageset.cpp +++ b/tools/convert_imageset.cpp @@ -61,15 +61,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "caffe/util/io.hpp" #include "caffe/util/rng.hpp" -#include //### To use tokenizer -#include //### - using namespace caffe; // NOLINT(build/namespaces) using std::pair; using boost::scoped_ptr; -using namespace std; //### - DEFINE_bool(gray, false, "When this option is on, treat images as grayscale ones"); DEFINE_bool(shuffle, false, @@ -112,39 +107,16 @@ int main(int argc, char** argv) { const bool check_size = FLAGS_check_size; const bool encoded = FLAGS_encoded; const string encode_type = FLAGS_encode_type; - + std::ifstream infile(argv[2]); - //std::vector > lines; //### - /* - ** change the label value from int to vector - ** the purpose of this change is to enable the regression problem - ** the integer value does not support multiple label or the float value - */ - std::vector > > lines; + std::vector > lines; std::string line; - //size_t pos; - //int label; //### - std::vector labels; - + size_t pos; + int label; while (std::getline(infile, line)) { - // pos = line.find_last_of(' '); - // label = atoi(line.substr(pos + 1).c_str()); - // lines.push_back(std::make_pair(line.substr(0, pos), label)); - //### - std::vector tokens; - boost::char_separator sep(" "); - boost::tokenizer > tok(line, sep); - tokens.clear(); - std::copy(tok.begin(), tok.end(), std::back_inserter(tokens)); - - for (int i = 1; i < tokens.size(); ++i) - { - labels.push_back(atof(tokens.at(i).c_str())); - } - - lines.push_back(std::make_pair(tokens.at(0), labels)); - //###To clear the vector labels - labels.clear(); + pos = line.find_last_of(' '); + label = atoi(line.substr(pos + 1).c_str()); + lines.push_back(std::make_pair(line.substr(0, pos), label)); } if (FLAGS_shuffle) { // randomly shuffle data @@ -183,7 +155,7 @@ int main(int argc, char** argv) { enc = fn.substr(p); std::transform(enc.begin(), enc.end(), enc.begin(), ::tolower); } - status = ReadImageToDatum(root_folder + lines[line_id].first, //### + status = ReadImageToDatum(root_folder + lines[line_id].first, lines[line_id].second, resize_height, resize_width, is_color, enc, &datum); if (status == false) continue; @@ -221,4 +193,4 @@ int main(int argc, char** argv) { LOG(FATAL) << "This tool requires OpenCV; compile with USE_OPENCV."; #endif // USE_OPENCV return 0; -} +} \ No newline at end of file From 3e3853ca404953f27c20074c050551628963f926 Mon Sep 17 00:00:00 2001 From: tujie-jiangye <3293375273@qq.com> Date: Sun, 6 May 2018 10:40:56 +0800 Subject: [PATCH 3/8] Repair some of the bug --- tools/convert_imageset_regression.cpp | 224 ++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 tools/convert_imageset_regression.cpp diff --git a/tools/convert_imageset_regression.cpp b/tools/convert_imageset_regression.cpp new file mode 100644 index 000000000..1bc805eb4 --- /dev/null +++ b/tools/convert_imageset_regression.cpp @@ -0,0 +1,224 @@ +/* +All modification made by Intel Corporation: © 2016 Intel Corporation + +All contributions by the University of California: +Copyright (c) 2014, 2015, The Regents of the University of California (Regents) +All rights reserved. + +All other contributions: +Copyright (c) 2014, 2015, the respective contributors +All rights reserved. +For the list of contributors go to https://github.com/BVLC/caffe/blob/master/CONTRIBUTORS.md + + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// This program converts a set of images to a lmdb/leveldb by storing them +// as Datum proto buffers. +// Usage: +// convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME +// +// where ROOTFOLDER is the root folder that holds all the images, and LISTFILE +// should be a list of files as well as their labels, in the format as +// subfolder1/file1.JPEG 7 +// .... + +#include +#include // NOLINT(readability/streams) +#include +#include +#include + +#include "boost/scoped_ptr.hpp" +#include "gflags/gflags.h" +#include "glog/logging.h" + +#include "caffe/proto/caffe.pb.h" +#include "caffe/util/db.hpp" +#include "caffe/util/format.hpp" +#include "caffe/util/io.hpp" +#include "caffe/util/rng.hpp" + +#include //### To use tokenizer +#include //### + +using namespace caffe; // NOLINT(build/namespaces) +using std::pair; +using boost::scoped_ptr; + +using namespace std; //### + +DEFINE_bool(gray, false, + "When this option is on, treat images as grayscale ones"); +DEFINE_bool(shuffle, false, + "Randomly shuffle the order of images and their labels"); +DEFINE_string(backend, "lmdb", + "The backend {lmdb, leveldb} for storing the result"); +DEFINE_int32(resize_width, 0, "Width images are resized to"); +DEFINE_int32(resize_height, 0, "Height images are resized to"); +DEFINE_bool(check_size, false, + "When this option is on, check that all the datum have the same size"); +DEFINE_bool(encoded, false, + "When this option is on, the encoded image will be save in datum"); +DEFINE_string(encode_type, "", + "Optional: What type should we encode the image as ('png','jpg',...)."); + +int main(int argc, char** argv) { +#ifdef USE_OPENCV + ::google::InitGoogleLogging(argv[0]); + // Print output to stderr (while still logging) + FLAGS_alsologtostderr = 1; + +#ifndef GFLAGS_GFLAGS_H_ + namespace gflags = google; +#endif + + gflags::SetUsageMessage("Convert a set of images to the leveldb/lmdb\n" + "format used as input for Caffe.\n" + "Usage:\n" + " convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME\n" + "The ImageNet dataset for the training demo is at\n" + " http://www.image-net.org/download-images\n"); + gflags::ParseCommandLineFlags(&argc, &argv, true); + + if (argc < 4) { + gflags::ShowUsageWithFlagsRestrict(argv[0], "tools/convert_imageset"); + return 1; + } + + const bool is_color = !FLAGS_gray; + const bool check_size = FLAGS_check_size; + const bool encoded = FLAGS_encoded; + const string encode_type = FLAGS_encode_type; + + std::ifstream infile(argv[2]); + //std::vector > lines; //### + /* + ** change the label value from int to vector + ** the purpose of this change is to enable the regression problem + ** the integer value does not support multiple label or the float value + */ + std::vector > > lines; + std::string line; + //size_t pos; + //int label; //### + std::vector labels; + + while (std::getline(infile, line)) { + // pos = line.find_last_of(' '); + // label = atoi(line.substr(pos + 1).c_str()); + // lines.push_back(std::make_pair(line.substr(0, pos), label)); + //### + std::vector tokens; + boost::char_separator sep(" "); + boost::tokenizer > tok(line, sep); + tokens.clear(); + std::copy(tok.begin(), tok.end(), std::back_inserter(tokens)); + + for (int i = 1; i < tokens.size(); ++i) + { + labels.push_back(atof(tokens.at(i).c_str())); + } + + lines.push_back(std::make_pair(tokens.at(0), labels)); + //###To clear the vector labels + labels.clear(); + } + if (FLAGS_shuffle) { + // randomly shuffle data + LOG(INFO) << "Shuffling data"; + shuffle(lines.begin(), lines.end()); + } + LOG(INFO) << "A total of " << lines.size() << " images."; + + if (encode_type.size() && !encoded) + LOG(INFO) << "encode_type specified, assuming encoded=true."; + + int resize_height = std::max(0, FLAGS_resize_height); + int resize_width = std::max(0, FLAGS_resize_width); + + // Create new DB + scoped_ptr db(db::GetDB(FLAGS_backend)); + db->Open(argv[3], db::NEW); + scoped_ptr txn(db->NewTransaction()); + + // Storing to db + std::string root_folder(argv[1]); + Datum datum; + int count = 0; + int data_size = 0; + bool data_size_initialized = false; + + for (int line_id = 0; line_id < lines.size(); ++line_id) { + bool status; + std::string enc = encode_type; + if (encoded && !enc.size()) { + // Guess the encoding type from the file name + string fn = lines[line_id].first; + size_t p = fn.rfind('.'); + if ( p == fn.npos ) + LOG(WARNING) << "Failed to guess the encoding of '" << fn << "'"; + enc = fn.substr(p); + std::transform(enc.begin(), enc.end(), enc.begin(), ::tolower); + } + status = ReadImageToDatum(root_folder + lines[line_id].first, //### + lines[line_id].second, resize_height, resize_width, is_color, + enc, &datum); + if (status == false) continue; + if (check_size) { + if (!data_size_initialized) { + data_size = datum.channels() * datum.height() * datum.width(); + data_size_initialized = true; + } else { + const std::string& data = datum.data(); + CHECK_EQ(data.size(), data_size) << "Incorrect data field size " + << data.size(); + } + } + // sequential + string key_str = caffe::format_int(line_id, 8) + "_" + lines[line_id].first; + + // Put in db + string out; + CHECK(datum.SerializeToString(&out)); + txn->Put(key_str, out); + + if (++count % 1000 == 0) { + // Commit db + txn->Commit(); + txn.reset(db->NewTransaction()); + LOG(INFO) << "Processed " << count << " files."; + } + } + // write the last batch + if (count % 1000 != 0) { + txn->Commit(); + LOG(INFO) << "Processed " << count << " files."; + } +#else + LOG(FATAL) << "This tool requires OpenCV; compile with USE_OPENCV."; +#endif // USE_OPENCV + return 0; +} \ No newline at end of file From f7fe17ace4ca771d326f344968a0ed3f66385796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=9C=9F=E6=9D=B0?= <3293375273@qq.com> Date: Fri, 18 May 2018 23:28:45 +0800 Subject: [PATCH 4/8] delete some useful line delete some useful line --- src/caffe/util/io.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/caffe/util/io.cpp b/src/caffe/util/io.cpp index 35a8d4add..ea9a8e69d 100644 --- a/src/caffe/util/io.cpp +++ b/src/caffe/util/io.cpp @@ -261,29 +261,12 @@ bool ReadImageToDatum(const string& filename, const vector labels, const int height, const int width, const bool is_color, const std::string & encoding, Datum* datum) { cv::Mat cv_img = ReadImageToCVMat(filename, height, width, is_color); - if (cv_img.data) { - // if (encoding.size()) { - // if ( (cv_img.channels() == 3) == is_color && !height && !width && - // matchExt(filename, encoding) ) - // return ReadFileToDatum(filename, label, datum); - // std::vector buf; - // cv::imencode("."+encoding, cv_img, buf); - // datum->set_data(std::string(reinterpret_cast(&buf[0]), - // buf.size())); - // datum->set_label(label); - // datum->set_encoded(true); - // return true; - // } - + if (cv_img.data) { CVMatToDatum(cv_img, datum); - //datum->set_label(label); - - //### for (int i = 0; i < labels.size(); ++i) { datum->add_float_data(labels.at(i)); } - return true; } else { return false; From 455aa08bd23def33dec8a9a9cbdeee94a0283744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=9C=9F=E6=9D=B0?= <3293375273@qq.com> Date: Fri, 18 May 2018 23:36:20 +0800 Subject: [PATCH 5/8] Update convert_imageset.cpp --- tools/convert_imageset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/convert_imageset.cpp b/tools/convert_imageset.cpp index 7a5dea88e..d11c15c41 100644 --- a/tools/convert_imageset.cpp +++ b/tools/convert_imageset.cpp @@ -193,4 +193,4 @@ int main(int argc, char** argv) { LOG(FATAL) << "This tool requires OpenCV; compile with USE_OPENCV."; #endif // USE_OPENCV return 0; -} \ No newline at end of file +} From abbc33fb7a8aaaefd3f9c4a4cb0e3024cb7325ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=9C=9F=E6=9D=B0?= <3293375273@qq.com> Date: Fri, 18 May 2018 23:37:11 +0800 Subject: [PATCH 6/8] Update data_layer.cpp --- src/caffe/layers/data_layer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/caffe/layers/data_layer.cpp b/src/caffe/layers/data_layer.cpp index 426db7e91..a58b8f5bb 100644 --- a/src/caffe/layers/data_layer.cpp +++ b/src/caffe/layers/data_layer.cpp @@ -174,4 +174,4 @@ void DataLayer::load_batch(Batch* batch) { INSTANTIATE_CLASS(DataLayer); REGISTER_LAYER_CLASS(Data); -} // namespace caffe \ No newline at end of file +} // namespace caffe From 347f1fc43a00cdb24fe94776fd35005874a6c6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=9C=9F=E6=9D=B0?= <3293375273@qq.com> Date: Fri, 18 May 2018 23:37:48 +0800 Subject: [PATCH 7/8] Update convert_imageset_regression.cpp --- tools/convert_imageset_regression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/convert_imageset_regression.cpp b/tools/convert_imageset_regression.cpp index 1bc805eb4..e635cc94a 100644 --- a/tools/convert_imageset_regression.cpp +++ b/tools/convert_imageset_regression.cpp @@ -221,4 +221,4 @@ int main(int argc, char** argv) { LOG(FATAL) << "This tool requires OpenCV; compile with USE_OPENCV."; #endif // USE_OPENCV return 0; -} \ No newline at end of file +} From 69fad138a76de45d50f46a16cb2d8805ed43a353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=9C=9F=E6=9D=B0?= <3293375273@qq.com> Date: Fri, 18 May 2018 23:41:54 +0800 Subject: [PATCH 8/8] Revision of code specification Revision of code specification --- src/caffe/layers/data_layer.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/caffe/layers/data_layer.cpp b/src/caffe/layers/data_layer.cpp index a58b8f5bb..cd5abb3d2 100644 --- a/src/caffe/layers/data_layer.cpp +++ b/src/caffe/layers/data_layer.cpp @@ -79,18 +79,6 @@ void DataLayer::DataLayerSetUp(const vector*>& bottom, LOG(INFO) << "output data size: " << top[0]->num() << "," << top[0]->channels() << "," << top[0]->height() << "," << top[0]->width(); - - // label - //### - // if (this->output_labels_) { - // vector label_shape(1, batch_size); - // top[1]->Reshape(label_shape); - // for (int i = 0; i < this->PREFETCH_COUNT; ++i) { - // this->prefetch_[i].label_.Reshape(label_shape); - // } - // } - - //### int labelNum = 4; if (this->output_labels_) { @@ -145,13 +133,6 @@ void DataLayer::load_batch(Batch* batch) { this->transformed_data_.set_cpu_data(top_data + offset); this->data_transformer_->Transform(datum, &(this->transformed_data_)); - // Copy label. - //### - // if (this->output_labels_) { - // top_label[item_id] = datum.label(); - // } - - //### int labelNum = 4; if (this->output_labels_) { for(int i=0;i