MSCNN代码解读之mscnn/include/caffe/layers/image_gt_data_layer.hpp

本文介绍MS-CNN中的ImageGtDataLayer,详细解析其类结构和功能,包括数据预处理、批量加载及随机数生成机制,适用于目标检测任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码来源

// ------------------------------------------------------------------
// MS-CNN
// Copyright (c) 2016 The Regents of the University of California
// see mscnn/LICENSE for details
// Written by Zhaowei Cai [zwcai-at-ucsd.edu]
// Please email me if you find bugs, or have suggestions or questions!
// ------------------------------------------------------------------

#ifndef CAFFE_IMAGE_GT_DATA_LAYER_HPP_
#define CAFFE_IMAGE_GT_DATA_LAYER_HPP_

#include <string>
#include <utility>
#include <vector>

#include "caffe/blob.hpp"
#include "caffe/data_transformer.hpp"
#include "caffe/internal_thread.hpp"
#include "caffe/layer.hpp"
#include "caffe/layers/base_data_layer.hpp"
#include "caffe/proto/caffe.pb.h"

namespace caffe {

template <typename Dtype>
class ImageGtDataLayer : public BasePrefetchingDataLayer<Dtype> {
//public继承BasePrefetchingDataLayer类,后者继承自BaseDataLayer和InternalThread,包含能够读取一批数据的能力
 public:
 //与类同名的构造函数,调用父类BasePrefetchingDataLayer的构造函数,使用初始化列表(param)来初始化层参数。explicit的主要用法就是放在单参数的构造函数中,防止隐式转换。
 //调用父类构造函数的语法为,在子类的构造函数后,加一个冒号(:),然后加上父类的带参数的构造函数,后可接派生类的参数初始化表。
  explicit ImageGtDataLayer(const LayerParameter& param)
      : BasePrefetchingDataLayer<Dtype>(param) {}
  //类的析构函数是类的一种特殊的成员函数,它会在每次删除所创建的对象时执行。析构函数的名称与类的名称是完全相同的,只是在前面加了个波浪号(~)作为前缀,它不会返回任何值,也不能带有任何参数。析构函数有助于在跳出程序(比如关闭文件、释放内存等)前释放资源。
  //用来做基类的类的析构函数一般都是虚函数,这样做是为了当用一个基类的指针删除一个派生类的对象时,派生类的析构函数会被调用。
  virtual ~ImageGtDataLayer();
  virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,
      const vector<Blob<Dtype>*>& top);

  virtual inline const char* type() const { return "ImageGtData"; }
  virtual inline int ExactNumBottomBlobs() const { return 0; }
  virtual inline int ExactNumTopBlobs() const { return -1; }
  virtual inline int MinTopBlobs() const { return 2; }

  void BoundingboxAffine(vector<vector<float> >& bbs,
        float w_scale, float h_scale, float w_shift, float h_shift);

 protected:
  virtual unsigned int PrefetchRand();
  virtual void load_batch(Batch<Dtype>* batch);
  virtual void ShuffleList();

  //智能指针shared_ptr
  //RNG类是caffe中对Boost以及STL中随机数函数的封装,以方便使用。
  shared_ptr<Caffe::RNG> prefetch_rng_;
  vector<std::pair<std::string, vector<int> > > image_database_;
  enum ImageGtField { X1, Y1, X2, Y2, LABEL, IGNORE, NUM };
  vector<vector<vector<float> > > windows_;
  vector<vector<vector<float> > > roni_windows_;
  vector<Dtype> mean_values_;
  bool has_mean_values_;
  bool cache_images_;
  vector<std::pair<std::string, Datum > > image_database_cache_;
  vector<int> downsample_rates_;
  vector<int> field_ws_;
  vector<int> field_hs_;
  int label_channel_;
  int label_blob_num_;
  vector<int> image_list_;
  int list_id_;
  bool output_gt_boxes_;
};

}  // namespace caffe

#endif  // CAFFE_IMAGE_GT_DATA_LAYER_HPP_
-- Build files have been written to: /root/Workspace/openpose/build/caffe/src/openpose_lib-build [ 75%] Performing build step for 'openpose_lib' [ 1%] Running C++/Python protocol buffer compiler on /root/Workspace/openpose/3rdparty/caffe/src/caffe/proto/caffe.proto [ 1%] Building CXX object src/caffe/CMakeFiles/caffeproto.dir/__/__/include/caffe/proto/caffe.pb.cc.o [ 1%] Linking CXX static library ../../lib/libcaffeproto.a [ 1%] Built target caffeproto [ 1%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/util/cuda_compile_1_generated_math_functions.cu.o [ 1%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_absval_layer.cu.o [ 2%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_base_data_layer.cu.o [ 2%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_accuracy_layer.cu.o [ 2%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_batch_norm_layer.cu.o [ 2%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_batch_reindex_layer.cu.o [ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_bnll_layer.cu.o [ 4%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_bias_layer.cu.o In file included from /root/Workspace/openpose/3rdparty/caffe/src/caffe/util/math_functions.cu:1: /usr/local/cuda-11.8/include/math_functions.h:54:2: warning: #warning "math_functions.h is an internal header file and must not be used directly. This file will be removed in a future CUDA release. Please use cuda_runtime_api.h or cuda_runtime.h instead." [-Wcpp] 54 | #warning "math_functions.h is an internal header file and must not be used directly. This file will be removed in a future CUDA release.
最新发布
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值