AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.8k stars 7.96k forks source link

Did anyone manage to have opencv working on Archlinux or derivatives? #4622

Closed vfbsilva closed 4 years ago

vfbsilva commented 4 years ago

I stumble always in the following error:

/usr/bin/ld: warning: libIlmImf-2_3.so.24, needed by /opt/opencv3/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::InputFile::InputFile(char const*, int)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::OutputFile::setFrameBuffer(Imf_2_3::FrameBuffer const&)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::FrameBuffer::insert(char const*, Imf_2_3::Slice const&)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Header::channels()'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::chromaticities(Imf_2_3::Header const&)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::OutputFile::OutputFile(char const*, Imf_2_3::Header const&, int)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::FrameBuffer::begin()'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Header::Header(int, int, float, Imath_2_3::Vec2<float> const&, float, Imf_2_3::LineOrder, Imf_2_3::Compression)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Channel::Channel(Imf_2_3::PixelType, int, int, bool)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Header::channels() const'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::InputFile::setFrameBuffer(Imf_2_3::FrameBuffer const&)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::FrameBuffer::end()'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::InputFile::header() const'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Header::~Header()'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::InputFile::readPixels(int, int)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::globalThreadCount()'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Header::dataWindow() const'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::ChannelList::findChannel(char const*) const'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::OutputFile::~OutputFile()'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Slice::Slice(Imf_2_3::PixelType, char*, unsigned long, unsigned long, int, int, double, bool, bool)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::Chromaticities::Chromaticities(Imath_2_3::Vec2<float> const&, Imath_2_3::Vec2<float> const&, Imath_2_3::Vec2<float> const&, Imath_2_3::Vec2<float> const&)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::OutputFile::writePixels(int)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::ChannelList::insert(char const*, Imf_2_3::Channel const&)'
/usr/bin/ld: /opt/opencv3/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_3::hasChromaticities(Imf_2_3::Header const&)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:153: darknet] Error 1
phunc20 commented 4 years ago

Hello @vfbsilva, which kind of machine did you use for compiling darknet? I succeeded in thinkpad x200 (which is a 64-bit machine) and failed with the same error message as yours in thinkpad x60 (which is a 32-bit machine.) Besides, did you pacman -S opencv? I mean, did you compile opencv from source or install from pacman? (my x60 is parabola and x200 arch linux)

vfbsilva commented 4 years ago

I did install from pacman. The machine is 64 bits.

phunc20 commented 4 years ago

Ok, let me find some time writing my own experience on this. I just noticed there is one difference: I pacman installed opencv too, but my paths are always opencv4, unlike yours (opencv3). Anyway, I might as well help others if I managed to share.

vfbsilva commented 4 years ago

@phunc20 thanks a lot. I've found a work around with docker. But It does involve creating my own image so I can load my weighs and then run it as: docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --runtime=nvidia --rm -v $PWD:/workspace -w /workspace daisukekobayashi/darknet:gpu-cv darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -i 0 -thresh 0.25 'Yourvideo.mp4'

Basically you need to append the files you want to run on the following makefile:

ARG BASE_IMAGE=nvidia/cuda:10.0-cudnn7-devel
FROM $BASE_IMAGE
LABEL maintainer="Daisuke Kobayashi <daisuke@daisukekobayashi.com>"

ENV DEBIAN_FRONTEND noninteractive

ARG ADDITIONAL_PACKAGES=""

