open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.59k stars 9.46k forks source link

mmcv _file2dict shutil.copyfile PermissionError: [Errno 13] Permission denied #2926

Closed yg2024 closed 4 years ago

yg2024 commented 4 years ago

import matplotlib; matplotlib.use('Agg') Traceback (most recent call last): File "demo/image_demo.py", line 26, in main() File "demo/image_demo.py", line 18, in main model = init_detector(args.config, args.checkpoint, device=args.device) File "d:\python\pycharm\pycharmprojects\mmdetection\mmdet\apis\inference.py", line 28, in init_detector config = mmcv.Config.fromfile(config) File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 165, in fromfile cfg_dict, cfg_text = Config._file2dict(filename) File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 92, in _file2dict osp.join(temp_config_dir, temp_config_name)) File "D:\python\Python36\lib\shutil.py", line 121, in copyfile with open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied: 'C:\Users\XXX\AppData\Local\Temp\tmp_lu6u3id\tmpo9exnnds.py'

nothingws commented 4 years ago

import matplotlib; matplotlib.use('Agg') Traceback (most recent call last): File "demo/image_demo.py", line 26, in main() File "demo/image_demo.py", line 18, in main model = init_detector(args.config, args.checkpoint, device=args.device) File "d:\python\pycharm\pycharmprojects\mmdetection\mmdet\apis\inference.py", line 28, in init_detector config = mmcv.Config.fromfile(config) File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 165, in fromfile cfg_dict, cfg_text = Config._file2dict(filename) File "D:\python\Python36\lib\site-packages\mmcv\utils\config.py", line 92, in _file2dict osp.join(temp_config_dir, temp_config_name)) File "D:\python\Python36\lib\shutil.py", line 121, in copyfile with open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied: 'C:\Users\XXX\AppData\Local\Temp\tmp_lu6u3id\tmpo9exnnds.py'

I have the same problem. Have you solved it

aligoglos commented 4 years ago

I've got same error too !!!

aligoglos commented 4 years ago

I've solved it with these tricks : (its not good way but you could run it!) 1) first change config.py by replacing these lines:

            with tempfile.TemporaryDirectory() as temp_config_dir:
                temp_config_file = tempfile.NamedTemporaryFile(
                    dir=temp_config_dir, suffix='.py')
                temp_config_name = osp.basename(temp_config_file.name)
                des = osp.join(temp_config_dir, temp_config_name).replace('\\', '/')
                shutil.copyfile(filename,des)
                temp_module_name = osp.splitext(temp_config_name)[0]
                sys.path.insert(0, temp_config_dir)
                mod = import_module(temp_module_name)
                sys.path.pop(0)
                cfg_dict = {
                    name: value
                    for name, value in mod.__dict__.items()
                    if not name.startswith('__')
                }
                delete imported module
                del sys.modules[temp_module_name]
                close temp file
                temp_config_file.close()

with:

            mod = import_module('DetectoRS')
            sys.path.pop(0)
            cfg_dict = {
               name: value
               for name, value in mod.__dict__.items()
               if not name.startswith('__')
            }

and then copy config fime behind webcam_demo.py and renamed it with DetectoRS.py

nekitmm commented 4 years ago

Also got this problem. No idea what is the cause of this, but I solved it by changing two lines

This: temp_config_file = tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='.py')

changed to this: temp_config_file = tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='')

And: shutil.copy(filename, osp.join(temp_config_dir, temp_config_name))

To: shutil.copy(filename, osp.join(temp_config_dir, temp_config_name) + '.py')

No idea what is going on, but whenever suffix argument is different from actual file extension - everything works and every time file extension is the same as suffix argument I get this permission denied error.

TimothyZero commented 4 years ago

replace :

tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='.py')

with

tempfile.NamedTemporaryFile(dir=temp_config_dir, suffix='.py', delete=False)

it works for me