MMDet3D——构建基本工程demo,解决路径BUG
原创
©著作权归作者所有:来自51CTO博客作者IrvingGao的原创作品,请联系作者获取转载授权,否则将追究法律责任
文章目录
- 通过config配置
- 直接import路径加入
加入环境变量
工程目录结构:
通过config配置
- 需要在运行代码
train.py
和test.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])
需要在运行代码train.py
和test.py
中加入:
# 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)
- 在
config
文件中加入代码:
plugin=True
plugin_dir='projects/mmdet3d_plugin/'
直接import路径加入
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')