当前位置:   article > 正文

YOLOv7-obb上传kaggle遇到的问题合集_yolov7 读取kaggle数据集

yolov7 读取kaggle数据集

一、utils.nms_rotated问题

cannot import name ‘nms_rotated_ext‘ from partially initialized module ‘utils.nms_rotated‘ 

 在kaggle上再重新进行一次编译即可

  1. cd /kaggle/working/yolov7-obb/utils/nms_rotated
  2. !python setup.py build_ext --inplace

二、THC/THC.h问题

fatal error: THC/THC.h: No such file or directory

 运行问题一中的代码后随即出现该问题,因为pytorch1.10以后无THC.h头文件

参考代码

将poly_nms_cuda.cu替换为了链接中的代码,即可正常运行,如果pytorch版本在1.10以内则无需替换,但是显卡对pytorch版本有要求,需注意~

三、图片格式问题

原始数据集为.png格式,忘记进行转换了

参考代码

亲测好用~

四、训练中get_map问题

indices should be either on cpu or on the same device as the indexed tensor (cpu)

五、utils_map.py问题

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中修改三个地方即可

  1. #-------------- (x,y,w,h,θ) ----------------#
  2. # try:
  3. # if "difficult" in line:
  4. # class_name, x, y, w, h,angle, _difficult = line.split()
  5. # is_difficult = True
  6. # else:
  7. # class_name, x, y, w, h,angle = line.split()
  8. # except:
  9. # if "difficult" in line:
  10. # line_split = line.split()
  11. # _difficult = line_split[-1]
  12. # angle = line_split[-2]
  13. # h = line_split[-3]
  14. # w = line_split[-4]
  15. # y = line_split[-5]
  16. # x = line_split[-6]
  17. # class_name = ""
  18. # for name in line_split[:-6]:
  19. # class_name += name + " "
  20. # class_name = class_name[:-1]
  21. # is_difficult = True
  22. # else:
  23. # line_split = line.split()
  24. # angle = line_split[-1]
  25. # h = line_split[-2]
  26. # w = line_split[-3]
  27. # y = line_split[-4]
  28. # x = line_split[-5]
  29. # class_name = ""
  30. # for name in line_split[:-5]:
  31. # class_name += name + " "
  32. # class_name = class_name[:-1]
  33. #
  34. # bbox = x + " " + y + " " + w + " " + h + " " + angle
  35. #------------- (x1,y1,x2,y2,x3,y3,x4,y4) -----------------#
  36. try:
  37. if "difficult" in line:
  38. class_name, left, top, right, bottom, _difficult = line.split()
  39. is_difficult = True
  40. else:
  41. class_name, left, top, right, bottom = line.split()
  42. except:
  43. if "difficult" in line:
  44. line_split = line.split()
  45. _difficult = line_split[-1]
  46. bottom = line_split[-2]
  47. right = line_split[-3]
  48. top = line_split[-4]
  49. left = line_split[-5]
  50. class_name = ""
  51. for name in line_split[:-5]:
  52. class_name += name + " "
  53. class_name = class_name[:-1]
  54. is_difficult = True
  55. else:
  56. line_split = line.split()
  57. bottom = line_split[-1]
  58. right = line_split[-2]
  59. top = line_split[-3]
  60. left = line_split[-4]
  61. class_name = ""
  62. for name in line_split[:-4]:
  63. class_name += name + " "
  64. class_name = class_name[:-1]
  65. bbox = left + " " + top + " " + right + " " + bottom
  1. #--------------- (x,y,w,h,θ) ------------------#
  2. # try:
  3. # tmp_class_name, confidence, x, y, w, h,angle = line.split()
  4. # except:
  5. # line_split = line.split()
  6. # angle = line_split[-1]
  7. # h = line_split[-2]
  8. # w = line_split[-3]
  9. # y = line_split[-4]
  10. # x = line_split[-5]
  11. # confidence = line_split[-6]
  12. # tmp_class_name = ""
  13. # for name in line_split[:-6]:
  14. # tmp_class_name += name + " "
  15. # tmp_class_name = tmp_class_name[:-1]
  16. #
  17. # if tmp_class_name == class_name:
  18. # bbox = x + " " + y + " " + w + " " + h + " " + angle
  19. # bounding_boxes.append({"confidence":confidence, "file_id":file_id, "bbox":bbox})
  20. #--------------- (x1,y1,x2,y2,x3,y3,x4,y4) ------------------#
  21. try:
  22. tmp_class_name, confidence, left, top, right, bottom = line.split()
  23. except:
  24. line_split = line.split()
  25. bottom = line_split[-1]
  26. right = line_split[-2]
  27. top = line_split[-3]
  28. left = line_split[-4]
  29. confidence = line_split[-5]
  30. tmp_class_name = ""
  31. for name in line_split[:-5]:
  32. tmp_class_name += name + " "
  33. tmp_class_name = tmp_class_name[:-1]
  34. if tmp_class_name == class_name:
  35. bbox = left + " " + top + " " + right + " " +bottom
  36. bounding_boxes.append({"confidence":confidence, "file_id":file_id, "bbox":bbox})
  1. for obj in ground_truth_data:
  2. #--------------- (x,y,w,h,θ) ------------------#
  3. # if obj["class_name"] == class_name:
  4. # bbgt = [float(x) for x in obj["bbox"].split() ]
  5. # box1 = np.array([bb[0], bb[1], bb[2], bb[3], bb[4]], np.float32)
  6. # box2 = np.array([bbgt[0], bbgt[1], bbgt[2], bbgt[3], bbgt[4]], np.float32)
  7. # ov = iou_rotate_calculate(box1, box2)
  8. # if ov > ovmax:
  9. # ovmax = ov
  10. # gt_match = obj
  11. #--------------- (x1,y1,x2,y2,x3,y3,x4,y4) ------------------#
  12. if obj["class_name"] == class_name:
  13. bbgt = [ float(x) for x in obj["bbox"].split() ]
  14. bi = [max(bb[0],bbgt[0]), max(bb[1],bbgt[1]), min(bb[2],bbgt[2]), min(bb[3],bbgt[3])]
  15. iw = bi[2] - bi[0] + 1
  16. ih = bi[3] - bi[1] + 1
  17. if iw > 0 and ih > 0:
  18. ua = (bb[2] - bb[0] + 1) * (bb[3] - bb[1] + 1) + (bbgt[2] - bbgt[0]
  19. + 1) * (bbgt[3] - bbgt[1] + 1) - iw * ih
  20. ov = iw * ih / ua
  21. if ov > ovmax:
  22. ovmax = ov
  23. gt_match = obj

其中,iou_rotate_calculate对①是必需的,代码如下:

  1. # def iou_rotate_calculate(boxes1, boxes2):
  2. # """
  3. # 计算旋转面积
  4. # boxes1,boxes2格式为x,y,w,h,theta
  5. # """
  6. # area1 = boxes1[2] * boxes1[3]
  7. # area2 = boxes2[2] * boxes2[3]
  8. # r1 = ((boxes1[0], boxes1[1]), (boxes1[2], boxes1[3]), boxes1[4])
  9. # r2 = ((boxes2[0], boxes2[1]), (boxes2[2], boxes2[3]), boxes2[4])
  10. # int_pts = cv2.rotatedRectangleIntersection(r1, r2)[1]
  11. # if int_pts is not None:
  12. # order_pts = cv2.convexHull(int_pts, returnPoints=True)
  13. # int_area = cv2.contourArea(order_pts)
  14. # ious = int_area * 1.0 / (area1 + area2 - int_area)
  15. # else:
  16. # ious = 0
  17. # return ious

--------------------------------------------

正常运行啦~撒花

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/850389
推荐阅读
相关标签