diff --git a/.gitignore b/.gitignore index 9953d9b49b..c1abaf794a 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,8 @@ model_ts*.txt .idea .vscode _darcs +.venv +.envrc # project dirs /detectron2/model_zoo/configs diff --git a/detectron2/model_zoo/model_zoo.py b/detectron2/model_zoo/model_zoo.py index 4e80ffd48f..28db8d692e 100644 --- a/detectron2/model_zoo/model_zoo.py +++ b/detectron2/model_zoo/model_zoo.py @@ -1,12 +1,15 @@ # Copyright (c) Facebook, Inc. and its affiliates. + +import atexit import os -from typing import Optional -import pkg_resources import torch +from contextlib import ExitStack from detectron2.checkpoint import DetectionCheckpointer from detectron2.config import CfgNode, LazyConfig, get_cfg, instantiate from detectron2.modeling import build_model +from importlib import resources as importlib_resources +from typing import Optional class _ModelZooUrls: @@ -136,9 +139,10 @@ def get_config_file(config_path): Returns: str: the real path to the config file. """ - cfg_file = pkg_resources.resource_filename( - "detectron2.model_zoo", os.path.join("configs", config_path) - ) + file_manager = ExitStack() + atexit.register(file_manager.close) + ref = importlib_resources.files("detectron2.model_zoo") / os.path.join("configs", config_path) + cfg_file = file_manager.enter_context(importlib_resources.as_file(ref)) if not os.path.exists(cfg_file): raise RuntimeError("{} not available in Model Zoo!".format(config_path)) return cfg_file diff --git a/setup.cfg b/setup.cfg index f127d7ba05..62ebded5e5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ known_standard_library=numpy,setuptools,mock skip=./datasets,docs skip_glob=*/__init__.py,**/configs/**,**/tests/config/** known_myself=detectron2 -known_third_party=fvcore,matplotlib,cv2,torch,torchvision,PIL,pycocotools,yacs,termcolor,cityscapesscripts,tabulate,tqdm,scipy,lvis,psutil,pkg_resources,caffe2,onnx,panopticapi,black,isort,av,iopath,omegaconf,hydra,yaml,pydoc,submitit,cloudpickle,packaging,timm,pandas,fairscale,pytorch3d,pytorch_lightning +known_third_party=fvcore,matplotlib,cv2,torch,torchvision,PIL,pycocotools,yacs,termcolor,cityscapesscripts,tabulate,tqdm,scipy,lvis,psutil,importlib_resources,caffe2,onnx,panopticapi,black,isort,av,iopath,omegaconf,hydra,yaml,pydoc,submitit,cloudpickle,packaging,timm,pandas,fairscale,pytorch3d,pytorch_lightning no_lines_before=STDLIB,THIRDPARTY sections=FUTURE,STDLIB,THIRDPARTY,myself,FIRSTPARTY,LOCALFOLDER default_section=FIRSTPARTY