Egrt / yolov7-obb

在YOLOv7的基础上使用KLD损失修改为旋转目标检测yolov7-obb
GNU General Public License v3.0
181 stars 26 forks source link

Windows安装nms_rotated #9

Closed neuhsm closed 1 year ago

neuhsm commented 1 year ago

按照博客教程安装了vs2019,并添加系统变量, image 安装11.3版本cuda,1.10.2pytorch, image

image

安装了ninja,编译时报错,在pycharm和anaconda终端编译都是报这个错 (pytorch_obb) utils\nms_rotated>python setup.py develop running develop running egg_info creating nms_rotated.egg-info writing nms_rotated.egg-info\PKG-INFO writing dependency_links to nms_rotated.egg-info\dependency_links.txt writing top-level names to nms_rotated.egg-info\top_level.txt writing manifest file 'nms_rotated.egg-info\SOURCES.txt' reading manifest file 'nms_rotated.egg-info\SOURCES.txt' writing manifest file 'nms_rotated.egg-info\SOURCES.txt' running build_ext D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py:316: UserWarning: Error checking compiler version for g++: Command 'g++' returned non-zero exit status 1. warnings.warn(f'Error checking compiler version for {compiler}: {error}') building '.nms_rotated_ext' extension Emitting ninja build file utils\nms_rotated\build\temp.win-amd64-3.6\Release\build.ninja... Compiling objects... Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N) ninja: error: 'utils/nms_rotated/src/nms_rotated_cpu.cpp', needed by 'utils/nms_rotated/build/temp.win-amd64-3.6/Release/src/nms_rotated_cpu.o', missing and no known rule to make it Traceback (most recent call last): File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 1723, in _run_ninja_build env=env) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\subprocess.py", line 438, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "setup.py", line 54, in zip_safe=False) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\setuptools__init__.py", line 163, in setup return distutils.core.setup(**attrs) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\core.py", line 148, in setup dist.run_commands() File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\setuptools\command\develop.py", line 38, in run self.install_for_development() File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\setuptools\command\develop.py", line 140, in install_for_development self.run_command('build_ext') File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\setuptools\command\build_ext.py", line 87, in run _build_ext.run(self) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 735, in build_extensions build_ext.build_extensions(self) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\Cython\Distutils\old_build_ext.py", line 195, in build_extensions _build_ext.build_ext.build_extensions(self) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\command\build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\setuptools\command\build_ext.py", line 208, in build_extension _build_ext.build_extension(self, ext) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\command\build_ext.py", line 533, in build_extension depends=ext.depends) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 565, in unix_wrap_ninja_compile with_cuda=with_cuda) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 1404, in _write_ninja_file_and_compile_objects error_prefix='Error compiling objects for extension') File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 1733, in _run_ninja_build raise RuntimeError(message) from e RuntimeError: Error compiling objects for extension

Egrt commented 1 year ago

检查cpp源代码是否为CRLF编码,如果不是,请直接git clone 仓库,不要下载压缩包解压!

neuhsm commented 1 year ago

git clone了,还是一样的错误,并且在YOLOv7比YOLOv7-tiny少一些,下面是YOLOv7的,之前的是YOLOv7-tiny的 image running build_ext D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py:316: UserWarning: Error checking compiler version for g++: Command 'g++' returned non-zero exit status 1. warnings.warn(f'Error checking compiler version for {compiler}: {error}') building '.nms_rotated_ext' extension creating utils\nms_rotated\build creating utils\nms_rotated\build\temp.win-amd64-3.6 creating utils\nms_rotated\build\temp.win-amd64-3.6\Release creating utils\nms_rotated\build\temp.win-amd64-3.6\Release\src Emitting ninja build file utils\nms_rotated\build\temp.win-amd64-3.6\Release\build.ninja... Compiling objects... Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N) ninja: error: 'utils/nms_rotated/src/nms_rotated_cpu.cpp', needed by 'utils/nms_rotated/build/temp.win-amd64-3.6/Release/src/nms_rotated_cpu.o', missing and no known rule to make it File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\Cython\Distutils\old_build_ext.py", line 195, in build_extensions _build_ext.build_ext.build_extensions(self) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\command\build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\setuptools\command\build_ext.py", line 208, in build_extension _build_ext.build_extension(self, ext) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\distutils\command\build_ext.py", line 533, in build_extension depends=ext.depends) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 565, in unix_wrap_ninja_compile with_cuda=with_cuda) File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 1404, in _write_ninja_file_and_compile_objects error_prefix='Error compiling objects for extension') File "D:\ProgramData\Anaconda3\envs\pytorch_obb\lib\site-packages\torch\utils\cpp_extension.py", line 1733, in _run_ninja_build raise RuntimeError(message) from e RuntimeError: Error compiling objects for extension

Egrt commented 1 year ago

并不需要安装ninja,我的python版本为3.8。

neuhsm commented 1 year ago

更换Python3.8后编译成功,感谢博主,同时发现一个小问题,同一个数据集我自己转换hbb和obb格式,在yolov7-tiny上训练速度大约是yolov7-tiny-obb的两倍,不知道是不是正常情况

Egrt commented 1 year ago

更换Python3.8后编译成功,感谢博主,同时发现一个小问题,同一个数据集我自己转换hbb和obb格式,在yolov7-tiny上训练速度大约是yolov7-tiny-obb的两倍,不知道是不是正常情况

正常的,KLD的损失计算比计算矩形IOU慢

neuhsm commented 1 year ago

我修改了计算map部分,计算旋转框iou可以使用OpenCV的函数,http://www.manongjc.com/detail/59-kjrbphngajnyzok.html 写了个函数可以计算两个旋转框的iou,将其替换计算iou即可,还需要修改写的gt和dr的文件以及对应读取的地方,写dr的文件时注意把弧度转换为角度,最终可以实现计算obb的map。 dr写文件,yolo.py,yolo.get_map_txt() image utils/utils_map.py里面 image 这种有好几个,我就放一个图 image get_map.py里面 image iou计算函数 image

def iou_rotate_calculate(boxes1, boxes2): 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)

计算出iou

    ious = int_area * 1.0 / (area1 + area2 - int_area)
else:
    ious = 0
return ious

obb的map mAP