在 Pyfaster RCNN CAFFE 模型中重塑图像
Reshaping image in Pyfaster RCNN CAFFE model
我正在进行一个使用 CAFFE 训练 Pyfaster RCNN 模型的项目。 test.prototxt 使用以下输入参数:
name: "ZF"
input: "data"
input_shape {
dim: 1
dim: 3
dim: 224
dim: 224
}
当调用 demo.py 时,将使用此 prototxt 文件。有人可以告诉我演示图像在何处被重塑为上述尺寸。我一直追溯到 fast_rcnn.test.py 文件,该文件有一个名为 im_detect 的函数。有一条线,我相信它会重塑:
def im_detect(net, im, boxes=None):
"""Detect object classes in an image given object proposals.
Arguments:
net (caffe.Net): Fast R-CNN network to use
im (ndarray): color image to test (in BGR order)
boxes (ndarray): R x 4 array of object proposals or None (for RPN)
Returns:
scores (ndarray): R x K array of object class scores (K includes
background as object category 0)
boxes (ndarray): R x (4*K) array of predicted bounding boxes
"""
blobs, im_scales = _get_blobs(im, boxes)
# When mapping from image ROIs to feature map ROIs, there's some aliasing
# (some distinct image ROIs get mapped to the same feature ROI).
# Here, we identify duplicate feature ROIs, so we only compute features
# on the unique subset.
if cfg.DEDUP_BOXES > 0 and not cfg.TEST.HAS_RPN:
v = np.array([1, 1e3, 1e6, 1e9, 1e12])
hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v)
_, index, inv_index = np.unique(hashes, return_index=True,
return_inverse=True)
blobs['rois'] = blobs['rois'][index, :]
boxes = boxes[index, :]
if cfg.TEST.HAS_RPN:
im_blob = blobs['data']
blobs['im_info'] = np.array(
[[im_blob.shape[2], im_blob.shape[3], im_scales[0]]],
dtype=np.float32)
# reshape network inputs
net.blobs['data'].reshape(*(blobs['data'].shape))
if cfg.TEST.HAS_RPN:
net.blobs['im_info'].reshape(*(blobs['im_info'].shape))
else:
net.blobs['rois'].reshape(*(blobs['rois'].shape))
但我仍然无法弄清楚如何到达定义这些维度的 file/code。
如有任何帮助,我们将不胜感激。
看行
# reshape network inputs
net.blobs['data'].reshape(*(blobs['data'].shape))
如您所见,输入的 blob 'data'
根据输入图像的大小进行了重塑。一旦你 forward
caffe 将根据输入形状
重塑所有后续的斑点
我正在进行一个使用 CAFFE 训练 Pyfaster RCNN 模型的项目。 test.prototxt 使用以下输入参数:
name: "ZF"
input: "data"
input_shape {
dim: 1
dim: 3
dim: 224
dim: 224
}
当调用 demo.py 时,将使用此 prototxt 文件。有人可以告诉我演示图像在何处被重塑为上述尺寸。我一直追溯到 fast_rcnn.test.py 文件,该文件有一个名为 im_detect 的函数。有一条线,我相信它会重塑:
def im_detect(net, im, boxes=None):
"""Detect object classes in an image given object proposals.
Arguments:
net (caffe.Net): Fast R-CNN network to use
im (ndarray): color image to test (in BGR order)
boxes (ndarray): R x 4 array of object proposals or None (for RPN)
Returns:
scores (ndarray): R x K array of object class scores (K includes
background as object category 0)
boxes (ndarray): R x (4*K) array of predicted bounding boxes
"""
blobs, im_scales = _get_blobs(im, boxes)
# When mapping from image ROIs to feature map ROIs, there's some aliasing
# (some distinct image ROIs get mapped to the same feature ROI).
# Here, we identify duplicate feature ROIs, so we only compute features
# on the unique subset.
if cfg.DEDUP_BOXES > 0 and not cfg.TEST.HAS_RPN:
v = np.array([1, 1e3, 1e6, 1e9, 1e12])
hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v)
_, index, inv_index = np.unique(hashes, return_index=True,
return_inverse=True)
blobs['rois'] = blobs['rois'][index, :]
boxes = boxes[index, :]
if cfg.TEST.HAS_RPN:
im_blob = blobs['data']
blobs['im_info'] = np.array(
[[im_blob.shape[2], im_blob.shape[3], im_scales[0]]],
dtype=np.float32)
# reshape network inputs
net.blobs['data'].reshape(*(blobs['data'].shape))
if cfg.TEST.HAS_RPN:
net.blobs['im_info'].reshape(*(blobs['im_info'].shape))
else:
net.blobs['rois'].reshape(*(blobs['rois'].shape))
但我仍然无法弄清楚如何到达定义这些维度的 file/code。
如有任何帮助,我们将不胜感激。
看行
# reshape network inputs
net.blobs['data'].reshape(*(blobs['data'].shape))
如您所见,输入的 blob 'data'
根据输入图像的大小进行了重塑。一旦你 forward
caffe 将根据输入形状