RUN apt-get update \
      && apt-get install --no-install-recommends --no-install-suggests -y gnupg2 ca-certificates \
            git build-essential $ADDITIONAL_PACKAGES \
      && rm -rf /var/lib/apt/lists/*

COPY configure.sh /tmp/

ARG SOURCE_BRANCH=unspecified
ENV SOURCE_BRANCH $SOURCE_BRANCH

ARG SOURCE_COMMIT=unspecified
ENV SOURCE_COMMIT $SOURCE_COMMIT

ARG CONFIG

RUN git clone https://github.com/AlexeyAB/darknet.git && cd darknet \
      && git checkout $SOURCE_BRANCH \
      && git reset --hard $SOURCE_COMMIT \
      && /tmp/configure.sh $CONFIG && make \
      && cp darknet /usr/local/bin \
      && cd .. && rm -rf darknet

And from my understanding to train under this setup I need volumes so I can persist the trained files which is again a new level of complexity.

phunc20 commented 4 years ago

Thanks, I haven't tried with docker, but I think I'll follow your instructions next time I wanted to use opencv with darknet.

Basically, I just sudo pacman -S opencv, and then follow this link to modify two files in the darknet repo. (I used only pjreddie's github repo only, not AlexeyAB's.) Once the files modified, you can start to compile (either make or make clean all). Back when I compiled, I still met some error messages, but those eventually turned out being able to be solved simply by installing more packages from, e.g. in my case, sudo pacman -S qt5 hdf5 vtk glew. Sorry for not being spontaneously enough, because i/ I was kind of busy these days; ii/ I experimented once more on my parabola thinkpad x201 (which unfortunately failed and which made me wonder if on parabola one need some extra effort to make it work.) If my memory serves me well, this is all that I did to make it work on my x200; otherwise, one might need to make one or two symlink, but I think my memory is correct and that's all one needs to do.

AlexeyAB commented 4 years ago

@vfbsilva

It seems that there is an issue in Archlinx+OpenCV+OPENEXR

I found your issue: https://forum.manjaro.org/t/undefined-references-to-libimf-in-opencv/112184/4

Possible solution: try to build OpenCV with cmake -DBUILD_OPENEXR=OFF -WITH_OPENEXR=OFF

do you actually need openexr support (floating point images, HDR and such) ?

it seems, some dependancies of the 3rdparty openexr module have the wrong version.

you could disable it with

cmake -DBUILD_OPENEXR=OFF -WITH_OPENEXR=OFF

vfbsilva commented 4 years ago

I can't compile OpenCV on Manjaro (arch derivative). I don't use pacman on my install I've tried both aur and source. Yes I've looked for that before but I might be setting this options wrongly. Whats the right way to do it? @acxz does it help?

AlexeyAB commented 4 years ago

@vfbsilva What command did you use for training OpenCV from source?

Did you add these flags to cmake command? -DBUILD_OPENEXR=OFF -WITH_OPENEXR=OFF

vfbsilva commented 4 years ago

I did not compile opencv from source. I've tried https://github.com/acxz/pkgbuilds/blob/master/darknet-alexeyab-git/PKGBUILD

I did try to add those flags. Maybe I did it wrongly. I added: set (CMAKE_CXX_FLAGS " -DBUILD_OPENEXR=OFF -WITH_OPENEXR=OFF") to the makefile

acxz commented 4 years ago

I have managed to get darknet working on ArchLinux using the AUR package, darknet-alexeyab-git. I had to use opencv, openexr, and ilmbase compiled with gcc8 however. See https://aur.archlinux.org/packages/darknet-alexeyab-git/#pinned-736206 for more information.

Note: the AUR does not support Manjaro, and by extension I also do not. However, maybe what works on ArchLinux might also work for you. I highly recommend using ArchLinux or a proper Arch-Repo compatible distro like EndeavourOS, instead of an Arch-Repo incompatible distro like Manjaro, which comes with its own set of issues.

vfbsilva commented 4 years ago

@acxz Do you use KDE? Cause I do and the removal of the packages you suggests breaks among other things KDE libs.


LC_ALL=en_US sudo pacman -Rns opencv openexr
[sudo] password for vfbsilva: 
checking dependencies...
error: failed to prepare transaction (could not satisfy dependencies)
:: removing openexr breaks dependency 'openexr' required by freeimage
:: removing openexr breaks dependency 'openexr' required by gegl
:: removing openexr breaks dependency 'openexr' required by gimp
:: removing openexr breaks dependency 'openexr' required by gst-plugins-bad
:: removing openexr breaks dependency 'openexr' required by kdelibs
:: removing openexr breaks dependency 'openexr' required by kimageformats
:: removing openexr breaks dependency 'openexr' required by kio-extras
:: removing openexr breaks dependency 'openexr' required by krita
:: removing opencv breaks dependency 'opencv=4.2.0' required by opencv-samples
vfbsilva@mordor ~/Downloads/pacotes $ 

I can switch to endeavour or arch but I wanna be sure of that would be a real fix in my case.

acxz commented 4 years ago

I do not use KDE.

I would recommend switching to EndeavourOS in any case.

I have updated the instructions, that do not involve uninstalling. https://aur.archlinux.org/packages/darknet-alexeyab-git/#pinned-736206

vfbsilva commented 4 years ago

@acxz updated instructions fixed the issue I'm closing it as a solution was provided.