当前位置: 首页>>代码示例>>C++>>正文


C++ shared_ptr::AddImagesAndLabels方法代码示例

本文整理汇总了C++中shared_ptr::AddImagesAndLabels方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::AddImagesAndLabels方法的具体用法?C++ shared_ptr::AddImagesAndLabels怎么用?C++ shared_ptr::AddImagesAndLabels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shared_ptr的用法示例。


在下文中一共展示了shared_ptr::AddImagesAndLabels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _getProbability

    	/**
    	 * Evaluate the given image to see its probability in the given category.
    	 */
    	float _getProbability(const cv::Mat& image, const int category)
    	{
    		this->initCaffeNet();	//Initialize caffe

				// Initialize test network
				shared_ptr<Net<float> > caffe_test_net = shared_ptr<Net<float> >( new Net<float>(Params::image::model_definition));

				// Get the trained model
				caffe_test_net->CopyTrainedLayersFrom(Params::image::pretrained_model);

				// Run ForwardPrefilled
				float loss;

				// Add images and labels manually to the ImageDataLayer
				vector<int> labels(10, 0);
				vector<cv::Mat> images;

				// Add images to the list
				if (Params::image::use_crops)
				{
					// Ten crops have been stored in the vector
					_createTenCrops(image, images);
				}
				else
				{
					images.push_back(image);
				}

				// Classify images
				const shared_ptr<ImageDataLayer<float> > image_data_layer =
						boost::static_pointer_cast<ImageDataLayer<float> >(
								caffe_test_net->layer_by_name("data"));

				image_data_layer->AddImagesAndLabels(images, labels);

				const vector<Blob<float>*>& result = caffe_test_net->ForwardPrefilled(&loss);

				// Get the highest layer of Softmax
				const float* softmax = result[1]->cpu_data();

				// If use 10 crops, we have to average the predictions of 10 crops
				if (Params::image::use_crops)
				{
					vector<double> values;

					// Average the predictions of evaluating 10 crops
					for(int i = 0; i < Params::image::num_categories; ++i)
					{
						boost::accumulators::accumulator_set<double, boost::accumulators::stats<boost::accumulators::tag::mean> > avg;

						for(int j = 0; j < 10 * Params::image::num_categories; j += Params::image::num_categories)
						{
							avg(softmax[i + j]);
						}

						double mean = boost::accumulators::mean(avg);

						values.push_back(mean);
					}

	    		return values[category];
				}
				// If use only 1 crop
				else
				{
					return softmax[category];
				}

    	}
开发者ID:Beerkay,项目名称:fooling,代码行数:72,代码来源:fit_deep_learning.hpp


注:本文中的shared_ptr::AddImagesAndLabels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。