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


C++ TrainingSet::getImages方法代码示例

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


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

示例1:

void CLTreeTrainer<ImgType, nChannels, FeatType, FeatDim, nClasses>::train(
  Tree<FeatType, FeatDim, nClasses> &tree,
  const TrainingSet<ImgType, nChannels> &trainingSet,
  const TreeTrainerParameters<FeatType, FeatDim> &params,
  unsigned int startDepth, unsigned int endDepth)
{
  /** \todo support a starting depth different from 1 */
  if (startDepth!=1) throw "Starting depth must be equal to 1";

  _initTrain(tree, trainingSet, params, startDepth, endDepth);
  

  for (unsigned int currDepth=startDepth; currDepth<endDepth; currDepth++)
  {
    boost::chrono::steady_clock::time_point perLevelTrainStart = 
      boost::chrono::steady_clock::now(); 

    unsigned int frontierSize = _initFrontier(tree, params, currDepth);
    unsigned int nSlices = _initHistogram(params);

    
    if (nSlices>1)
    {
      BOOST_LOG_TRIVIAL(info) << "Maximum allowed global histogram size reached: split in "
			      << nSlices << " slices";
    }
    

    // Flag all images as to-be-skipped: the flag will be set to false if at least one
    // image pixel is processed
    std::fill_n(m_toSkipTsImg, trainingSet.getImages().size(), true);

    for (unsigned int i=0; i<nSlices; i++)
    {
      _traverseTrainingSet(trainingSet, params, currDepth, i);
      _learnBestFeatThr(tree, params, currDepth, i);
    }

    // Update skipped images flags
    std::copy(m_toSkipTsImg, m_toSkipTsImg+trainingSet.getImages().size(), m_skippedTsImg);
  

    boost::chrono::duration<double> perLevelTrainTime =
      boost::chrono::duration_cast<boost::chrono::duration<double> >(boost::chrono::steady_clock::now() - 
								   perLevelTrainStart);
    
    BOOST_LOG_TRIVIAL(info) << "Depth " << currDepth << " trained in "
			    << perLevelTrainTime.count() << " seconds";
    
  }

  _cleanTrain();
}
开发者ID:mUogoro,项目名称:padenti,代码行数:53,代码来源:cl_tree_trainer_impl.hpp

示例2:

