py-rfcn中遇到的错误

半世苍凉 提交于 2020-08-17 15:22:23

eltwise_layer.cpp:34 check failed: bottom[i]->shape() == bottom[0]->shape(). error)

训练py-R-FCN或faster rcnn过程中报错

这个错误是在执行element-wise(concat或sum)时产生的,此使只需要根据日志,查找到相加的两个元素,对其维度调整,基本就可以解决问题。

训练py-R-FCNwithFPN过程中报错

在py-rfcn中加入FPN网络结构,产生如下错误:(错误链接: link.)
在这里插入图片描述
错误原因:FPN网络模型中的下采样操作使得特征图分辨减少为原来的1/2,向下取整,而反卷积操作使得特征图分辨率成为原来的两倍,如果图片或特征图的分辨率不是2的整数倍,在FPN网络特征融合的过程中就会产生问题。比如:特征图大小1111,下采样后为55,再将其上采样后为10*10,此时做element-wise(sum)会产生如上错误。
解决办法
FPN 在congfig.py 中设置了下采样倍数参数:__C.TRAIN.IMAGE_STRIDE=64。同样在congfig.py中添加自己网络中下采样倍数。



// config.py
# Max pixel size of the longest side of a scaled input image
__C.TRAIN.MAX_SIZE = 1280
__C.TRAIN.IMAGE_STRIDE = 32# 添加下采样倍数参数
__C.TRAIN.IMS_PER_BATCH = 2# Images to use per minibatch

修改 blob.pydef prep_im_for_blob()函数:

def prep_im_for_blob(im, pixel_means, target_size, max_size):    """Mean subtract and scale an image for use in a blob."""   
   im = im.astype(np.float32, copy=False)   
   im -= pixel_means   
   im_shape = im.shape  
   im_size_min = np.min(im_shape[0:2])   
   im_size_max = np.max(im_shape[0:2])  
   im_scale = float(target_size) / float(im_size_min)   
  # Prevent the biggest axis from being more than MAX_SIZE    
   if np.round(im_scale * im_size_max) > max_size:       
      im_scale = float(max_size) / float(im_size_max)    
   im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale,
                   interpolation=cv2.INTER_LINEAR)
    return im, im_scale

minibatch.pydef _get_image_blob()函数中调用prep_im_for_blob()

// minibatch.py

def _get_image_blob(roidb, scale_inds):  
  """Builds an input blob from the images in the roidb at the specified    scales. """   
   num_images = len(roidb)    
   processed_ims = []    
   im_scales = []   
   for i in xrange(num_images):     
       im = cv2.imread(roidb[i]['image'])    
       if roidb[i]['flipped']:         
          im = im[:, ::-1, :]       
       target_size = cfg.TRAIN.SCALES[scale_inds[i]]
       #修改此处,传入      
       im,im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS,target_size,
                                     cfg.TRAIN.MAX_SIZE,cfg.TRAIN.IMAGE_STRIDE)
       im_scales.append(im_scale)        
       processed_ims.append(im)    
                 # Create a blob to hold the input images  
  blob = im_list_to_blob(processed_ims)   
  return blob, im_scales

py-R-FCN with FPN 完整版: py-R-FCN with FPN.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!