/* * Software License Agreement (BSD License) * * Copyright (c) 2009, Willow Garage, Inc. * All rights reserved. * * 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 Willow Garage, Inc. 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. * */ #include #include // for snprintf #include #include #include #include "google/protobuf/text_format.h" #include #include #define CPU_ONLY #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/net.hpp" #include "caffe/proto/caffe.pb.h" #include "caffe/util/io.hpp" #include "caffe/vision_layers.hpp" using caffe::Blob; using caffe::Caffe; using caffe::Datum; using caffe::Net; //using boost::shared_ptr; using std::string; //namespace db = caffe::db; using namespace cv; using namespace std; using namespace cv::cnn_3dobj; int main(int argc, char* argv[]) { const String keys = "{help | | this demo will convert a set of images in a particular path into leveldb database for feature extraction using Caffe.}" "{src_dir | ../data/images_all/ | Source direction of the images ready for being converted to leveldb dataset.}" "{src_dst | ../data/dbfile | Aim direction of the converted to leveldb dataset. }" "{attach_dir | ../data/dbfile | Path for saving additional files which describe the transmission results. }" "{channel | 1 | Channel of the images. }" "{width | 64 | Width of images}" "{height | 64 | Height of images}" "{pretrained_binary_proto | ../data/3d_triplet_iter_10000.caffemodel | caffe model for feature exrtaction.}" "{feature_extraction_proto | ../data/3d_triplet_train_test.prototxt | network definition in .prototxt the path of the training samples must be wrotten in in .prototxt files in Phase TEST}" "{save_feature_dataset_names | ../data/feature/feature_iter_10000.bin | the output of the extracted feature in form of binary files together with the vector features as the feature.}" "{extract_feature_blob_names | feat | the layer used for feature extraction in CNN.}" "{num_mini_batches | 6 | batches suit for the batches defined in the .proto for the aim of extracting feature from all images.}" "{device | CPU | device}" "{dev_id | 0 | dev_id}"; cv::CommandLineParser parser(argc, argv, keys); parser.about("Demo for Sphere View data generation"); if (parser.has("help")) { parser.printMessage(); return 0; } string src_dir = parser.get("src_dir"); string src_dst = parser.get("src_dst"); string attach_dir = parser.get("attach_dir"); int channel = parser.get("channel"); int width = parser.get("width"); int height = parser.get("height"); string pretrained_binary_proto = parser.get("pretrained_binary_proto"); string feature_extraction_proto = parser.get("feature_extraction_proto"); string save_feature_dataset_names = parser.get("save_feature_dataset_names"); string extract_feature_blob_names = parser.get("extract_feature_blob_names"); int num_mini_batches = parser.get("num_mini_batches"); string device = parser.get("device"); int dev_id = parser.get("dev_id"); cv::cnn_3dobj::DataTrans transTemp; transTemp.convert(src_dir,src_dst,attach_dir,channel,width,height); std::vector extractedFeature = transTemp.feature_extraction_pipeline(pretrained_binary_proto, feature_extraction_proto, save_feature_dataset_names, extract_feature_blob_names, num_mini_batches, device, dev_id); }