ValueError: All bounding boxes should have positive height and width. Found invaid box

问题

运行faster rcnn时出现该错误时,需要的bounding boxes格式为:[xmin, ymin, xmax, ymax],但数据集导入时格式可能为[xmin, ymin, width, height],就会出现这种错误。

解决方法

torchvision.ops.boxes.box_convert提供了一个bounding boxes的转换函数,其用法

 def box_convert(boxes: Tensor, in_fmt: str, out_fmt: str) -> Tensor: 
     """ 
     Converts boxes from given in_fmt to out_fmt. 
     Supported in_fmt and out_fmt are: 
  
     'xyxy': boxes are represented via corners, x1, y1 being top left and x2, y2 being bottom right. 
  
     'xywh' : boxes are represented via corner, width and height, x1, y2 being top left, w, h being width and height. 
  
     'cxcywh' : boxes are represented via centre, width and height, cx, cy being center of box, w, h 
     being width and height. 
  
     Arguments: 
         boxes (Tensor[N, 4]): boxes which will be converted. 
         in_fmt (str): Input format of given boxes. Supported formats are ['xyxy', 'xywh', 'cxcywh']. 
         out_fmt (str): Output format of given boxes. Supported formats are ['xyxy', 'xywh', 'cxcywh'] 
  
     Returns: 
         boxes (Tensor[N, 4]): Boxes into converted format. 
     """ 

案例:

from torchvision.ops.boxes import box_convert

"""
... 数据导入部分省略
"""


boxes = box_convert(boxes=torch.tensor(boxes), in_fmt='xywh', out_fmt='xyxy')

源自:https://github.com/pytorch/vision/issues/2740

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值