成功在windows系统上安装OpenPCDet-踩坑无数版

2023-12-20 00:34:23

先上图

在网上看了无数帖子,终于集百家之长后,安装成功了。事实证明是可以安装成功的,希望还在挣扎的兄弟们不要放弃。
在这里插入图片描述

关键配置(版本问题很致命)

#有的差一个小版本号都会出问题
操作系统 : win10
cuda版本 : 11.7[cuda安装参考](https://blog.csdn.net/weixin_43848614/article/details/117221384))
python : 3.8
torch : 1.13.1+cu116(OpenPCDet要求在1.10.0以下,但是在安装C++ build tools与cuda的的时候遇到了很多版本不兼容的问题)
torchaudio : 0.13.1+cu116
torchvision :  0.14.1+cu116
numpy : 1.20.0
scikit-image : 0.15.0
scipy : 1.9.1
setuptools : 58.2.0
spconv : spconv-cu117
cumm : cumm-cu117(很关键,否则会导致以下错误)
 from cumm.core_cc import tensorview_bind
ImportError: DLL load failed while importing core_cc: 找不到指定的模块。

创建虚拟环境开始安装

问题1 windows无法直接pip install SharedArray

创建过程就不废话了,按照requirements.txt,配置环境就可以,注意我标注的版本号。
主要说一下SharedArray的安装。
首先新建一个文件夹,不要和OpenPCDet项目放在一起,不然import可能会出现问题(切记)
然后 在新建的目录下面把SharedArray的安装包下载下来,或者在当前目录打开终端
git clone https://github.com/imaginary-friend94/SharedNumpyArray.git

cd SharedNumpyArray ,即到SharedNumpyArray目录下。
python setup develop
参考这篇文章

问题2 ERROR: Could not build wheels for SharedArray, which is required to install pyproject.toml-based projects

这是由于没有cmake工具造成的
下载C++build tools
在这里插入图片描述
安装
在这里插入图片描述

问题3 error: command ‘D:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\bin\HostX86\x64\cl.exe’ failed with exit code 2

在环境变量PATH中,添加

D:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\bin\HostX86\x64

重新python setup develop,截止到这SharedArray安装完毕,所需环境基本搭建完成。
进入OpenPCDet的项目里进行python setup develop之前。

1、对pcdet\ops\iou3d_nms\src里面的文件进行修改

iou3d_nms.cpp

/*
3D Rotated IoU Calculation (CPU)
Written by Shaoshuai Shi
All Rights Reserved 2020.
*/

#include <stdio.h>
#include <math.h>
#include <torch/serialize/tensor.h>
#include <torch/extension.h>
#include <vector>
#include <cuda.h>
#include <cuda_runtime_api.h>
#include "iou3d_cpu.h"

#define CHECK_CUDA(x) do { \
  if (!x.type().is_cuda()) {
    \
    fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
    exit(-1); \
  } \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
  if (!x.is_contiguous()) {
    \
    fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
    exit(-1); \
  } \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)

inline float min(float a, float b){
   
    return a > b ? b : a;
}

inline float max(float a, float b){
   
    return a > b ? a : b;
}

const float EPS = 1e-8;
struct Point {
   
    float x, y;
    __device__ Point() {
   }
    __device__ Point(double _x, double _y){
   
        x = _x, y = _y;
    }

    __device__ void set(float _x, float _y){
   
        x = _x; y = _y;
    }

    __device__ Point operator +(const Point &b)const{
   
        return Point(x + b.x, y + b.y);
    }

    __device__ Point operator -(const Point &b)const{
   
        return Point(x - b.x, y - b.y);
    }
};

inline float cross(const Point &a, const Point &b){
   
    return a.x * b.y - a.y * b.x;
}

inline float cross(const Point &p1, const Point &p2, const Point &p0){
   
    return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}

inline int check_rect_cross(const Point &p1, const Point &p2, const Point &q1, const Point &q2){
   
    int ret = min(p1.x,p2.x) <= max(q1.x,q2.x)  &&
              min(q1.x,q2.x) <= max(p1.x,p2.x) &&
              min(p1.y,p2.y) <= max(q1.y,q2.y) &&
              min(q1.y,q2.y) <= max(p1.y,p2.y);
    return ret;
}

inline int check_in_box2d(const float *box, const Point &p){
   
    //params: (7) [x, y, z, dx, dy, dz, heading]
    const float MARGIN = 1e-2;

    float center_x = box[0], center_y = box[1];
    float angle_cos = cos(-box[6]), angle_sin = sin(-box[6]);  // rotate the point in the opposite direction of box
    float rot_x = (p.x - center_x) * angle_cos + (p.y - center_y) * (-angle_sin);
    float rot_y = (p.x - center_x) * angle_sin + (p.y - center_y) * angle_cos;

    return (fabs(rot_x) < box[3] / 2 + MARGIN && fabs(rot_y) < box[4] / 2 + MARGIN);
}

inline int intersection(const Point &p1, const Point &p0, const Point &q1, const Point &q0, Point &ans){
   
    // fast exclusion
    if (check_rect_cross(p0, p1, q0, q1) == 0) return 0;

    // check cross standing
    float s1 = cross(q0, p1, p0);
    float s2 = cross(p1, q1, p0);
    float s3 = cross(p0, q1, q0);
    float s4 = cross(q1, p1, q0);

    if (!(s1 * s2 > 0 && s3 * s4 > 0)) return 0;

    // calculate intersection of two lines
    float s5 = cross(q1, p1, p0);
    if(fabs(s5 - s1) > EPS){
   
        ans.x = (s5 * q0.x - s1 * q1.x) / (s5 - s1);
        ans.y = (s5 * q0.y - s1 * q1.y) / (s5 - s1);

    }
    else{
   
        float a0 = p0.y - p1.y, b0 = p1.x - p0.x, c0 = p0.x * p1.y - p1.x * p0.y;
        float a1 = q0.y - q1.y, b1 = q1.x - q0.x, c1 = q0.x * q1.y - q1.x * q0.y;
        float D = a0 * b1 - a1 * b0;

        ans.x = (b0 * c1 - b1 * c0) / D;
        ans.y = (a1 * c0 - a0 * c1) / D;
    }

    return 1;
}

inline void rotate_around_center(const Point &center, const float angle_cos, const float angle_sin, Point &p){
   
    float new_x = (p.x - center.x) * angle_cos + (p.y - center.y) * (-angle_sin) + center.x;
    float new_y = (p.x - center.x) * angle_sin + (p.y - center.y) * angle_cos + center.y;
    p.set(new_x, new_y);
}

inline int point_cmp(const Point &a, const Point &b, const Point &center){
   
    return atan2(a.y - center.y, a.x - center.x) > atan2(b.y - center.y, b.x - center.x);
}

inline float box_overlap(const float *box_a, const float *box_b){
   
    // params: box_a (7) [x, y, z, dx, dy, dz, heading]
    // params: box_b (7) [x, y, z, dx, dy, dz, heading]

//    float a_x1 = box_a[0], a_y1 = box_a[1], a_x2 = box_a[2], a_y2 = box_a[3], a_angle = box_a[4];
//    float b_x1 = box_b[0], b_y1 = box_b[1], b_x2 

文章来源:https://blog.csdn.net/weixin_49252254/article/details/135087124
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。