- 一、安装显卡
- 二、安装docker
- 2.1、设置存储库
- 2.2、安装 Docker 引擎
- 2.3、验证 Docker Engine 是否已正确安装。
- 三、安装nvidia docker
- 四、拉取Deepstream镜像
- 4.1、拉取镜像:
- 4.2、docker空间不足解决办法
- 4.3、启动deepstream的docker容器:
- 五、 docker中deepstream的使用
- 六、Yolov5在deepstream中的部署
- 6.1、将预训练的图像分割 PyTorch 模型转换为 ONNX。
- 6.2、将 onNX 模型导入 TensorRT。
- 6.3、应用优化并生成引擎。
- 6.4、在 GPU 上执行推理。
安装过程见我另外一篇博客:
验证是否安装成功,输入命令
nvidia-smi
若出现下图则表示安装成功:
二、安装dockerdocker的安装过程最好请参考官方地址:https://docs.docker.com/engine/install/ubuntu/
这里的docker指的是docker-ce(docker社区版本),采用基于仓库的方式进行安装。
2.1、设置存储库更新apt包索引并安装包以允许apt通过 HTTPS 使用存储库:
- 更新软件源
sudo apt-get update
sudo apt-get install
ca-certificates
curl
gnupg
lsb-release
- 添加Docker官方的GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- 使用以下命令设置稳定存储库。要添加 夜间或测试存储库,请在以下命令中的单词后添加单词nightly或test(或两者)stable。了解nightly和test频道。
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null2.2、安装 Docker 引擎
更新apt包索引,安装最新版本的Docker Engine和containerd,或者到下一步安装特定版本:
sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io2.3、验证 Docker Engine 是否已正确安装。
sudo docker run hello-world
如下说明安装成功:
aaaaa@aaaa:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
至此,docker已安装完成。可以通过sudo docker version命令查看所安装docker的版本。如下图所示
sudo docker version
可以看出所安装docker的版本为20.10
nvidia docker的安装参考https://github.com/NVIDIA/nvidia-docker
NVIDIA Container Toolkit 允许用户构建和运行 GPU 加速的 Docker 容器。该工具包包括一个容器运行时库和实用程序,用于自动配置容器以利用 NVIDIA GPU。
确保您已经为您的 Linux 发行版安装了NVIDIA 驱动程序和 Docker 引擎 注意,您不需要在主机系统上安装 CUDA Toolkit,但需要安装 NVIDIA 驱动程序。(我们的第一第二步已经做到)
设置 Docker
Ubuntu 上的 Docker-CE 可以使用 Docker 的官方便利脚本进行设置:
curl https://get.docker.com | sh && sudo systemctl --now enable docker
设置 NVIDIA 容器工具包
设置stable存储库和 GPG 密钥:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
配置日志:可能出现 gpg: 找不到有效的 OpenPGP 数据,解决方法如下:
wget https://download.docker.com/linux/ubuntu/gpg sudo apt-key add gpg
参考:https://blog.csdn.net/bean_business/article/details/112278504
jiang@jiang-ThinkStation-P520:~$ jiang@jiang-ThinkStation-P520:~$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) > && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - > && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list gpg: 找不到有效的 OpenPGP 数据。 jiang@jiang-ThinkStation-P520:~$ jiang@jiang-ThinkStation-P520:~$ jiang@jiang-ThinkStation-P520:~$ jiang@jiang-ThinkStation-P520:~$ wget https://download.docker.com/linux/ubuntu/gpg --2021-11-24 17:20:33-- https://download.docker.com/linux/ubuntu/gpg 正在解析主机 download.docker.com (download.docker.com)... 99.84.206.7, 99.84.206.109, 99.84.206.25, ... 正在连接 download.docker.com (download.docker.com)|99.84.206.7|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度: 3817 (3.7K) [binary/octet-stream] 正在保存至: “gpg” gpg 100%[=======================================================>] 3.73K --.-KB/s 用时 0s 2021-11-24 17:20:49 (228 MB/s) - 已保存 “gpg” [3817/3817]) jiang@jiang-ThinkStation-P520:~$ sudo apt-key add gpg OK jiang@jiang-ThinkStation-P520:~$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list OK deb https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/$(ARCH) / #deb https://nvidia.github.io/libnvidia-container/experimental/ubuntu18.04/$(ARCH) / deb https://nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/$(ARCH) / #deb https://nvidia.github.io/nvidia-container-runtime/experimental/ubuntu18.04/$(ARCH) / deb https://nvidia.github.io/nvidia-docker/ubuntu18.04/$(ARCH) /
nvidia-docker2更新包列表后安装包(和依赖项):
sudo apt-get update sudo apt-get install -y nvidia-docker2
设置好默认运行后重启Docker守护进程完成安装:
sudo systemctl restart docker
此时,可以通过运行基本 CUDA 容器来测试工作设置:
sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi四、拉取Deepstream镜像
官方地址:
1、https://catalog.ngc.nvidia.com/orgs/nvidia/containers/deepstream
2、https://docs.nvidia.com/metropolis/deepstream/5.0/dev-guide/index.html#page/DeepStream_Development_Guide/deepstream_plugin_docker.html#wwpID0EYHA
4.1、拉取镜像:docker pull nvcr.io/nvidia/deepstream:5.0-20.07-devel
可能会出现如下问题:空间不足
failed to register layer: Error processing tar file(exit status 1): write /usr/lib/x86_64-linux-gnu/libicutu.a: no space left on device
用了下面的解决办法,还是不行
https://www.jianshu.com/p/8239d32f19e6
原因: 通常docker默认安装在/var/lib/docker,也就是在根目录下,而通常根分区不会很大,docker占用了大量空间,有时的确会导致磁盘不够用。
于是找到docker环境的存储地址,查看了剩余空间,发现在没有docker pull 的时候,空间还有5G,但是在pull安装解压的过程中,空间会变为0.最后出错,因此再怎么清理垃圾也是没有用的。
排查问题:
1.检查 /var/lib/docker 所在目录的空间是否足够,假使因为这个原因,只要将/var/lib/docker 挂载到较大的磁盘下就行,重启服务即可。
2.可能是新版的docker base Device Size默认只有10G,而你pull的image在解压的过程中所需的空间超过了这个size
原文链接:https://blog.csdn.net/u013641234/article/details/95202596
我使用了挂载方式:
先停掉docker服务
sudo service docker stop
挂载
sudo mount -o bind /home/jiang/docker_diyun2 /var/lib/docker
重启docker服务
sudo service docker start
最终成功。
安装的日志
4.3、启动deepstream的docker容器:jiang@jiang-ThinkStation-P520:~$ sudo service docker stop
jiang@jiang-ThinkStation-P520:~$
jiang@jiang-ThinkStation-P520:~$
jiang@jiang-ThinkStation-P520:~$ sudo mount -o bind /home/jiang/docker_diyun2 /var/lib/docker
jiang@jiang-ThinkStation-P520:~$ sudo service docker start
jiang@jiang-ThinkStation-P520:~$ sudo docker pull nvcr.io/nvidia/deepstream:5.0-20.07-devel
5.0-20.07-devel: Pulling from nvidia/deepstream
7ddbc47eeb70: Pull complete
c1bbdc448b72: Pull complete
8c3b70e39044: Pull complete
45d437916d57: Pull complete
d8f1569ddae6: Pull complete
902fc5ce8229: Pull complete
ae1bb79c5cfc: Pull complete
fa6605c8fe7a: Pull complete
0508a679d339: Pull complete
569964daa9b3: Pull complete
e013d8934c2e: Pull complete
dfe43e9df471: Pull complete
5e6c9b9d746f: Pull complete
1d445ebc7a6a: Pull complete
f1f96518021c: Pull complete
fb8f309be79c: Pull complete
f8747b771ab7: Pull complete
a16597b9336c: Pull complete
557841bbb4a3: Pull complete
8c2f02e0a901: Pull complete
f06185b90e37: Pull complete
4b7f14893d39: Pull complete
30a04cdf5f52: Pull complete
Digest: sha256:6c8eed19144ed1318ecc40c946ed87d06ce4fc72a7379b8e8849decda681eced
Status: Downloaded newer image for nvcr.io/nvidia/deepstream:5.0-20.07-devel
nvcr.io/nvidia/deepstream:5.0-20.07-devel
jiang@jiang-ThinkStation-P520:~$
sudo docker run --gpus '"'device=0'"' -it --rm -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -w /opt/nvidia/deepstream/deepstream-5.0 nvcr.io/nvidia/deepstream:5.0-20.07-devel
进入到容器内部:
可以看到deepstream的内容了,后续继续探索。
参考:https://blog.csdn.net/qq_41987977/article/details/105994564
rtsp流地址
rtsp://admin:123456789bit@172.23.0.44/1六、Yolov5在deepstream中的部署 6.1、将预训练的图像分割 PyTorch 模型转换为 ONNX。 6.2、将 onNX 模型导入 TensorRT。 6.3、应用优化并生成引擎。 6.4、在 GPU 上执行推理。



