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: Failed to import projects.<MODEL_NAME>.<model> #11082

Closed
charisoudis opened this issue Oct 24, 2023 · 6 comments
Closed

ImportError: Failed to import projects.<MODEL_NAME>.<model> #11082

charisoudis opened this issue Oct 24, 2023 · 6 comments
Assignees

Comments

@charisoudis
Copy link

charisoudis commented Oct 24, 2023

I cannot instantiate a custom model, Co-DETR given the weights.

After searching, it seems that there is a package named "projects" which prevents python from searching into the mmdetection directory (it is in the PYTHONPATH).

>>> from mmdet.apis import DetInferencer
>>> DetInferencer(weights='/workspace/out/checkpoints/co-detr/co_dino_5scale_r50_lsj_8xb2_1x_coco-69a72d67.pth')
>>> ...
>>> ImportError: Failed to import custom modules from {'allow_failed_imports': False, 'imports': ['projects.CO-DETR.codetr']}, the current sys.path is: 
    
    /mmdetection
    /workspace
    /opt/conda/lib/python310.zip
    /opt/conda/lib/python3.10
    /opt/conda/lib/python3.10/lib-dynload
    /opt/conda/lib/python3.10/site-packages
    /opt/conda/lib/python3.10/site-packages/smplx-0.1.28-py3.10.egg
    /tmp/tmp1_v1g0zy
You should set `PYTHONPATH` to make `sys.path` include the directory which contains your custom module
>>>
>>>
>>> import projects
>>> projects.__file__
'/opt/conda/lib/python3.10/site-packages/projects/__init__.py'
>>> 

My env is a docker image (thanosch/mmtorch:2.1.0-cuda121) with Python 3.10 and the latest version of mm:

  • mmcv 2.1.0
  • mmdet 3.2.0
  • mmengine 0.9.0
  • mmpose 1.2.0
@hhaAndroid
Copy link
Collaborator

@achariso This operation is not supported under the project. You need to prepare the configuration and weights.

@Jordan-Pierce
Copy link

@hhaAndroid can you please elaborate?

@LokeshJatangi
Copy link

LokeshJatangi commented Nov 2, 2023

@Jordan-Pierce I could solve the above error , by adding path to mmdetection to python path or through sys.path.append(path_to_mmedetection_dir)

@charisoudis
Copy link
Author

Adding to @LokeshJatangi 's solution, one has to modify the config imports as well.

@bibekyess
Copy link

#11913 provides a simple fix to this.

@L-Reichardt
Copy link

L-Reichardt commented Oct 29, 2024

I've had the same issue, but with different causes.

1.) I had another library installed, which also had a module "projects" in it. The import logic in MMEngine imported from that library instead.
-> The Solution was to delete the other library. I have not yet found a way to keep both, without changing folder names.

2.) For me, MMDet also needed to be installed in "editable" (pip install . -e) mode to use projects.

  • Installing without "editable" causes the projects folder to be missing since its below the mmdet folder. Adding +["projects"] to setup.py did not help.
  • However, if I did install normally (without editable flag -e) the import failed and created a namespace "projects" in site-packages. The corresponding folder needed to be manually removed from site-packages, as it persists and keeps causing import errors.

For me, the import logic of mmengine in the context of using "projects" is not robust.

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

6 participants