menu

[2022-03-07 Mon 14:08]

深度学习开发机

Ubuntu 20.04.4 LTS

安装

没什么特殊的

一般配置

sshd

sudo apt install openssh-server

vnc

sudo apt install tigervnc-scraping-server

~/Writing/_notes/Computer/jetson.md

emacs

sudo add-apt-repository ppa:kelleyk/emacs
sudo apt update
sudo apt install emacs27

zsh

sudo apt install zsh curl
zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
omz theme set ys

jtmux

frpc

需要手动安装

nvidia driver

  • https://linuxize.com/post/how-to-nvidia-drivers-on-ubuntu-20-04/
  • [CUDA Toolkit 11.6 Update 1 Downloads | NVIDIA Developer](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network)
  • export PATH="/usr/local/cuda/bin:$PATH"

开发

pyright

conda install pyright

jupyter

sudo snap install node --classic
pip install jupyterlab
# 显示图片
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager
# 支持 pyplot
pip install ipympl
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib
# 支持头部折叠
pip install aquirdturtle_collapsible_headings

conda

  • 安装到 /opt/miniconda3
  • [Installing for multiple users — Anaconda documentation](https://docs.anaconda.com/anaconda/install/multi-user/)
  • [Installing on Linux — conda 4.11.0.post66+edb5737bd documentation](https://conda.io/projects/conda/en/latest/user-guide/install/linux.html#)
  • zsh 插件
git clone https://github.com/esc/conda-zsh-completion ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/conda-zsh-completion
omz plugin enable conda-zsh-completion

ffmpeg

https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu https://trac.ffmpeg.org/wiki/HWAccelIntro

sudo apt-get update -qq && sudo apt-get -y install \
autoconf \
automake \
build-essential \
cmake \
git-core \
libass-dev \
libfreetype6-dev \
libgnutls28-dev \
libmp3lame-dev \
libsdl2-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
meson \
ninja-build \
pkg-config \
texinfo \
wget \
yasm \
zlib1g-dev \
libunistring-dev \
nasm \
libx264-dev \
libx265-dev \
libnuma-dev \
libvpx-dev \
libfdk-aac-dev \
libopus-dev \
  • 编译 opencv 需要 enable-shared https://stackoverflow.com/questions/32785279/ffmpeg-doesnt-compile-with-shared-libraries
  • cmake 添加 libaom you need to add: “-DBUILD_SHARED_LIBS=1”
  • meson –default-library=shared

master 分支

PATH="$HOME/bin:$CUDA_DIR/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
    --prefix="$HOME/ffmpeg_build" \
    --pkg-config-flags="--static" \
    --extra-cflags="-I$HOME/ffmpeg_build/include" \
    --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
    --extra-libs="-lpthread -lm" \
    --ld="g++" \
    --bindir="$HOME/bin" \
    --enable-shared \
    --disable-static \
    --enable-gpl \
    --enable-gnutls \
    --enable-libaom \
    --enable-libass \
    --enable-libfdk-aac \
    --enable-libfreetype \
    --enable-libmp3lame \
    --enable-libopus \
    --enable-libsvtav1 \
    --enable-libdav1d \
    --enable-libvorbis \
    --enable-libvpx \
    --enable-libx264 \
    --enable-libx265 \
    --enable-nonfree \
    --enable-cuda-sdk \
    --enable-cuvid \
    --enable-nvenc \
    --enable-libnpp \
    --extra-cflags=-I"$CUDA_DIR/include" --extra-ldflags=-L"$CUDA_DIR/lib64" && \
    PATH="$HOME/bin:$CUDA_DIR/bin:$PATH" make -j $(nproc) && \
    make install && \
    hash -r

编译成动态库,需要告诉动态链接去哪里找包

通过环境变量:

export LD_LIBRARY_PATH=/home/lc/ffmpeg_build/lib

推荐用 ldconfig

编辑 sudo vi /etc/ld.so.conf.d/my_ffmpeg_.conf

/home/lc/ffmpeg_build/lib

再运行

sudo ldconfig

pkg-config 的作用? https://www.freedesktop.org/wiki/Software/pkg-config/

opencv

gui 支持 sudo apt install libgtk2.0-dev libcanberra-gtk-module libcanberra-gtk3-module

编译前需要先安装 numpy conda install numpy

参考

  • https://www.cnblogs.com/geoffreyone/p/14765124.html
  • https://dev.widemeadows.de/2017/08/23/building-opencv-for-anaconda-python-3/

最终能正确生成 cv2 的可用的 cmake TODO CMAKE_INSTALL_PREFIX 应该可放到 /usr/local/opencv 方便多个虚拟环境公用


cmake \
      -D INCLUDE_DIRS=${OPENCV_INCLUDE_DIR_ANACONDA} $INCLUDE_DIRS \
      -D LIBRARY_DIRS=$OPENCV_LIBRARY_ANACONDA $LIBRARY_DIRS \
      -D CMAKE_BUILD_TYPE=RELEASE \
      -D BUILD_PYTHON_SUPPORT=ON \
      -D BUILD_DOCS=ON \
      -D BUILD_PERF_TESTS=OFF \
      -D BUILD_TESTS=OFF \
      -D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_opencv_python3=ON \
      -D BUILD_opencv_python2=OFF \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D PYTHON_EXECUTABLE="/opt/miniconda3/envs/mmlab/bin/python3" \
      -D PYTHON3_EXECUTABLE="/opt/miniconda3/envs/mmlab/bin/python3" \
      -D PYTHON_LIBRARY="/opt/miniconda3/envs/mmlab/lib/libpython3.9.so" \
      -D PYTHON3_LIBRARY="/opt/miniconda3/envs/mmlab/lib/libpython3.9.so" \
      -D PYTHON3_INCLUDE_DIR="/opt/miniconda3/envs/mmlab/include/python3.9" \
      -D PYTHON3_INCLUDE_DIR2="/opt/miniconda3/envs/mmlab/include" \
      -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c "import numpy; print(numpy.get_include())") \
      -D PYTHON3_INCLUDE_PATH="/opt/miniconda3/envs/mmlab/include/python3.9" \
      -D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
      -D BUILD_EXAMPLES=ON \
      -D WITH_GTK=ON \
      -D WITH_GTK_2_X=ON \
      -D WITH_IPP=ON \
      -D BUILD_TIFF=ON \
      -D BUILD_opencv_cvv=OFF \
      -D INSTALL_CREATE_DISTRIB=ON \
      -D WITH_FFMPEG=ON \
      -D WITH_GSTREAMER=ON \
      -D WITH_V4L=ON \
      -D WITH_LIBV4L=ON \
      -D WITH_TBB=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D WITH_CUDA=ON \
      -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
      -D CMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs \
      -D CUDA_ARCH_BIN="7.5" \
      -D CUDA_ARCH_PTX="" \
      -D WITH_CUBLAS=ON \
      -D WITH_NVCUVID=ON \
      -D ENABLE_FAST_MATH=1 \
      -D CUDA_FAST_MATH=1 \
      -D ENABLE_PRECOMPILED_HEADERS=OFF \
      ..

做了这个改动,方便看 ffmpeg 的报错 https://github.com/opencv/opencv/issues/10217

ffmpeg build shared lib https://answers.opencv.org/question/229639/cmake-static-link-ffmpeg-for-build-shared-libraries/ Opencv build error: relocation R_X86_64_PC32 against symbol `ff_pw_9’ … recompile with -fPIC

mmpose

  • numpy=1.21.2=py39h20f2e39_0

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

  • pytorch==1.10.2
  • torchvision=0.11.3

    pip install openmim

    • openmim

      mim install mmcv-full # 会替换了 opencv 版本 mim install mmdet

mmcls 0.21.0 https://github.com/open-mmlab/mmclassification mmcv-full 1.4.6 https://github.com/open-mmlab/mmcv mmdet 2.22.0 https://github.com/open-mmlab/mmdetection mmpose 0.24.0 https://github.com/open-mmlab/mmpose mmtrack 0.11.0 https://github.com/open-mmlab/mmtracking

scikit-learn

keyboard_arrow_up