Browse Source

change dectection_lidar_pointpillars_multihead. In AGX, Test Fail. Prepare test in X86.

yuchuli 3 years ago
parent
commit
662cc55baf

+ 28 - 2
src/detection/detection_lidar_PointPillars_MultiHead/detection_lidar_PointPillars_MultiHead.pro

@@ -122,8 +122,34 @@ LIBS += -L/usr/local/cuda-10.2/targets/aarch64-linux/lib
 
 LIBS += -lcudart -lcufft -lyaml-cpp
 
-LIBS += -L/home/adc/soft/cudnn-10.2-linux-x64-v7.6.5.32/cuda/lib64 -lcudnn
+#LIBS += -L/home/adc/soft/cudnn-10.2-linux-x64-v7.6.5.32/cuda/lib64 -lcudnn
 
 LIBS +=  -lmyelin -lnvinfer -lnvonnxparser -lnvcaffe_parser
 
-LIBS += -L/home/nvidia/git/libtorch_gpu-1.6.0-linux-aarch64/lib -ltorch_cuda  -ltorch -lc10 -ltorch_cpu
+#LIBS += -L/home/nvidia/git/libtorch_gpu-1.6.0-linux-aarch64/lib -ltorch_cuda  -ltorch -lc10 -ltorch_cpu
+
+unix:INCLUDEPATH += /usr/include/eigen3
+unix:INCLUDEPATH += /usr/include/pcl-1.7
+unix:INCLUDEPATH += /usr/include/pcl-1.8
+
+
+LIBS += -lboost_system
+
+unix:LIBS +=  -lpcl_common\
+        -lpcl_features\
+        -lpcl_filters\
+        -lpcl_io\
+        -lpcl_io_ply\
+        -lpcl_kdtree\
+        -lpcl_keypoints\
+        -lpcl_octree\
+        -lpcl_outofcore\
+        -lpcl_people\
+        -lpcl_recognition\
+        -lpcl_registration\
+        -lpcl_sample_consensus\
+        -lpcl_search\
+        -lpcl_segmentation\
+        -lpcl_surface\
+        -lpcl_tracking\
+        -lpcl_visualization

+ 135 - 0
src/detection/detection_lidar_PointPillars_MultiHead/main.cpp

@@ -1,8 +1,143 @@
 #include <QCoreApplication>
 
+#include <QDateTime>
+
+#include <iostream>
+
+#include "pointpillars.h"
+
+
+#include <iostream>
+
+#include <pcl/point_cloud.h>
+#include <pcl/point_types.h>
+#include <pcl/io/io.h>
+#include <pcl/io/pcd_io.h>
+
+void PclToArray(
+    const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
+    float* out_points_array, const float normalizing_factor) {
+  for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
+    pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
+    out_points_array[i * 3 + 0] = point.x;
+    out_points_array[i * 3 + 1] = point.y;
+    out_points_array[i * 3 + 2] = point.z;
+    out_points_array[i * 4 + 3] =
+        static_cast<float>(point.intensity / normalizing_factor);
+  }
+}
+
+void PclXYZITToArray(
+    const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
+    float* out_points_array, const float normalizing_factor) {
+  for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
+    pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
+    out_points_array[i * 5 + 0] = point.x;
+    out_points_array[i * 5 + 1] = point.y;
+    out_points_array[i * 5 + 2] = point.z;
+    out_points_array[i * 5 + 3] =
+        static_cast<float>(point.intensity / normalizing_factor);
+    out_points_array[i * 5 + 4] = 0;
+  }
+}
+
+void Boxes2Txt( std::vector<float> boxes , string file_name , int num_feature = 7)
+{
+    ofstream ofFile;
+    ofFile.open(file_name , std::ios::out );
+    if (ofFile.is_open()) {
+        for (int i = 0 ; i < boxes.size() / num_feature ; ++i) {
+            for (int j = 0 ; j < num_feature ; ++j) {
+                ofFile << boxes.at(i * num_feature + j) << " ";
+            }
+            ofFile << "\n";
+        }
+    }
+    ofFile.close();
+    return ;
+};
+
+
+void test(std::string pfe_file,std::string backbone_file,std::string pp_config)
+{
+
+    PointPillars * pPillars;
+    pPillars = new PointPillars(
+      0.1,
+      0.2,
+      true,
+      pfe_file,
+      backbone_file,
+      pp_config
+    );
+    std::cout<<"PointPillars Init OK."<<std::endl;
+
+    pcl::PointCloud<pcl::PointXYZI>::Ptr xpc(
+        new pcl::PointCloud<pcl::PointXYZI>);
+
+
+    pcl::PointCloud<pcl::PointXYZI>::Ptr xpcfile;
+
+    xpcfile = boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI>>(new pcl::PointCloud<pcl::PointXYZI>);
+
+    if(0 == pcl::io::loadPCDFile("/home/nvidia/20200604054241688.pcd",*xpc))
+    {
+
+    }
+    else
+    {
+        std::cout<<"load pcd fail"<<std::endl;
+        return;
+    }
+
+    const int kNumPointFeature = 5;
+    const int kOutputNumBoxFeature = 7;
+
+
+//    for (size_t i = 0; i < xpcfile->size(); ++i) {
+//      pcl::PointXYZI point;
+//      point.x = xpcfile->at(i).x;
+//      point.y = xpcfile->at(i).y;qt
+//      point.z = xpcfile->at(i).z;
+//      point.intensity = 0;
+//      xpc->push_back(point);
+//    }
+
+    std::cout<<"point size is "<<xpc->width<<std::endl;
+
+
+    float* points_array = new float[xpc->size() * kNumPointFeature];
+    PclXYZITToArray(xpc, points_array, 255.0);
+
+    int    in_num_points = in_num_points;
+
+    std::vector<float> out_detections;
+    std::vector<int> out_labels;
+    std::vector<float> out_scores;
+
+    QTime xTime;
+
+    xTime.start();
+
+    cudaDeviceSynchronize();
+    pPillars->DoInference(points_array, in_num_points, &out_detections, &out_labels , &out_scores);
+    cudaDeviceSynchronize();
+    int BoxFeature = 7;
+    int num_objects = out_detections.size() / BoxFeature;
+
+    std::cout<<"objects num: "<<num_objects<<std::endl;
+    std::cout<<"infer time: "<<xTime.elapsed()<<std::endl;
+
+    std::string boxes_file_name = "/home/nvidia/pointpillarsout.txt";
+    Boxes2Txt(out_detections , boxes_file_name );
+}
+
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
 
+    test("/home/nvidia/Downloads/cbgs_pp_multihead_pfe.onnx",
+         "/home/nvidia/Downloads/cbgs_pp_multihead_backbone.onnx",
+         "/home/nvidia/code/modularization/src/detection/detection_lidar_PointPillars_MultiHead/cfgs/cbgs_pp_multihead.yaml");
     return a.exec();
 }