91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

將此cpp替換掉vs2015編譯好的caffe里的classification.cpp,輸入不同的模型參數,最終效果很好

資源截圖

代碼片段和文件信息

#include?
#ifdef?USE_OPENCV
#include?
#include?
#include?
#endif??//?USE_OPENCV
#include?
#include?
#include?
#include?
#include?
#include?


using?namespace?caffe;??//?NOLINT(build/namespaces)
using?std::string;

/*?Pair?(label?confidence)?representing?a?prediction.?*/
typedef?std::pair?Prediction;

class?Classifier?{
public:
Classifier(const?string&?model_file
const?string&?trained_file
const?string&?mean_file
const?string&?label_file);

std::vector?Classify(const?cv::Mat&?img?int?N?=?10);

private:
void?SetMean(const?string&?mean_file);

std::vector?Predict(const?cv::Mat&?img);

void?WrapInputlayer(std::vector*?input_channels);

void?Preprocess(const?cv::Mat&?img
std::vector*?input_channels);

private:
shared_ptr?>?net_;
cv::Size?input_geometry_;
int?num_channels_;
cv::Mat?mean_;
std::vector?labels_;
};

Classifier::Classifier(const?string&?model_file
const?string&?trained_file
const?string&?mean_file
const?string&?label_file)?{

Caffe::set_mode(Caffe::GPU);


/*?Load?the?network.?*/
net_.reset(new?Net(model_file?TEST));
net_->CopyTrainedlayersFrom(trained_file);

CHECK_EQ(net_->num_inputs()?1)?< CHECK_EQ(net_->num_outputs()?1)?<
Blob*?input_layer?=?net_->input_blobs()[0];
num_channels_?=?input_layer->channels();
CHECK(num_channels_?==?3?||?num_channels_?==?1)
<yer?should?have?1?or?3?channels.“;
input_geometry_?=?cv::Size(input_layer->width()?input_layer->height());

/*?Load?the?binaryproto?mean?file.?*/
SetMean(mean_file);

/*?Load?labels.?*/
std::ifstream?labels(label_file.c_str());
CHECK(labels)?< string?line;
while?(std::getline(labels?line))
labels_.push_back(string(line));

Blob*?output_layer?=?net_->output_blobs()[0];
CHECK_EQ(labels_.size()?output_layer->channels())
<yer?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]?i));
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;
}

/*?Return?the?top?N?predictions.?*/
std::vector?Classifier::Classify(const?cv::Mat&?

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????8801??2018-06-30?16:05??myclassification.cpp

-----------?---------??----------?-----??----

?????????????????8801????????????????????1


評論

共有 條評論