Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

i run a scipt in conda env and get following errors: anonimizevideo.py", line 20, in…

  1. User

    i run a scipt in conda env and get following errors:

    anonimize_video.py", line 20, in from isuor.loops import inference_loop File "/mnt/c/Users/xyz/Downloads/Tools/Development/08_monocular_depth_estimation/isuor/src/isuor/loops.py", line 5, in from isuor.pipelines import PipelineAction File "/mnt/c/Users/xyz/Downloads/Tools/Development/08_monocular_depth_estimation/isuor/src/isuor/pipelines/init.py", line 1, in from depth.datasets.pipelines import Compose File "/home/xyz/miniconda3/envs/isuor_mde/lib/python3.10/site-packages/depth/datasets/init.py", line 2, in from .kitti import KITTIDataset File "/home/xyz/miniconda3/envs/isuor_mde/lib/python3.10/site-packages/depth/datasets/kitti.py", line 14, in from depth.utils import get_root_logger File "/home/xyz/miniconda3/envs/isuor_mde/lib/python3.10/site-packages/depth/utils/init.py", line 4, in from .position_encoding import SinePositionalEncoding, LearnedPositionalEncoding File "/home/xyz/miniconda3/envs/isuor_mde/lib/python3.10/site-packages/depth/utils/position_encoding.py", line 11, in class SinePositionalEncoding(BaseModule): File "/home/xyz/miniconda3/envs/isuor_mde/lib/python3.10/site-packages/mmcv/utils/registry.py", line 337, in _register self._register_module(module=module, module_name=name, force=force) File "/home/xyz/miniconda3/envs/isuor_mde/lib/python3.10/site-packages/mmcv/utils/misc.py", line 340, in new_func output = old_func(*args, **kwargs) File "/home/xyz/miniconda3/envs/isuor_mde/lib/python3.10/site-packages/mmcv/utils/registry.py", line 272, in _register_module raise KeyError(f'{name} is already registered ' KeyError: 'SinePositionalEncoding is already registered in position encoding'

  2. Assistant

    The error you're encountering suggests that the class SinePositionalEncoding is being registered twice in the registry, which is not allowed. This typically happens when the module defining SinePositionalEncoding is being imported more than once under different module names or paths, causing the class definition to execute multiple times.

    Here's what's likely happening:

    1. Multiple Imports of the Same Module: The module depth.utils.position_encoding is being imported more than once, possibly due to different import paths (e.g., absolute vs. relative imports) or because of conflicting module names in different directories.

    2. Duplicate depth Packages: There might be multiple copies of the depth package in your environment—one installed in your site-packages and another in your local directory or project.

    Steps to Resolve the Issue:

    1. Check for Multiple Copies of the depth Package:

      • Search your project directory and your site-packages for any instances of the depth package.
      • If you find that depth exists both in your project directory and in site-packages, decide which one you want to use and remove or rename the other to avoid conflicts.
    2. Ensure Consistent Import Paths:

      • Use absolute imports consistently throughout your code to prevent Python from interpreting the same module as two different ones.
      • Avoid using relative imports if they can cause ambiguity in module paths.
    3. Verify Your PYTHONPATH and sys.path:

      • Print out sys.path at the start of your script to see which directories are being searched for modules.
      • Ensure that the directories in sys.path do not contain conflicting module names that could lead to the same module being imported from different locations.
    4. Modify the Registry Registration:

      • In the module where SinePositionalEncoding is defined (usually with a decorator like @POSITION_ENCODING.register_module()), you can add a force=True parameter to allow re-registration:
        @POSITION_ENCODING.register_module(force=True)
        class SinePositionalEncoding(BaseModule):
            ...
        
        • Note: This is generally not recommended as it may mask underlying issues with your imports. It's better to resolve the root cause.
    5. Avoid Circular Imports:

      • Check your code for circular imports that could cause modules to be imported multiple times.
    6. Clean and Reinstall Your Environment:

      • Sometimes, stale .pyc files or leftover old module versions can cause issues.
      • Delete __pycache__ directories and recompile your code.
      • If necessary, create a fresh conda environment and reinstall your dependencies carefully.

    Example of Checking for Multiple Copies:

    # Find all instances of the 'depth' package
    find / -type d -name 'depth' 2>/dev/null
    

    Example of Printing sys.path:

    import sys
    print(sys.path)
    

    By ensuring that the depth package (and specifically the position_encoding module) is only present once in your module search path and that it's being imported consistently, you should be able to resolve the KeyError you're encountering.

    Summary:

    • The KeyError arises because SinePositionalEncoding is being registered twice.
    • This is likely due to the module being imported more than once under different paths.
    • Ensure there's only one version of the module and that imports are consistent.
    • Check for and resolve any conflicts in your module paths or names.