void CLTreeTrainer<ImgType, nChannels, FeatType, FeatDim, nClasses>::_initTrain(
  Tree<FeatType, FeatDim, nClasses> &tree,
  const TrainingSet<ImgType, nChannels> &trainingSet,
  const TreeTrainerParameters<FeatType, FeatDim> &params,
  unsigned int startDepth, unsigned int endDepth)
{
  unsigned int nNodes = (2<<(endDepth-1))-1;
  cl_int errCode;

  // Init OpenCL tree buffers and load corresponding data
  m_clTreeLeftChildBuff = cl::Buffer(m_clContext,
				     CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,
				     nNodes*sizeof(cl_uint),
				     (void*)tree.getLeftChildren());
  m_clTreeFeaturesBuff = cl::Buffer(m_clContext,
				    CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,
				    nNodes*sizeof(FeatType)*FeatDim,
				    (void*)tree.getFeatures());
  m_clTreeThrsBuff = cl::Buffer(m_clContext,
				CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,
				nNodes*sizeof(FeatType),
				(void*)tree.getThresholds());
  m_clTreePosteriorsBuff = cl::Buffer(m_clContext,
				      CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,
				      nNodes*sizeof(cl_float)*nClasses,
				      (void*)tree.getPosteriors());

  // Init per-node total and per-class number of samples
  m_perNodeTotSamples = new unsigned int[nNodes];
  m_perClassTotSamples = new unsigned int[nNodes*nClasses];
  std::fill_n(m_perNodeTotSamples, nNodes, 0);
  std::fill_n(m_perClassTotSamples, nNodes*nClasses, 0);

  // Init to-skip flags for training set images
  m_toSkipTsImg = new bool[trainingSet.getImages().size()];
  m_skippedTsImg = new bool[trainingSet.getImages().size()];
  std::fill_n(m_skippedTsImg, trainingSet.getImages().size(), false);

  // Init OpenCL training set image buffer:
  // - first of all, iterate through the training set and find the maximum
  //   image width/height
  m_maxTsImgWidth=0;
  m_maxTsImgHeight=0;
  m_maxTsImgSamples=0;
  m_perNodeTotSamples[0] = 0;
  const std::vector<TrainingSetImage<ImgType, nChannels> > &tsImages = trainingSet.getImages();
  for (typename std::vector<TrainingSetImage<ImgType, nChannels> >::const_iterator it=tsImages.begin();
       it!=tsImages.end(); ++it)
  {
    const TrainingSetImage<ImgType, nChannels> &currImage=*it;
    
    if (currImage.getWidth()>m_maxTsImgWidth) m_maxTsImgWidth=currImage.getWidth();
    if (currImage.getHeight()>m_maxTsImgHeight) m_maxTsImgHeight=currImage.getHeight();

    // Get maximum number of sampled pixels as well
    if (currImage.getNSamples()>m_maxTsImgSamples) m_maxTsImgSamples=currImage.getNSamples();

    /** \todo update here total number of pixel per class at root node */
    m_perNodeTotSamples[0]+=currImage.getNSamples();
  }

  // Make the maximum width and height a multiple of the, respectively, work-group x and y
  // dimension
  m_maxTsImgWidth += (m_maxTsImgWidth%WG_WIDTH) ? WG_WIDTH-(m_maxTsImgWidth%WG_WIDTH) : 0;
  m_maxTsImgHeight += (m_maxTsImgHeight%WG_HEIGHT) ? WG_HEIGHT-(m_maxTsImgHeight%WG_HEIGHT) : 0;

  // - initialize OpenCL images
  cl::size_t<3> origin, region;
  size_t rowPitch;
  origin[0]=0; origin[1]=0; origin[2]=0;
  region[0]=m_maxTsImgWidth; region[1]=m_maxTsImgHeight;
  region[2]= (nChannels<=4) ? 1 : nChannels;

  cl::ImageFormat clTsImgFormat;
  ImgTypeTrait<ImgType, nChannels>::toCLImgFmt(clTsImgFormat);
  if (nChannels<=4)
  {
    m_clTsImg1 = new cl::Image2D(m_clContext, CL_MEM_READ_ONLY, clTsImgFormat,
				 m_maxTsImgWidth, m_maxTsImgHeight);
    m_clTsImg2 = new cl::Image2D(m_clContext, CL_MEM_READ_ONLY, clTsImgFormat,
				 m_maxTsImgWidth, m_maxTsImgHeight);
  }
  else
  {
    m_clTsImg1 = new cl::Image3D(m_clContext, CL_MEM_READ_ONLY, clTsImgFormat,
				 m_maxTsImgWidth, m_maxTsImgHeight, nChannels);
    m_clTsImg2 = new cl::Image3D(m_clContext, CL_MEM_READ_ONLY, clTsImgFormat,
				 m_maxTsImgWidth, m_maxTsImgHeight, nChannels);
  }
  m_clTsImgPinn = cl::Buffer(m_clContext,
			     CL_MEM_READ_ONLY|CL_MEM_ALLOC_HOST_PTR,
			     m_maxTsImgWidth*m_maxTsImgHeight*nChannels*sizeof(ImgType)*2);
  m_clTsImgPinnPtr = 
    reinterpret_cast<ImgType*>(m_clQueue1.enqueueMapBuffer(m_clTsImgPinn, CL_TRUE,
							   CL_MAP_WRITE,
							   0, m_maxTsImgWidth*m_maxTsImgHeight*nChannels*sizeof(ImgType)*2));

  clTsImgFormat.image_channel_order = CL_R;
  clTsImgFormat.image_channel_data_type = CL_UNSIGNED_INT8;
  region[2] = 1;
//.........这里部分代码省略.........
开发者ID:Banus,项目名称:padenti,代码行数:101,代码来源:cl_tree_trainer_impl_init.hpp


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