本文整理汇总了C++中shared_ptr::AddDatumVector方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::AddDatumVector方法的具体用法?C++ shared_ptr::AddDatumVector怎么用?C++ shared_ptr::AddDatumVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shared_ptr
的用法示例。
在下文中一共展示了shared_ptr::AddDatumVector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test
int CaffeMobile::test(string img_path) {
CHECK(caffe_net != NULL);
Datum datum;
CHECK(ReadImageToDatum(img_path, 0, 256, 256, true, &datum));
const shared_ptr<MemoryDataLayer<float>> memory_data_layer =
static_pointer_cast<MemoryDataLayer<float>>(
caffe_net->layer_by_name("data"));
memory_data_layer->AddDatumVector(vector<Datum>({datum}));
vector<Blob<float>* > dummy_bottom_vec;
float loss;
clock_t t_start = clock();
const vector<Blob<float>*>& result = caffe_net->Forward(dummy_bottom_vec, &loss);
clock_t t_end = clock();
LOG(DEBUG) << "Prediction time: " << 1000.0 * (t_end - t_start) / CLOCKS_PER_SEC << " ms.";
const float* argmaxs = result[1]->cpu_data();
for (int i = 0; i < result[1]->num(); i++) {
for (int j = 0; j < result[1]->height(); j++) {
LOG(INFO) << " Image: "<< i << " class:"
<< argmaxs[i*result[1]->height() + j];
}
}
return argmaxs[0];
}
示例2: clock
const vector<Blob<float>*> CaffeMobile::deepDream(string img_path) {
CHECK(caffe_net != NULL);
Datum datum;
CHECK(ReadImageToDatum(img_path, 0, 256, 256, true, &datum));
const shared_ptr<MemoryDataLayer<float>> memory_data_layer =
static_pointer_cast<MemoryDataLayer<float>>(
caffe_net->layer_by_name("data"));
memory_data_layer->AddDatumVector(vector<Datum>({datum}));
float loss;
vector<Blob<float>* > dummy_bottom_vec;
clock_t t_start = clock();
const vector<Blob<float>*>& forwardResult = caffe_net->Forward(dummy_bottom_vec, &loss);
clock_t t_end = clock();
LOG(DEBUG) << "Forward time: " << 1000.0 * (t_end - t_start) / CLOCKS_PER_SEC << " ms.";
t_start = clock();
caffe_net->Backward();
t_end = clock();
LOG(DEBUG) << "Backward time: " << 1000.0 * (t_end - t_start) / CLOCKS_PER_SEC << " ms.";
vector<Blob<float>*> result;
Blob<float>* dataResult = caffe_net->blob_by_name("data").get();
result.push_back(dataResult);
return result;
}
示例3: main
int main(int argc, char** argv)
{
/* initizlie video capture */
VideoCapture cap(0);
if(!cap.isOpened())
{
cout << "Cannot open video" << endl;
return -1;
}
Demoutil util;
util.Init();
/* initialize for pretrained CNN and command line arguements */
::google::InitGoogleLogging(argv[0]);
if (argc < 3 || argc > 5) {
LOG(ERROR) << "test_caffe net_proto pretrained_net_proto iterations "
<< "[CPU/GPU] [Device ID]";
return 1;
}
if (argc >= 4 && strcmp(argv[3], "GPU") == 0) {
Caffe::set_mode(Caffe::GPU);
int device_id = 0;
if (argc == 5) {
device_id = atoi(argv[4]);
}
Caffe::SetDevice(device_id);
LOG(ERROR) << "Using GPU #" << device_id;
} else {
LOG(ERROR) << "Using CPU";
Caffe::set_mode(Caffe::CPU);
}
//get pretrained network
Net<float> caffe_test_net(argv[1], caffe::TEST);
caffe_test_net.CopyTrainedLayersFrom(argv[2]);
Mat frame, showimage, testimage;
Mat croppedImage;
Rect rec(120,100,400,280);
float loss;
clock_t tStart, tEnd;
double execTime, totalTime= 0.0;
struct timeval time;
int counter = 1;
int counterFlag = 0;
/* capture starts here*/
for(;;)
{
tStart = clock();
Mat tag = Mat::zeros(100,640, CV_8UC3);
cap >> frame;
if(frame.empty()) continue;
if(quit_signal) exit(0);
// resize and save image
resize(frame, testimage, Size(227, 227));
//croppedImage = showimage(rec);
//resize(showimage, testimage, Size(227,227));
//cv::rectangle(showimage, rec, CV_RGB(255, 0, 0), 3);
//resize(frame, testimage, Size(256,256));
vector <Datum> datum_vector;
Datum datum;
CVMatToDatum(testimage, &datum);
datum_vector.push_back(datum);
const shared_ptr<MemoryDataLayer<float> > memory_data_layer =
boost::static_pointer_cast<MemoryDataLayer<float> >(
caffe_test_net.layer_by_name("data"));
memory_data_layer->AddDatumVector(datum_vector);
vector<Blob<float>* > dummy_bottom_vec;
const vector<Blob<float>*>& result = caffe_test_net.Forward(dummy_bottom_vec, &loss);
//draw_all_joints(result, testimage);
draw_upper_joints(result, testimage);
tEnd = clock();
execTime = (double)((tEnd-tStart)*1000/CLOCKS_PER_SEC);
totalTime += execTime;
counter ++;
if(counterFlag){
//.........这里部分代码省略.........