当前位置:   article > 正文

YOLOv8训练自己的OBB数据集_obb dataset incorrectly formatted or not a obb dat

obb dataset incorrectly formatted or not a obb dataset

 1.采用rolabelImg标注产生相应的XML标签文件

2.下载代码及安装相应的依赖环境

git clone https://github.com/ultralytics/ultralytics.git

下面是我安装的相应依赖,torch可在官网命令安装

  1. absl-py==2.1.0
  2. actionlib==1.12.1
  3. angles==1.9.12
  4. bondpy==1.8.5
  5. cachetools==5.3.3
  6. camera_calibration_parsers==1.11.13
  7. catkin==0.7.29
  8. certifi==2024.2.2
  9. charset-normalizer==3.3.2
  10. coloredlogs==15.0.1
  11. contourpy==1.1.1
  12. controller_manager==0.18.4
  13. controller_manager_msgs==0.18.4
  14. cycler==0.12.1
  15. diagnostic_analysis==1.9.7
  16. diagnostic_common_diagnostics==1.9.7
  17. diagnostic_updater==1.9.7
  18. dynamic_reconfigure==1.6.5
  19. filelock==3.13.1
  20. flatbuffers==23.5.26
  21. fonttools==4.50.0
  22. fsspec==2024.3.1
  23. gazebo_ros==2.8.7
  24. gencpp==0.6.6
  25. geneus==2.2.6
  26. genlisp==0.4.16
  27. genmsg==0.5.17
  28. gennodejs==2.0.1
  29. genpy==0.6.16
  30. google-auth==2.28.2
  31. google-auth-oauthlib==0.4.6
  32. grpcio==1.62.1
  33. humanfriendly==10.0
  34. idna==3.6
  35. importlib_metadata==7.0.2
  36. importlib_resources==6.3.1
  37. interactive-markers==1.11.5
  38. Jinja2==3.1.3
  39. joint_state_publisher==1.12.15
  40. kdl-parser-py==1.13.3
  41. kiwisolver==1.4.5
  42. lanelet2-python==1.0.1
  43. laser_geometry==1.6.7
  44. Markdown==3.6
  45. markdown-it-py==3.0.0
  46. MarkupSafe==2.1.5
  47. matplotlib==3.7.5
  48. mdurl==0.1.2
  49. message_filters==1.14.13
  50. #mmsegmentation== 0.11.0 /data/SegFormer
  51. mpmath==1.3.0
  52. networkx==3.1
  53. nmea_navsat_driver==0.5.2
  54. numpy==1.24.4
  55. nvidia-cublas-cu12==12.1.3.1
  56. nvidia-cuda-cupti-cu12==12.1.105
  57. nvidia-cuda-nvrtc-cu12==12.1.105
  58. nvidia-cuda-runtime-cu12==12.1.105
  59. nvidia-cudnn-cu12==8.9.2.26
  60. nvidia-cufft-cu12==11.0.2.54
  61. nvidia-curand-cu12==10.3.2.106
  62. nvidia-cusolver-cu12==11.4.5.107
  63. nvidia-cusparse-cu12==12.1.0.106
  64. nvidia-nccl-cu12==2.19.3
  65. nvidia-nvjitlink-cu12==12.4.99
  66. nvidia-nvtx-cu12==12.1.105
  67. oauthlib==3.2.2
  68. onnx==1.15.0
  69. onnxruntime==1.15.1
  70. onnxsim==0.4.36
  71. opencv-python==4.9.0.80
  72. packaging==24.0
  73. pandas==2.0.3
  74. pillow==10.2.0
  75. pip==23.3.1
  76. protobuf==5.26.0
  77. psutil==5.9.8
  78. py-cpuinfo==9.0.0
  79. pyasn1==0.5.1
  80. pyasn1-modules==0.3.0
  81. Pygments==2.17.2
  82. pyparsing==3.1.2
  83. python-dateutil==2.9.0.post0
  84. python_qt_binding==0.4.4
  85. pytz==2024.1
  86. PyYAML==6.0.1
  87. qt-dotgraph==0.4.2
  88. qt-gui==0.4.2
  89. qt-gui-cpp==0.4.2
  90. qt-gui-py-common==0.4.2
  91. requests==2.31.0
  92. requests-oauthlib==1.4.0
  93. resource_retriever==1.12.7
  94. rich==13.7.1
  95. rosapi==0.11.16
  96. rosbag==1.14.13
  97. rosboost-cfg==1.14.9
  98. rosbridge-library==0.11.16
  99. rosbridge-server==0.11.16
  100. rosclean==1.14.9
  101. roscreate==1.14.9
  102. rosgraph==1.14.13
  103. roslaunch==1.14.13
  104. roslib==1.14.9
  105. roslint==0.11.2
  106. roslz4==1.14.13
  107. rosmake==1.14.9
  108. rosmaster==1.14.13
  109. rosmsg==1.14.13
  110. rosnode==1.14.13
  111. rosparam==1.14.13
  112. rospy==1.14.13
  113. rosservice==1.14.13
  114. rostest==1.14.13
  115. rostopic==1.14.13
  116. rosunit==1.14.9
  117. roswtf==1.14.13
  118. rqt_action==0.4.9
  119. rqt_bag==0.5.1
  120. rqt_bag_plugins==0.5.1
  121. rqt_console==0.4.9
  122. rqt_dep==0.4.9
  123. rqt_graph==0.4.11
  124. rqt_gui==0.5.3
  125. rqt_gui_py==0.5.3
  126. rqt_launch==0.4.8
  127. rqt_logger_level==0.4.8
  128. rqt-moveit==0.5.10
  129. rqt_msg==0.4.8
  130. rqt_nav_view==0.5.7
  131. rqt_plot==0.4.13
  132. rqt_pose_view==0.5.8
  133. rqt_publisher==0.4.8
  134. rqt_py_common==0.5.3
  135. rqt_py_console==0.4.8
  136. rqt-reconfigure==0.5.4
  137. rqt_robot_dashboard==0.5.7
  138. rqt-robot-monitor==0.5.14
  139. rqt_robot_steering==0.5.10
  140. rqt_runtime_monitor==0.5.7
  141. rqt-rviz==0.7.0
  142. rqt_service_caller==0.4.8
  143. rqt_shell==0.4.9
  144. rqt_srv==0.4.8
  145. rqt_tf_tree==0.6.0
  146. rqt_top==0.4.8
  147. rqt_topic==0.4.11
  148. rqt_web==0.4.8
  149. rsa==4.9
  150. rviz==1.13.29
  151. scipy==1.10.1
  152. seaborn==0.13.2
  153. sensor-msgs==1.12.8
  154. setuptools==68.2.2
  155. six==1.16.0
  156. smach==2.0.1
  157. smach_ros==2.0.1
  158. smclib==1.8.5
  159. sound-play==0.3.15
  160. sympy==1.12
  161. tensorboard==2.12.0
  162. tensorboard-data-server==0.7.2
  163. tensorboard-plugin-wit==1.8.1
  164. tensorboardX==2.6.2.2
  165. terminaltables==3.1.10
  166. tf==1.12.1
  167. tf_conversions==1.12.1
  168. tf2_geometry_msgs==0.6.5
  169. tf2_kdl==0.6.5
  170. tf2_py==0.6.5
  171. tf2_ros==0.6.5
  172. thop==0.1.1.post2209072238
  173. topic_tools==1.14.13
  174. #torch==1.10.1+cu111
  175. #torchaudio==0.10.1+cu111
  176. #torchvision==0.11.2+cu111
  177. tqdm==4.66.2
  178. triton==2.2.0
  179. typing_extensions==4.10.0
  180. tzdata==2024.1
  181. urdfdom-py==0.4.6
  182. urllib3==2.2.1
  183. Werkzeug==3.0.1
  184. wheel==0.41.2
  185. xacro==1.13.18
  186. zipp==3.18.1

