赞
踩
cannot import name ‘nms_rotated_ext‘ from partially initialized module ‘utils.nms_rotated‘
在kaggle上再重新进行一次编译即可
- cd /kaggle/working/yolov7-obb/utils/nms_rotated
-
- !python setup.py build_ext --inplace
fatal error: THC/THC.h: No such file or directory
运行问题一中的代码后随即出现该问题,因为pytorch1.10以后无THC.h头文件
将poly_nms_cuda.cu替换为了链接中的代码,即可正常运行,如果pytorch版本在1.10以内则无需替换,但是显卡对pytorch版本有要求,需注意~
原始数据集为.png格式,忘记进行转换了
亲测好用~
indices should be either on cpu or on the same device as the indexed tensor (cpu)
NameError: name 'COCO' is not defined
ValueError: could not convert string to float: 'P-3C'
前者是未下载pycocotools,后者是utils_map.py中的obb的形式问题
obb有两种形式:① (x,y,w,h,θ) ②(x1,y1,x2,y2,x3,y3,x4,y4)
utils_map.py和数据集的形式要对应,在utils_map.py中修改三个地方即可
- #-------------- (x,y,w,h,θ) ----------------#
- # try:
- # if "difficult" in line:
- # class_name, x, y, w, h,angle, _difficult = line.split()
- # is_difficult = True
- # else:
- # class_name, x, y, w, h,angle = line.split()
- # except:
- # if "difficult" in line:
- # line_split = line.split()
- # _difficult = line_split[-1]
- # angle = line_split[-2]
- # h = line_split[-3]
- # w = line_split[-4]
- # y = line_split[-5]
- # x = line_split[-6]
- # class_name = ""
- # for name in line_split[:-6]:
- # class_name += name + " "
- # class_name = class_name[:-1]
- # is_difficult = True
- # else:
- # line_split = line.split()
- # angle = line_split[-1]
- # h = line_split[-2]
- # w = line_split[-3]
- # y = line_split[-4]
- # x = line_split[-5]
- # class_name = ""
- # for name in line_split[:-5]:
- # class_name += name + " "
- # class_name = class_name[:-1]
- #
- # bbox = x + " " + y + " " + w + " " + h + " " + angle
-
-
- #------------- (x1,y1,x2,y2,x3,y3,x4,y4) -----------------#
- try:
- if "difficult" in line:
- class_name, left, top, right, bottom, _difficult = line.split()
- is_difficult = True
- else:
- class_name, left, top, right, bottom = line.split()
- except:
- if "difficult" in line:
- line_split = line.split()
- _difficult = line_split[-1]
- bottom = line_split[-2]
- right = line_split[-3]
- top = line_split[-4]
- left = line_split[-5]
- class_name = ""
- for name in line_split[:-5]:
- class_name += name + " "
- class_name = class_name[:-1]
- is_difficult = True
- else:
- line_split = line.split()
- bottom = line_split[-1]
- right = line_split[-2]
- top = line_split[-3]
- left = line_split[-4]
- class_name = ""
- for name in line_split[:-4]:
- class_name += name + " "
- class_name = class_name[:-1]
- bbox = left + " " + top + " " + right + " " + bottom

- #--------------- (x,y,w,h,θ) ------------------#
- # try:
- # tmp_class_name, confidence, x, y, w, h,angle = line.split()
- # except:
- # line_split = line.split()
- # angle = line_split[-1]
- # h = line_split[-2]
- # w = line_split[-3]
- # y = line_split[-4]
- # x = line_split[-5]
- # confidence = line_split[-6]
- # tmp_class_name = ""
- # for name in line_split[:-6]:
- # tmp_class_name += name + " "
- # tmp_class_name = tmp_class_name[:-1]
- #
- # if tmp_class_name == class_name:
- # bbox = x + " " + y + " " + w + " " + h + " " + angle
- # bounding_boxes.append({"confidence":confidence, "file_id":file_id, "bbox":bbox})
-
-
-
- #--------------- (x1,y1,x2,y2,x3,y3,x4,y4) ------------------#
- try:
- tmp_class_name, confidence, left, top, right, bottom = line.split()
- except:
- line_split = line.split()
- bottom = line_split[-1]
- right = line_split[-2]
- top = line_split[-3]
- left = line_split[-4]
- confidence = line_split[-5]
- tmp_class_name = ""
- for name in line_split[:-5]:
- tmp_class_name += name + " "
- tmp_class_name = tmp_class_name[:-1]
-
- if tmp_class_name == class_name:
- bbox = left + " " + top + " " + right + " " +bottom
- bounding_boxes.append({"confidence":confidence, "file_id":file_id, "bbox":bbox})

- for obj in ground_truth_data:
-
- #--------------- (x,y,w,h,θ) ------------------#
- # if obj["class_name"] == class_name:
- # bbgt = [float(x) for x in obj["bbox"].split() ]
- # box1 = np.array([bb[0], bb[1], bb[2], bb[3], bb[4]], np.float32)
- # box2 = np.array([bbgt[0], bbgt[1], bbgt[2], bbgt[3], bbgt[4]], np.float32)
- # ov = iou_rotate_calculate(box1, box2)
- # if ov > ovmax:
- # ovmax = ov
- # gt_match = obj
-
-
- #--------------- (x1,y1,x2,y2,x3,y3,x4,y4) ------------------#
- if obj["class_name"] == class_name:
- bbgt = [ float(x) for x in obj["bbox"].split() ]
- bi = [max(bb[0],bbgt[0]), max(bb[1],bbgt[1]), min(bb[2],bbgt[2]), min(bb[3],bbgt[3])]
- iw = bi[2] - bi[0] + 1
- ih = bi[3] - bi[1] + 1
- if iw > 0 and ih > 0:
- ua = (bb[2] - bb[0] + 1) * (bb[3] - bb[1] + 1) + (bbgt[2] - bbgt[0]
- + 1) * (bbgt[3] - bbgt[1] + 1) - iw * ih
- ov = iw * ih / ua
- if ov > ovmax:
- ovmax = ov
- gt_match = obj

其中,iou_rotate_calculate对①是必需的,代码如下:
- # def iou_rotate_calculate(boxes1, boxes2):
- # """
- # 计算旋转面积
- # boxes1,boxes2格式为x,y,w,h,theta
- # """
- # area1 = boxes1[2] * boxes1[3]
- # area2 = boxes2[2] * boxes2[3]
- # r1 = ((boxes1[0], boxes1[1]), (boxes1[2], boxes1[3]), boxes1[4])
- # r2 = ((boxes2[0], boxes2[1]), (boxes2[2], boxes2[3]), boxes2[4])
- # int_pts = cv2.rotatedRectangleIntersection(r1, r2)[1]
- # if int_pts is not None:
- # order_pts = cv2.convexHull(int_pts, returnPoints=True)
- # int_area = cv2.contourArea(order_pts)
- # ious = int_area * 1.0 / (area1 + area2 - int_area)
- # else:
- # ious = 0
- # return ious

--------------------------------------------
正常运行啦~撒花
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。