Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: g:\Pythonproject\YOLOX-main\exps\example\yolo_voc\yolox_voc_s.py doesn't contains class named 'Exp' #317

Closed
haomayang1126 opened this issue Aug 2, 2021 · 3 comments

Comments

@haomayang1126
Copy link

Traceback (most recent call last):
File "g:\pythonproject\yolox-main\yolox\exp\build.py", line 15, in get_exp_by_file
current_exp = importlib.import_module(os.path.basename(exp_file).split(".")[0])
File "C:\Users\xiaoma\Anaconda3\envs\Swin\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'yolox_voc_s'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "tools/train.py", line 110, in
exp = get_exp(args.exp_file, args.name)
File "g:\pythonproject\yolox-main\yolox\exp\build.py", line 54, in get_exp
return get_exp_by_file(exp_file)
File "g:\pythonproject\yolox-main\yolox\exp\build.py", line 19, in get_exp_by_file
raise ImportError("{} doesn't contains class named 'Exp'".format(exp_file))
ImportError: g:\Pythonproject\YOLOX-main\exps\example\yolo_voc\yolox_voc_s.py doesn't contains class named 'Exp'

(Swin) G:\Pythonproject\YOLOX-main>

@haomayang1126
Copy link
Author

指令打错了,仔细检查文件名,路径没对

@qq1243196045
Copy link

我也是这个错误,路径是复制的...用命令行就不报错,在IDE里面就报错(-f 设置了default值),仔细想想IDEtrain.py在tools下面,如果要用相对路径的话要..到项目根目录(pycharm的目录结构问题,VSCODE没有这个问题),或者在run/edit-configurations下修改working dir为项目根目录......

@WentingDu
Copy link

WentingDu commented Jul 10, 2022

指令打错了,仔细检查文件名,路径没对

还真是,我一开始在pycharm的Terminal里面输入指令: python tools/train.py -f /exps/example/yolox_voc/yolox_voc_s.py -d 1 -b 8 --fp16 -o 结果报了下面这个错:

Traceback (most recent call last):
File "/home/dwt/MyCode/pycharm_projects/YOLOX/yolox/exp/build.py", line 14, in get_exp_by_file
current_exp = importlib.import_module(os.path.basename(exp_file).split(".")[0])#importlib.import_module()导入括号内给出的python文件 ; os.path.basename()返回path最后的文件名。
File "/home/dwt/anaconda3/envs/fbnet_yolox/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'yolox_voc_s'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "tools/train.py", line 143, in
exp = get_exp(args.exp_file, args.name)#这里返回了类Exp,首先通过get_exp()函数找到实现储存着事先定义好的yolox训练配置的python文件,并且其中对训练的配置全部写在名为Exp的类定义中
File "/home/dwt/MyCode/pycharm_projects/YOLOX/yolox/exp/build.py", line 42, in get_exp
return get_exp_by_file(exp_file)
File "/home/dwt/MyCode/pycharm_projects/YOLOX/yolox/exp/build.py", line 18, in get_exp_by_file
raise ImportError("{} doesn't contains class named 'Exp'".format(exp_file))
ImportError: /exps/example/yolox_voc/yolox_voc_s.py doesn't contains class named 'Exp'

接着修改指令中-f 后面的地址参数:python tools/train.py -f exps/example/yolox_voc/yolox_voc_s.py -d 1 -b 8 --fp16 -o,就跑起来了。原来是多加了一个 "/"导致的错误。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants