Quellcode durchsuchen

bugfix(3d_bev_detection):modify open3d import method to lazy. (#3302)

Jonathans575 vor 9 Monaten
Ursprung
Commit
df31cea59e

+ 12 - 0
docs/module_usage/tutorials/cv_modules/3d_bev_detection.en.md

@@ -43,6 +43,18 @@ output = pipeline.predict("nuscenes_demo_infer.tar")
 for res in output:
     res.print()  ## Print the structured output of the prediction
     res.save_to_json("./output/")  ## Save the results to a JSON file```
+    res.visualize(save_path="./output/", show=True) ## 3D result visualization. If the runtime environment has a graphical interface, set `show=True`; otherwise, set it to `False`.
+```
+
+<b>Note: </b>  
+1、To visualize 3D detection results, you need to install the open3d package first. The installation command is as follows:
+```bash
+pip install open3d
+```
+2、If the runtime environment does not have a graphical interface, visualization will not be possible, but the results will still be saved. You can run the script in an environment that supports a graphical interface to visualize the saved results:
+```bash
+python paddlex/inference/models/3d_bev_detection/visualizer_3d.py --save_path="./output/"
+```
 
 After running, the result obtained is:
 

+ 6 - 1
docs/module_usage/tutorials/cv_modules/3d_bev_detection.md

@@ -51,7 +51,12 @@ for res in output:
     res.visualize(save_path="./output/", show=True) ## 3d结果可视化,如果运行环境有图形界面设置show=True,否则设置为False
 ```
 
-<b>注:</b> 如果运行环境没有图形界面,则无法可视化,但不影响结果的保存,可以在支持图形界面的环境下运行脚本,对保存的结果进行可视化:
+<b>注:</b>   
+1、3d检测结果可视化需要先安装open3d包,安装命令如下:
+```bash
+pip install open3d
+```
+2、如果运行环境没有图形界面,则无法可视化,但不影响结果的保存,可以在支持图形界面的环境下运行脚本,对保存的结果进行可视化:
 ```bash
 python paddlex/inference/models/3d_bev_detection/visualizer_3d.py --save_path="./output/"
 ```

+ 6 - 1
docs/pipeline_usage/tutorials/cv_pipelines/3d_bev_detection.en.md

@@ -142,7 +142,12 @@ for res in output:
     res.visualize(save_path="./output/", show=True) ## 3D result visualization. If the runtime environment has a graphical interface, set `show=True`; otherwise, set it to `False`.
 ```
 
-<b>Note: </b> If the runtime environment does not have a graphical interface, visualization will not be possible, but the results will still be saved. You can run the script in an environment that supports a graphical interface to visualize the saved results:
+<b>Note: </b>  
+1、To visualize 3D detection results, you need to install the open3d package first. The installation command is as follows:
+```bash
+pip install open3d
+```
+2、If the runtime environment does not have a graphical interface, visualization will not be possible, but the results will still be saved. You can run the script in an environment that supports a graphical interface to visualize the saved results:
 ```bash
 python paddlex/inference/models/3d_bev_detection/visualizer_3d.py --save_path="./output/"
 ```

+ 6 - 1
docs/pipeline_usage/tutorials/cv_pipelines/3d_bev_detection.md

@@ -134,7 +134,12 @@ for res in output:
     res.visualize(save_path="./output/", show=True) ## 3d结果可视化,如果运行环境有图形界面设置show=True,否则设置为False
 ```
 
-<b>注:</b> 如果运行环境没有图形界面,则无法可视化,但不影响结果的保存,可以在支持图形界面的环境下运行脚本,对保存的结果进行可视化:
+<b>注:</b>   
+1、3d检测结果可视化需要先安装open3d包,安装命令如下:
+```bash
+pip install open3d
+```
+2、如果运行环境没有图形界面,则无法可视化,但不影响结果的保存,可以在支持图形界面的环境下运行脚本,对保存的结果进行可视化:
 ```bash
 python paddlex/inference/models/3d_bev_detection/visualizer_3d.py --save_path="./output/"
 ```

+ 15 - 2
paddlex/inference/models/3d_bev_detection/visualizer_3d.py

@@ -1,13 +1,26 @@
 import os
-import open3d
 import numpy as np
 import argparse
+import importlib.util
+import sys
+
+class LazyLoader:
+    def __init__(self, module_name):
+        self.module_name = module_name
+        self._module = None
+
+    def __getattr__(self, item):
+        if self._module is None:
+            self._module = importlib.import_module(self.module_name)
+        return getattr(self._module, item)
+
+open3d = LazyLoader('open3d')
 
 class Visualizer3D:
     def __init__(self):
         self.vis = open3d.visualization.Visualizer() # initialize visualizer
 
-    def boxes_to_lines(self, box: np.ndarray) -> open3d.geometry.LineSet:
+    def boxes_to_lines(self, box: np.ndarray):
         """
            4-------- 6
          /|         /|

+ 0 - 1
requirements.txt

@@ -14,7 +14,6 @@ albumentations==1.4.10
 opencv-python==4.5.5.64
 opencv-python-headless==4.10.0.84
 opencv-contrib-python==4.10.0.84
-open3d
 chinese_calendar
 scikit-learn
 pycocotools