Caffe2填坑系列(2)----获取数据或参数的方法

  • pad_end_(OperatorBase::template GetSingleArgument(“pad_end”,0))
    如果参数“pad_end”没有提供,则采用0为默认值
  • 获取Op的输入和输出
    const auto& X = Input(0):获取第一个输入,注意输入一般为常量类型,因为我们一般只读不更改数据。
    auto* Y = Output(0): 指向第一个输出,不能为常量类型。
    X是一个Tensor对象,可以按照操作一个Tensor的方式去操作X,在tensor.h中可以找到具体的方法。
  • 获得输入的维度信息
    vector dims_
/**
   * Returns the i-th dimension of the tensor in int.
   * 返回第i维的值,是一个int型
   * This function returns an int value instead of TIndex, which depending on
   * the typedef could be int64. If you want int64 dim values, make sure you
   * call dim() instead.
   */
  inline int dim32(const int i) const {
    #ifndef NDEBUG
    CAFFE_ENFORCE_LT_WITH_CALLER(i, dims_.size(), "Exceeding ndim limit");
    CAFFE_ENFORCE_GE_WITH_CALLER(i, 0, "Cannot have negative dimension index");
    #endif
    CAFFE_ENFORCE_LT_WITH_CALLER(dims_[i], std::numeric_limits<int>::max());
    return static_cast<int>(dims_[i]);
  }
/**
 * Returns the i-th dimension of the tensor. Note that the passed in index
 * must be between 0 (inclusive) and the number of dimensions, otherwise
 * this function will produce a fatal message.
 */
inline TIndex dim(const int i) const {
  #ifndef NDEBUG
  CAFFE_ENFORCE_LT_WITH_CALLER(i, dims_.size(), "Exceeding ndim limit");
  CAFFE_ENFORCE_GE_WITH_CALLER(i, 0, "Cannot have negative dimension index");
  #endif
  return dims_[i];
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值