【问题标题】:How to reshape the res5c layer of ResNet (3D to 2D)?如何重塑 ResNet 的 res5c 层(3D 到 2D)?
【发布时间】:2017-06-09 01:52:37
【问题描述】:

我使用 'res5c' 层的 ResNet 提取图像的特征,得到一个形状为 (2048, 14, 14) 的 numpy 数组

我无法处理这些维度。我知道有 14*14 个大小为 2048 的特征。我想迭代以一次访问每个特征。

因此,我如何才能将其重塑为 (14*14, 2048) 的数组而不会出错,然后使用 for 循环轻松地对其进行迭代?

【问题讨论】:

标签: python numpy neural-network caffe resnet


【解决方案1】:

net.forward()后面的功能可以阅读:

feat = net.blobs['res5c'].data.cop() # copy to be on the safe side.

正如您所描述的,featnp.arrayshape = (2048, 14, 14)
你可以reshape它:

feat.reshape((2048,-1)) # fix the first dimension to 2048, -1 set the number of features to match that of `feat`.

现在您可以迭代特征:

for fi in xrange(feat.shape[1]):
    f = feat[:,fi] # get the fi-th feature
    # do somethinf to the feature f

【讨论】:

  • 效果很好。如果我完全理解,这是否可以得到 (14, 14, 2048) : x= x.reshape((2048,-1)) 然后 x = np.swapaxes(x,0,1) x= x.reshape((14,14,2048))
  • @Mickey 看看numpy.transpose。但是你想这样做吗? feat[:,fi] 有什么问题?您是否正在尝试将数据导出到 Matlab?
  • 我正在使用 python 但它很愚蠢,我只想使用一个接受形状输入张量(W、H、Feature)的函数。我对重塑的了解不足给我带来了麻烦 :-) 我会看看用转置来做到这一点
  • @Mickey 你有feat 形状(F,H,W)feat.transpose((2,1,0)) 之后你的形状是(W,H,F)
猜你喜欢
  • 2019-07-10
  • 2021-09-07
  • 1970-01-01
  • 2016-01-17
  • 1970-01-01
  • 1970-01-01
  • 2011-01-16
  • 2019-07-13
  • 1970-01-01
相关资源
最近更新 更多