> For the complete documentation index, see [llms.txt](https://cifar.gitbook.io/note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cifar.gitbook.io/note/fu-wu/gong-zuo-yun-wei.md).

# 工作运维

### 工作约定

* **【重点】**&#x4E3A;确保SDK推理结果和原始模型结果一致，模型训练、测试、SDK开发与应用时，图片读取/变换工具禁用PIL/Pillow，均使用OpenCV，版本不限，但其依赖libjpeg版本必须为v62，查看方法如下：
  * C++: ldd /path/to/libopencv\_highgui.so | grep jpeg，结果为libjpeg.so.62或 libjpeg-turbo.so.xxx.62
  * Python: print(cv2.getBuildInformation())，结果为JPEG: libjpeg-turbo (ver x.x.x-62)
* **代码风格遵循**[**Google 开源项目风格指南 (中文版)**](https://zh-google-styleguide.readthedocs.io/en/latest/)
  * [c++](https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/)
  * [Python](https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/)
  * [Shell](https://zh-google-styleguide.readthedocs.io/en/latest/google-shell-styleguide/)
  * [Json](https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md)
* **版本号**
  * 算法模型以日期为版本号
  * SDK/应用程序版本以3位表示，格式：libname.so.MajorVerion.MinorVersion.ModelVersion，如libface.so.1.1.20201203。接口变动的修改，更改大版本号MajorVerion；接口未变动的修改，修改小版本号MinorVersion；模型变更需修改ModelVersion。每次修改都需更改版本号。
* **工具规范**
  * 文本编辑器：Notepad++/Sublime
  * 代码编辑器：VSCode/PyCharm/Visual Studio
  * 笔记：飞书云文档
  * 任务管理：飞书-板栗看板
  * 命令行工具：XShell
  * 桌面远程：向日葵
  * 图片浏览器：[Honeyview](https://www.bandisoft.com/honeyview/)
  * 视频模仿器：Potplayer/VLC
* **SDK开发、工程应用等开发环境**
  * docker pull registry.cn-beijing.aliyuncs.com/rmzk-pubilc/rd\_dev\_centos7.7-cuda10.2-trt7.0.0.11:20210422（外网）
  * docker pull registry-vpc.cn-beijing.aliyuncs.com/rmzk-pubilc/rd\_dev\_centos7.7-cuda10.2-trt7.0.0.11:20210422（内网）
  * OpenCV CMake链接opencv（静态库+jpeg v62动态库）：
  * libopencv\_imgcodecs.a libopencv\_imgproc.a libopencv\_core.a libIlmImf.a libade.a libittnotify.a libquirc.a liblibprotobuf.a liblibjasper.a liblibpng.a liblibtiff.a liblibwebp.a libz.a jpeg
* **SAAS部署基础环境**
  * docker pull registry-vpc.cn-beijing.aliyuncs.com/rmzk-pubilc/rd\_saas\_runtime:20210311

### 工作效率

* 能用内网ip通信，不用外网ip通信
* 网络传输大量小文件时，先打包，再传输
* [VS Code远程连接服务器，调试python代码的方法](https://cifar.gitbook.io/link-ed/)
* [四个VSCode插件可以大幅提升Python开发效率](https://blog.csdn.net/weixin_42731853/article/details/109174860)：Python Type Hint、Pylance、Python Docstring Generator、Better Comments
* 代码管理
  * 学习工具：[Learn Git Branching](https://learngitbranching.js.org/?NODEMO=\&locale=zh_CN)
* Conda安装加速：conda install xxxx -c <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/>
* Pip安装加速

  * pip install xxxx -i <https://pypi.tuna.tsinghua.edu.cn/simple>
  * pip install xxxx -i <http://mirrors.aliyun.com/pypi/simple/>

### **21服务器训练环境**

**使用原则**

21服务器配置8块3090显卡，性能强大，但是/home目录和/目录空间很小，请大家遵循以下原则使用服务器。

* 为了更好的同步环境和方便使用，使用docker部署和管理训练和测试等环境
* 不在/home和 / 目录下存放大量数据和代码，以免空间占用；
* 将数据和代码存放在/data目录（7.3T空间），每个账号下会有个软链接data指向/data，如未有该目录请联系运维武春雨建立该目录；
* 如切实需要在宿主机搭建python环境，避免使用anaconda，推荐使用miniconda，注意不要安装于默认路径`/home/账户名`下，更改到`/data/账户名`下

**docker部署训练环境指南**

***镜像说明***

21服务器上训练基础docker镜像已经完成，输入`docker images`即可看到 `pytorch:1.8`

* 该镜像系统为Ubuntu 18.04，包含cuda11.1【3090显卡计算能力sm86，cuda10.2最高支持sm70】
* 已安装常用包：vim，git，htop，tmux，screen，openssh-server等
* 镜像中已经安装miniconda，路径`/root/miniconda3`，方便多python环境管理
* base环境下已安装以下常用python包：pytorch1.8+cu111，torchvision==0.9.1+cu111，python-opencv等
* apt、pip、conda均已更换为清华源

***部署步骤***

* 使用以下命令完成容器的创建

> nvidia-docker run -dit --gpus all --name=指定容器名 --shm-size 8G -p 指定映射端口号:22 -v /data/账户名:/workspace pytorch:1.8

* 其中：--name是容器名称，需自行定义
* \--shm-size是docker共享内存大小，不指定会影响pytorch下数据加载，num\_workers只能设为0才可正常运行；实测指定8G，num\_workers为16，batch\_size为256可以正常运行
* -p 为容易映射端口号，22端口的映射方便vs code连接远程调试，需自行指定
* -v 为目录映射，格式为：宿主机目录：容器目录，推荐直接映射/data/账户名目录到容器内
* 进入容器内部命令：`docker exec -it CONTAINER /bin/bash`

***VS Code连接***

* Vs code 远程连接请先进入容器：执行`/etc/init.d/ssh start` 开启ssh server
* 配置root账户密码
* VS code remote 连接配置

```json
Host 自定义连接名称
  HostName 192.168.3.21
      User root
      Port 映射端口号
```
