Adjust MMCV_MAX version in MDE-Toolbox to prevent version complaints
RUN sed -i "s/MMCV_MAX = '1.5.0'/MMCV_MAX = '1.8.0'/g" /mde_toolbox/depth/init.py
Install yapf to fix configuration printing bug
RUN pip install yapf==0.40.1
Replace memory hook in MMCV to fix GPU context issue
COPY patch/hooks_memory.py $CONDA_DIR/envs/isuor/lib/python3.9/site-packages/mmcv/runner/hooks/memory.py with conda_env.yml: name: isuor_face
channels:
defaults
pytorch
conda-forge
dependencies:
python=3.9
numpy=1.21.2
pytorch=1.12.1
torchvision=0.13.1
torchaudio=0.12.1
cudatoolkit=11.3
tqdm=4.64.1
pyyaml=6.0
matplotlib=3.5.3
h5py=3.7.0
scikit-learn=1.1.3
pandas=1.4.4
cython=0.29.32 # Removed duplicate 'cython'
ipython=8.6.0
ffmpeg=4.2.2
tensorboard
lap # Verify availability in channels
pip # Include pip without version
pip:
opencv-python==4.6.0.66
openmim==0.3.5
timm==0.6.12 but get following error: anonimize_video.py", line 12, in
from mmdet.apis import init_detector, inference_detector
File "/mmdet/mmdet/apis/init.py", line 2, in
from .inference import (async_inference_detector, inference_detector,
File "/mmdet/mmdet/apis/inference.py", line 8, in
from mmcv.ops import RoIPool
File "/opt/conda/envs/isuor/lib/python3.9/site-packages/mmcv/ops/init.py", line 3, in
from .active_rotated_filter import active_rotated_filter
File "/opt/conda/envs/isuor/lib/python3.9/site-packages/mmcv/ops/active_rotated_filter.py", line 10, in
ext_module = ext_loader.load_ext(
File "/opt/conda/envs/isuor/lib/python3.9/site-packages/mmcv/utils/ext_loader.py", line 13, in load_ext
ext = importlib.import_module('mmcv.' + name)
File "/opt/conda/envs/isuor/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: /opt/conda/envs/isuor/lib/python3.9/site-packages/mmcv/_ext.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZN3c1014DeviceTypeNameENS_10DeviceTypeEb
indicates a mismatch between the MMCV library and your PyTorch installation. This typically occurs when MMCV is compiled against a different version of PyTorch or CUDA than what is currently installed in your environment.
Here's a breakdown of the issue and steps to resolve it:
Root Cause Analysis
Version Incompatibility:
MMCV and PyTorch versions must be compatible. The error suggests that mmcv-full==1.7.1 may not be compatible with PyTorch 1.12.1.
The symbol _ZN3c1014DeviceTypeNameENS_10DeviceTypeEb is related to PyTorch's C++ backend and indicates that MMCV was likely compiled against a different version of PyTorch than what's installed.
CUDA Compatibility:
MMCV must also be compatible with the installed CUDA version. You're using CUDA 11.3, so MMCV should be built against this version.
Solution Steps
1. Update MMCV to a Compatible Version
Ensure that the MMCV version aligns with your PyTorch and CUDA versions.
PyTorch 1.12.1 is compatible with MMCV 1.8.0 or higher.
Modify Your Dockerfile as Follows:
Replace the line that installs MMCV:
dockerfile
conda run -p /opt/conda/envs/isuor mim install mmcv-full==1.7.1
With:
dockerfile
conda run -p /opt/conda/envs/isuor mim install mmcv-full==1.8.0
Alternatively, for better compatibility and to leverage pre-built binaries optimized for your setup, use pip to install MMCV:
dockerfile
RUN conda run -p /opt/conda/envs/isuor pip install mmcv-full==1.8.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.12.1/index.html
2. Ensure Compatibility with MMDetection
MMDetection relies on a specific range of MMCV versions. Make sure that the MMCV version you're installing is compatible with the specific commit of MMDetection you're using (94afcdc).
Recommendation: Update MMDetection to a more recent commit or release that is compatible with MMCV 1.8.0.
Adjust the MMDetection Installation:
dockerfile
# Install MMDetection from source
RUN git clone https://github.com/open-mmlab/mmdetection.git /mmdet && \
cd /mmdet && \
git checkout 94afcdc && \ # Consider updating to a newer commit if possible
pip install -v -e .
Avoid Hardcoding Versions: Where possible, allow tools like mamba or pip to resolve compatible versions unless a specific version is required.
Use Environment Files Effectively: Consider specifying all dependencies, including MMCV and MMDetection, within your conda_env.yml to maintain consistency.
Clean Up Intermediate Files: Ensure that any temporary files or caches are cleaned up to keep the Docker image size minimal.
Updated Dockerfile Snippet
Here's how the relevant section of your Dockerfile should look after modifications:
dockerfile
# Update conda, set channel priority to strict, and install mamba
RUN conda update -n base -c defaults conda -y && \
conda config --set channel_priority flexible && \
conda install -n base -c conda-forge mamba -y
# Copy your conda environment file
COPY conda_env.yml /tmp/conda_env.yml
# Create Conda environment with mamba
RUN mamba env create -f /tmp/conda_env.yml -p /opt/conda/envs/isuor && \
conda clean -afy && \
conda env list
# Set environment variables to use the new environment
ENV CONDA_DEFAULT_ENV=isuor
ENV PATH="$CONDA_DIR/envs/isuor/bin:$PATH"
# Initialize conda
RUN conda init bash
RUN conda run -p /opt/conda/envs/isuor pip install openmim && \
pip install mmcv-full==1.8.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.12.1/index.html
# Verify that mmcv and torch are correctly installed
RUN python -c "import torch; import mmcv; print(torch.__version__); print(mmcv.__version__)"
# Proceed with the rest of your installations
# ...
Updated conda_env.yml
Ensure your conda_env.yml includes all necessary dependencies. Here's an updated version incorporating best practices:
yaml
name: isuor_face
channels:
- defaults
- pytorch
- conda-forge
dependencies:
- python=3.9
- numpy=1.21.2
- pytorch=1.12.1
- torchvision=0.13.1
- torchaudio=0.12.1
- cudatoolkit=11.3
- tqdm=4.64.1
- pyyaml=6.0
- matplotlib=3.5.3
- h5py=3.7.0
- scikit-learn=1.1.3
- pandas=1.4.4
- cython=0.29.32
- ipython=8.6.0
- ffmpeg=4.2.2
- tensorboard
- lap # Ensure 'lap' is available in the specified channels
- pip # Include pip without specifying the version
- pip:
- opencv-python==4.6.0.66
- openmim==0.3.5
- timm==0.6.12
Note: Ensure that the lap package is available in the specified channels. If not, you may need to find an alternative source or remove it if it's not critical.
Conclusion
The ImportError you're experiencing is due to a version mismatch between MMCV and PyTorch. By updating MMCV to a version compatible with your PyTorch and CUDA installations, you should be able to resolve this issue. Always ensure that all components in your stack are compatible to prevent such runtime errors.
If you continue to face issues after these changes, consider the following:
Check Other Dependencies: Ensure that all other packages are compatible with the updated versions of MMCV and PyTorch.
Review Patch Files: Ensure that any custom patches or modifications (like patch/hooks_memory.py) are compatible with the updated libraries.
Consult Documentation: Refer to the official MMCV and MMDetection documentation for version compatibility and installation guidelines.
Feel free to reach out if you encounter further issues!