dockerfiles: # Use base CUDA image
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04

# Update NVIDIA GPG key
RUN rm /etc/apt/sources.list.d/cuda.list && \
    apt-key del 7fa2af80 && \
    apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends wget && \
    wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb && \
    dpkg -i cuda-keyring_1.0-1_all.deb

# Preseed tzdata and install dependencies
RUN truncate -s0 /tmp/preseed.cfg && \
    echo "tzdata tzdata/Areas select Europe" >> /tmp/preseed.cfg && \
    echo "tzdata tzdata/Zones/Europe select Berlin" >> /tmp/preseed.cfg && \
    debconf-set-selections /tmp/preseed.cfg && \
    rm -f /etc/timezone /etc/localtime && \
    apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata sudo nano git ffmpeg libsm6 libxext6 && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install Miniconda
ENV CONDA_DIR=/opt/conda
ENV PATH="$CONDA_DIR/bin:$PATH"

RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
    /bin/bash ~/miniconda.sh -b -p $CONDA_DIR && \
    rm ~/miniconda.sh && \
    $CONDA_DIR/bin/conda clean -afy && \
    ln -s $CONDA_DIR/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    echo ". $CONDA_DIR/etc/profile.d/conda.sh" >> ~/.bashrc

# 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 && \
    conda run -p /opt/conda/envs/isuor mim install mmcv-full==1.7.1

# Verify that mim is installed
RUN ls /opt/conda/envs/isuor/bin/

# Activate the environment
ENV PATH /opt/conda/envs/isuor/bin:$PATH

# Install MMDetection from source
RUN git clone https://github.com/open-mmlab/mmdetection.git /mmdet && \
    cd /mmdet && \
    git checkout 94afcdc && \
    pip install -v -e .

# Install Monocular-Depth-Estimation-Toolbox from source
RUN git clone https://github.com/zhyever/Monocular-Depth-Estimation-Toolbox.git /mde_toolbox && \
    cd /mde_toolbox && \
    git checkout 7c0c89c && \
    pip install -v -e .

# Update PYTHONPATH and activate the environment in .bashrc for interactive sessions
RUN echo "export PYTHONPATH=/isuor/src:${PYTHONPATH}" >> ~/.bashrc && \
    echo "conda activate isuor" >> ~/.bashrc

# Verify that __init__.py exists
RUN ls -la /mde_toolbox/depth/
# 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 <module>
    from mmdet.apis import init_detector, inference_detector
  File "/mmdet/mmdet/apis/__init__.py", line 2, in <module>
    from .inference import (async_inference_detector, inference_detector,
  File "/mmdet/mmdet/apis/inference.py", line 8, in <module>
    from mmcv.ops import RoIPool
  File "/opt/conda/envs/isuor/lib/python3.9/site-packages/mmcv/ops/__init__.py", line 3, in <module>
    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 <module>
    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