Meshroom
Meshroom copied to clipboard
[bug] Calling meshroom through python subprocess in Docker fails
Describe the bug
While calling meshroom through Python subprocess in a FastAPI app in a docker container, the meshroom_batch
command throws an exception and doesn't work. There is no issue in running the exact same command inside the docker container's bash shell. That runs perfectly without any issue. I also don't face this issue when using the same code outside of Docker.
To Reproduce Steps to reproduce the behavior:
- The Dockerfile I am trying looks similar to this:
FROM nvidia/cuda:11.4.1-runtime-ubuntu20.04
ARG DEBIAN_FRONTEND=noninteractive
ENV PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
ENV CUDA_HOME=/usr/local/cuda
RUN apt-get update
RUN apt-get install -y \
# Install build tools
build-essential \
cmake \
git \
wget \
unzip \
yasm \
pkg-config
RUN apt-get install -y \
# Install build tools, build dependencies and python
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libavformat-dev \
libpq-dev \
libxine2-dev \
libglew-dev \
libtiff5-dev \
zlib1g-dev \
libavcodec-dev \
libavutil-dev \
libpostproc-dev \
libswscale-dev \
libeigen3-dev \
libtbb-dev \
libgtk2.0-dev
RUN apt-get install -y \
# Install python
python3-dev \
python3-pip
RUN rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY ./requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
RUN wget \
--no-verbose --show-progress \
--progress=bar:force:noscroll \
https://github.com/alicevision/meshroom/releases/download/v2021.1.0/Meshroom-2021.1.0-linux-cuda10.tar.gz \
&& tar -xf Meshroom-2021.1.0-linux-cuda10.tar.gz \
&& rm Meshroom-2021.1.0-linux-cuda10.tar.gz
RUN mv Meshroom-2021.1.0-av2.4.0-centos7-cuda10.2 Meshroom-2021.1.0
ENV ALICEVISION_INSTALL=/app/Meshroom-2021.1.0/aliceVision
ENV PATH=$PATH:${ALICEVISION_INSTALL}/bin
ENV LD_LIBRARY_PATH=${ALICEVISION_INSTALL}/lib:$LD_LIBRARY_PATH
ENV ALICEVISION_SENSOR_DB=${ALICEVISION_INSTALL}/share/aliceVision/cameraSensors.db
ENV PYTHONPATH=$PWD
COPY ./code ./code
CMD ["uvicorn", "--host", "0.0.0.0", "halo_object_reconstruction.app:app"]
I build and spawn the docker container through docker compose with the relevant section being:
fastapi-app:
image: fastapi-app-image
container_name: fastapi-app
build: .
runtime: nvidia
restart: always
deploy:
resources:
reservations:
devices:
- capabilities:
- gpu
ports:
- "8000:8000"
volumes:
- ./data:/app/data
In the code, I am calling the subprocess like this:
process = subprocess.run(
[
'/app/Meshroom-2021.1.0/meshroom_batch',
'--input',
frames_directory_absolute_path,
'--output',
extracted_mesh_absolute_path,
'--cache',
meshroom_cache_absolute_path
],
check=True
)
Expected behavior The photogrammetry pipeline should run like it does when called from bash shell.
Screenshots N/A
Log
No image found
Traceback (most recent call last):
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/cx_Freeze/initscripts/__startup__.py", line 40, in run
File "/opt/Meshroom/setupInitScriptUnix.py", line 39, in run
File "bin/meshroom_batch", line 107, in <module>
NameError: name 'exit' is not defined
.
.
.
subprocess.CalledProcessError: Command '/app/data/meshroom_batch --input /app/data/frames --output /app/data/results --cache /app/data/cache' returned non-zero exit status 1.
Desktop (please complete the following and other pertinent information):
- OS: Ubuntu 20.04 (WSL2) and using the docker image specified above in that (also Ubuntu 20.04)
- Python version: 3.8
- Qt/PySide version: Not sure if applicable
- Meshroom version:
- Binary version: 2021.1.0
Additional context I understand that exit() was deprecated for sys.exit() in later versions. However, the issue is that it Meshroom is not able to locate images in the directory. I also don't understand the calls to python3.6 as can be seen in the logs. Running the exact same command as subprocess.run() in bash works perfectly though and I am able to get the 3D model I require.
Related question: Is there are better way to do this than how I am currently doing it?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.