資源簡介
SSD源碼閱讀的時候,我對SSD源碼創建了QT工程,這樣方便閱讀,提高閱讀效率

代碼片段和文件信息
#include?“Classifier.h“
Classifier::Classifier(const?string&?deploy_file
??????????????????????????????const?string&?caffe_model_file
??????????????????????????????const?string&?label_file
??????????????????????????????const?string&?mean_file)?{
#ifdef?CPU_ONLY
??Caffe::set_mode(Caffe::CPU);
#else
??Caffe::set_mode(Caffe::GPU);
#endif
??/*?Load?the?network.?*/
??//?此時已經給網絡中所有的Blob分配好了內存空間
??net_.reset(new?Net(deploy_file?TEST));?//?加載網絡參數,deploy.prototxt
??net_->CopyTrainedlayersFrom(caffe_model_file);?//?加載權值參數,snapshot_iter_38680.caffemodel
??CHECK_EQ(net_->num_inputs()?1)?<“Network?should?have?exactly?one?input.“;
??CHECK_EQ(net_->num_outputs()?1)?<“Network?should?have?exactly?one?output.“;
??//?第0個Blob就是數據層(輸入層)
??Blob*?input_layer?=?net_->input_blobs()[0];
??num_channels_?=?input_layer->channels();
??CHECK(num_channels_?==?3?||?num_channels_?==?1)
????<“Input?layer?should?have?1?or?3?channels.“;
??input_geometry_?=?cv::Size(input_layer->width()?input_layer->height());
??/*?Load?the?binaryproto?mean?file.?*/
??if(mean_file.empty()||mean_file.size()==0)
??{
????mean_?=?cv::Mat(input_geometry_?CV_MAKETYPE(CV_32FC1num_channels_)?Scalar(000));
??}
??else
??{
????SetMean(mean_file);
??}
??
??/*?Load?labels.?*/
??std::ifstream?labels(label_file.c_str());
??CHECK(labels)?<“Unable?to?open?labels?file?“?<??string?line;
??while?(std::getline(labels?line))
????labels_.push_back(string(line));
??//?第一個輸出Blob對于分類,就是最后輸出的類別數
??Blob*?output_layer?=?net_->output_blobs()[0];
??//?channels就表示類別數
??CHECK_EQ(labels_.size()?output_layer->channels())
????<“Number?of?labels?is?different?from?the?output?layer?dimension.“;
}
static?bool?PairCompare(const?std::pair&?lhs
????????????????????????const?std::pair&?rhs)?{
??return?lhs.first?>?rhs.first;
}
/*?Return?the?indices?of?the?top?N?values?of?vector?v.?*/
static?std::vector?Argmax(const?std::vector&?v?int?N)?{
??std::vector?>?pairs;
??for?(size_t?i?=?0;?i?????pairs.push_back(std::make_pair(v[i]?static_cast(i)));
??//?對第一個到第三個參數當中的前N個大(或者?。┑臄颠M行排序(后面的就不管了),N的個數由第二個參數與第一個參數的差決定。
??std::partial_sort(pairs.begin()?pairs.begin()?+?N?pairs.end()?PairCompare);
??std::vector?result;
??for?(int?i?=?0;?i?????result.push_back(pairs[i].second);
??return?result;
}
/*?步驟:
?*?1.?Mat經過預處理(灰度化,縮放為網絡數據層大小,轉換為float?減去均值)輸入數據層Blob(即轉化為數據層Blob)
*??2.?網絡前向轉播,獲取輸出Blob
*
*/
/*?Return?the?top?N?predictions.?*/
std::vector?Classifier::Classify(const?cv::Mat&?img?int?N)
{
??std::vector?output?=?Predict(img);
??N?=?std::min(labels_.size()?N);
??std::vector?maxN?=?Argmax(output?N);
??std::vector?predictions;
??for?(int?i?=?0;?i?????int?idx?=?maxN[i];
????predictions.push_back(std::make_pair(labels_[idx]?output[idx]));
??}
??r
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????18012??2018-04-26?23:09??Caffe_SSD\Caffe_SSD.pro
?????文件??????18707??2018-03-10?18:49??Caffe_SSD\Caffe_SSD.pro.user
?????文件??????18693??2018-03-03?17:10??Caffe_SSD\Caffe_SSD.pro.user.42a87c0
?????文件??????23780??2018-03-02?21:32??Caffe_SSD\Caffe_SSD.pro.user.6fd70a7
?????文件???????8229??2017-06-26?14:21??Caffe_SSD\Classifier.cpp
?????文件???????1094??2018-03-02?22:50??Caffe_SSD\Classifier.h
?????文件???????7610??2018-04-26?23:11??Caffe_SSD\convert_annoset.cpp
?????文件???????4552??2018-04-26?23:11??Caffe_SSD\main.cpp
?????文件???????9378??2018-01-02?11:07??Caffe_SSD\source\include\caffe\blob.hpp
?????文件????????634??2018-01-02?11:07??Caffe_SSD\source\include\caffe\caffe.hpp
?????文件???????6179??2018-01-02?11:07??Caffe_SSD\source\include\caffe\common.hpp
?????文件???????2161??2018-01-02?11:07??Caffe_SSD\source\include\caffe\data_reader.hpp
?????文件???????9001??2018-01-02?11:07??Caffe_SSD\source\include\caffe\data_transformer.hpp
?????文件??????10935??2018-01-02?11:07??Caffe_SSD\source\include\caffe\filler.hpp
?????文件???????1382??2018-01-02?11:07??Caffe_SSD\source\include\caffe\internal_thread.hpp
?????文件??????18495??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????2343??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????3352??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????1309??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????2727??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????6692??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????2948??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????3025??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????2825??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????1875??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????2307??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????3130??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????4076??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????3930??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
?????文件???????2802??2018-01-02?11:07??Caffe_SSD\source\include\caffe\la
............此處省略390個文件信息
- 上一篇:ispLEVER2.0
- 下一篇:LBP+SVM實驗數據
評論
共有 條評論