3.将相应的XML文件转化为dota格式的标签文件,转换代码可参考我的上一篇博客

4.将dota格式的标签文件转化为YOLOv8训练所需的YOLO格式

  1. def convert_dota_to_yolo_obb(dota_root_path: str):
  2. """
  3. Converts DOTA dataset annotations to YOLO OBB (Oriented Bounding Box) format.
  4. The function processes images in the 'train' and 'val' folders of the DOTA dataset. For each image, it reads the
  5. associated label from the original labels directory and writes new labels in YOLO OBB format to a new directory.
  6. Args:
  7. dota_root_path (str): The root directory path of the DOTA dataset.
  8. Example:
  9. ```python
  10. from ultralytics.data.converter import convert_dota_to_yolo_obb
  11. convert_dota_to_yolo_obb('path/to/DOTA')
  12. ```
  13. Notes:
  14. The directory structure assumed for the DOTA dataset:
  15. - DOTA
  16. ├─ images
  17. │ ├─ train
  18. │ └─ val
  19. └─ labels
  20. ├─ train_original
  21. └─ val_original
  22. After execution, the function will organize the labels into:
  23. - DOTA
  24. └─ labels
  25. ├─ train
  26. └─ val
  27. """
  28. dota_root_path = Path(dota_root_path)
  29. # Class names to indices mapping
  30. class_mapping = {
  31. "gfb": 0,
  32. }
  33. def convert_label(image_name, image_width, image_height, orig_label_dir, save_dir):
  34. """Converts a single image's DOTA annotation to YOLO OBB format and saves it to a specified directory."""
  35. orig_label_path = orig_label_dir / f"{image_name}.txt"
  36. save_path = save_dir / f"{image_name}.txt"
  37. with orig_label_path.open("r") as f, save_path.open("w") as g:
  38. lines = f.readlines()
  39. for line in lines:
  40. parts = line.strip().split()
  41. if len(parts) < 9:
  42. continue
  43. class_name = parts[8]
  44. class_idx = class_mapping[class_name]
  45. coords = [float(p) for p in parts[:8]]
  46. normalized_coords = [
  47. coords[i] / image_width if i % 2 == 0 else coords[i] / image_height for i in range(8)
  48. ]
  49. formatted_coords = ["{:.6g}".format(coord) for coord in normalized_coords]
  50. g.write(f"{class_idx} {' '.join(formatted_coords)}\n")
  51. for phase in ["train", "val"]:
  52. image_dir = dota_root_path / "images" / phase
  53. orig_label_dir = dota_root_path / "labels" / f"{phase}_original"
  54. save_dir = dota_root_path / "labels" / phase
  55. save_dir.mkdir(parents=True, exist_ok=True)
  56. image_paths = list(image_dir.iterdir())
  57. for image_path in TQDM(image_paths, desc=f"Processing {phase} images"):
  58. if image_path.suffix != ".png":
  59. continue
  60. image_name_without_ext = image_path.stem
  61. img = cv2.imread(str(image_path))
  62. h, w = img.shape[:2]
  63. convert_label(image_name_without_ext, w, h, orig_label_dir, save_dir)

  1. from ultralytics.data.converter import convert_dota_to_yolo_obb
  2. convert_dota_to_yolo_obb("/data/data/Ship_dota_v1.5_1024/DOTA")

