文章目录

  • ​​加入环境变量​​
  • ​​通过config配置​​
  • ​​直接import路径加入​​

加入环境变量

工程目录结构:

  • your_project
  • projects
  • mmdet3d_plugin
  • config
  • tools
  • ​train.py​
  • ​test.py​

通过config配置

  1. 需要在运行代码​​train.py​​​和​​test.py​​中加入两部分代码:
  • 加入到py文件的开头:
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))[:-5]) # insert project abs path
print(os.path.dirname(os.path.abspath(__file__))[:-5])

MMDet3D——构建基本工程demo,解决路径BUG_3d


需要在运行代码​​train.py​​​和​​test.py​​中加入:

  • 加入到main()函数中:
# import modules from plguin/xx, registry will be updated
if hasattr(cfg, 'plugin'):
if cfg.plugin:
import importlib
if hasattr(cfg, 'plugin_dir'):
plugin_dir = cfg.plugin_dir
_module_dir = os.path.dirname(plugin_dir)
_module_dir = _module_dir.split('/')
_module_path = _module_dir[0]

for m in _module_dir[1:]:
_module_path = _module_path + '.' + m
print(_module_path)
plg_lib = importlib.import_module(_module_path)
else:
# import dir is the dirpath for the config file
_module_dir = os.path.dirname(args.config)
_module_dir = _module_dir.split('/')
_module_path = _module_dir[0]
for m in _module_dir[1:]:
_module_path = _module_path + '.' + m
print(_module_path)
plg_lib = importlib.import_module(_module_path)

MMDet3D——构建基本工程demo,解决路径BUG_3d_02

  1. 在​​config​​文件中加入代码:
plugin=True
plugin_dir='projects/mmdet3d_plugin/'

MMDet3D——构建基本工程demo,解决路径BUG_python_03

直接import路径加入

  • 在需要运行的py文件的开始加入:
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))[:-5]) # insert project abs path
print(os.path.dirname(os.path.abspath(__file__))[:-5])
# import modules from plguin/xx, registry will be updated
import importlib
importlib.import_module('projects.mmdet3d_plugin')