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: <ROOT>/SparseTrack/tracker/pbcvt.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN2cv9videostab23MotionEstimatorRansacL2C1ENS0_11MotionModelE #2

Closed
Mittag-tech opened this issue Jun 20, 2023 · 4 comments

Comments

@Mittag-tech
Copy link

Overview

  • I want to run CUDA_VISIBLE_DEVICES=0 python3 track.py --num-gpus 1 --config-file mot17_track_cfg.py in docker.
  • Pyboostcvconverter can make in docker and can create pbcvt.xxx.so, copy to <ROOT>/SparseTrack/tracker/.
  • But, code occured ImportError. Please tell me the reason why error occured and the methods to avoid the error.

Code

Dockerfile

FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu20.04
# use an older system (18.04) to avoid opencv incompatibility (issue#3524)

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
	ca-certificates ninja-build python3-dev git wget sudo
RUN apt-get update && apt-get install -y python3-opencv
RUN apt-get update && apt-get install -y cmake cmake-gui libopencv-dev \
	libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev libboost-python-dev
RUN ln -sv /usr/bin/python3 /usr/bin/python

# create a non-root user
ARG USER_ID=1000
RUN useradd -m --no-log-init --system  --uid ${USER_ID} appuser -g sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER appuser
WORKDIR /home/appuser

ENV PATH="/home/appuser/.local/bin:${PATH}"
RUN wget https://bootstrap.pypa.io/pip/3.6/get-pip.py && \
	python3 get-pip.py --user && \
	rm get-pip.py

# install dependencies
# See https://pytorch.org/ for other options if you use a different version of CUDA
RUN pip install --user tensorboard cmake onnx   # cmake from apt-get is too old
RUN pip install --user torch==1.10 torchvision==0.11.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html

RUN pip install --user 'git+https://github.com/facebookresearch/fvcore'
# install detectron2
RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
# set FORCE_CUDA because during `docker build` cuda is not accessible
ENV FORCE_CUDA="1"
# This will by default build detectron2 for all common cuda architectures and take a lot more time,
# because inside `docker build`, there is no way to tell which architecture will be used.
ARG TORCH_CUDA_ARCH_LIST="Kepler;Kepler+Tesla;Maxwell;Maxwell+Tegra;Pascal;Volta;Turing"
ENV TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}"

RUN pip install --user -e detectron2_repo

# Set a fixed model cache directory.
ENV FVCORE_CACHE="/tmp"
WORKDIR /home/appuser/

Directory tree

<ROOT>
├── SparseTrack
│   ├── TrackEval
│   ├── assets
│   ├── datasets
│   ├── models
│   ├── tools
│   ├── tracker
│   ├── utils
│   └── ~
├── datasets
│   └── MOT17
├── docker
└── pyboostcvconverter
    ├── CMakeFiles
    ├── cmake
    ├── include
    ├── src
    └── tests
@Xavier-Lin
Copy link
Member

Xavier-Lin commented Jun 20, 2023

Do you have compiled OpenCV C++ and Boost ?

@Mittag-tech
Copy link
Author

Mittag-tech commented Jun 21, 2023

Thank you for your response, @Xavier-Lin .

Maybe it's done.
I'm thinking that if I compile pbcvt, it also compiles OpenCV C++ and Boost, is this correct?

If my idea is wrong, could you tell me how to compile OpenCV C++ and Boost?

@Xavier-Lin
Copy link
Member

Xavier-Lin commented Jun 22, 2023

Thank you very much for your feedback, @Mittag-tech.

My approach is to first compile OpenCV C++ (4.6.X) and Boost (1.73.X). Then, I download the pbcvt project and copy the python_module.cpp file to the pbcvt/src/ directory. Next, I compile pbcvt and copy the generated .so file to the Path/to/your/root/SparseTrack/tracker/ directory. There are 3 issues to note during the compilation of pbcvt:

  1. If you meet a bug as: '/lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined symbol: ffi_type_uint32, version LIBFFI_BASE_7.0' , please add export or add export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libffi.so.7 to .bashrc and then update .bashrc.

  2. It is as much as possible to modify the compilation path in the Makefile file before compiling pbcvt.

  3. Before compiling pbcvt (assuming you have already completed the installation of OpenCV C++ and Boost), you need to add the relevant OpenCV modules in the pbcvt/CMakeLists.txt file. Here's what you should do: locate the line "find_package(OpenCV COMPONENTS REQUIRED)" in the CMakeLists.txt file and replace it with "find_package(OpenCV COMPONENTS core highgui video videoio videostab REQUIRED)".

I hope the details above can help you.

@Mittag-tech
Copy link
Author

Thank you for your advice, @Xavier-Lin .
I was able to run your code on docker!

For those who have the same problem, I note the sammrize of solution with docker.

Dockerfile based on detectron2

FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu20.04
# use an older system (18.04) to avoid opencv incompatibility (issue#3524)

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
	ca-certificates ninja-build python3-dev git wget sudo
RUN apt-get update && apt-get install -y python3-opencv
RUN apt-get update && apt-get install -y cmake cmake-gui libopencv-dev \
	libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev libboost-python-dev
RUN apt update && apt install -y libopencv-dev g++
RUN ln -sv /usr/bin/python3 /usr/bin/python

# create a non-root user
ARG USER_ID=1000
RUN useradd -m --no-log-init --system  --uid ${USER_ID} appuser -g sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER appuser
WORKDIR /home/appuser

ENV PATH="/home/appuser/.local/bin:${PATH}"
RUN wget https://bootstrap.pypa.io/pip/3.6/get-pip.py && \
	python3 get-pip.py --user && \
	rm get-pip.py

# install dependencies
# See https://pytorch.org/ for other options if you use a different version of CUDA
RUN pip install --user tensorboard cmake onnx   # cmake from apt-get is too old
RUN pip install --user torch==1.10 torchvision==0.11.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html

RUN pip install --user 'git+https://github.com/facebookresearch/fvcore'
# install detectron2
RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
# set FORCE_CUDA because during `docker build` cuda is not accessible
ENV FORCE_CUDA="1"
# This will by default build detectron2 for all common cuda architectures and take a lot more time,
# because inside `docker build`, there is no way to tell which architecture will be used.
ARG TORCH_CUDA_ARCH_LIST="Kepler;Kepler+Tesla;Maxwell;Maxwell+Tegra;Pascal;Volta;Turing"
ENV TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}"

RUN pip install --user -e detectron2_repo
RUN pip install --user opencv-python boost numpy==1.23.4

# Set a fixed model cache directory.
ENV FVCORE_CACHE="/tmp"
WORKDIR /home/appuser/

# run detectron2 under user "appuser":
# wget http://images.cocodataset.org/val2017/000000439715.jpg -O input.jpg
# python3 demo/demo.py  \
	#--config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
	#--input input.jpg --output outputs/ \
	#--opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

pyboostcvconverter/CMakeLists.txt

Replace line 32 with the following.

find_package(OpenCV COMPONENTS core highgui video videoio videostab REQUIRED)

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

2 participants