5.修改yolov8-obb.yaml的类别

6.修改dota8-obb.yaml文件路径及类别 

  1. path: /data/data/Ship_dota_v1.5_1024/DOTA # dataset root dir
  2. train: images/train # train images (relative to 'path') 4 images
  3. val: images/val # val images (relative to 'path') 4 images
  4. # Classes for DOTA 1.0
  5. names:
  6. 0: gfb
  7. # Download script/URL (optional)
  8. download: https://github.com/ultralytics/yolov5/releases/download/v1.0/dota8.zip

 7.训练

  1. from ultralytics import YOLO
  2. # Load a model
  3. model = YOLO('yolov8n-obb.yaml') # build a new model from YAML
  4. model = YOLO('yolov8n-obb.pt') # load a pretrained model (recommended for training)
  5. model = YOLO('yolov8n-obb.yaml').load('yolov8n.pt') # build from YAML and transfer weights
  6. # Train the model
  7. results = model.train(data='dota8-obb.yaml', epochs=1000, imgsz=640)

8.测试 

  1. from ultralytics import YOLO
  2. # Load a model
  3. model = YOLO('yolov8n-obb.pt') # load an official model
  4. #model = YOLO('path/to/best.pt') # load a custom model
  5. # Predict with the model
  6. #results = model('https://ultralytics.com/images/bus.jpg') # predict on an image
  7. results = model('./P0006.png') # predict on an image
  8. # print("results:", results)

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

闽ICP备14008679号