基于Darknet框架的YOLOv3算法开发的模型训练和部署的容器化产品

基于 Darknet 的容器化产品

  • 模型训练工程化 [darknet]
  • 模型部署服务器 [darknet-serving]

模型训练工程化 [darknet]

  1. 训练前的数据准备
    • 工程目录结构
    project/            # 工程根目录
    ├── cfg             # 配置目录
    │   └── voc.names   # 标签名
    ├── images          # 样本
    │   ├── ...
    │   └── ...
    ├── labels          # YOLO标注格式
    │   ├── ...
    │   └── ...
    └── test            # 训练完后用于测试(非必须)
    ├── ...
    └── ...
    
  • 举例:这里以platen-switch为例
    platen-switch/
    ├── cfg
    │   └── voc.names
    ├── images
    │   ├── IMG_9255.JPG
    │   ├── IMG_9263.JPG
    │   ├── IMG_9266.JPG
    │   └── IMG_9280.JPG
    ├── labels
    │   ├── IMG_9255.txt
    │   ├── IMG_9263.txt
    │   ├── IMG_9266.txt
    │   └── IMG_9280.txt
    └── test
    ├── IMG_9256.JPG
    └── IMG_9271.JPG
    

运行darknet容器 将工程目录作为挂载点绑定到容器 # 使用您的工程绝对路径设置变量 project_dir

使用Darknet在自定义数据集上训练YOLOv3

编译darknet

git clone https://github.com/pjreddie/darknet
cd darknet/
make

创建工程 工程目录结构 ├── darknet53.conv.74 基于imagenet的预训练模型 └── open-close 工程目录 ├── backup 存储模型训练时权重值 ├── cfg 配置目录 │ ├── train.txt 存储用于训练的图像路径 │ ├── valid.txt 存储用于验证的图像路径 │ ├── voc.data 配置文件 │ ├── voc.names 标签名 │ └── yolov3.cfg YOLOv3神经网络文件 ├── data │ └── labels 预测时用于显示标签名字 │ ├── 100_0.png │ ├── 100_1.png │ ├── ...... │ └── make_labels.py ├── images 图像样本集 │ ├── IMG_9255.JPG │ ├── IMG_9263.JPG │ ├── IMG_9266.JPG │ └── IMG_9280.JPG ├── labels PASCAL VOC格式的标注 │ ├── IMG_9255.xml │ ├── IMG_9263.xml │ ├── IMG_9266.xml │ └── IMG_9280.

Linux系统网络配置

Ubuntu

修改IP

$ sudo nano /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      addresses:
      - 172.16.33.1/24
      gateway4: 172.16.33.254
      nameservers: {}
  version: 2

应用配置

$ sudo netplan apply
# 推荐使用 debug 参数
$ sudo netplan --debug apply

或者

sudo netplan generate

验证

ip a | grep eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    inet 172.16.33.1/24 brd 172.16.33.255 scope global eno1

参考资料 How to setup a static IP on Ubuntu Server 18.04 How to configure Network Settings in Ubuntu 18.

Dockerfile JDK-MCR(MATLAB Compiler Runtime)

JDK-MCR(MATLAB Compiler Runtime)

FROM openjdk:latest
LABEL maintainer="wang-junjian@qq.com"

MAINTAINER Wang Junjian

RUN apt-get update && apt-get install -y curl wget unzip xorg

#Install MATLAB runtime
RUN mkdir /mcr-install && cd /mcr-install && \
    wget -nv http://ssd.mathworks.com/supportfiles/downloads/R2018b/deployment_files/R2018b/installers/glnxa64/MCR_R2018b_glnxa64_installer.zip && \
    unzip MCR_R2018b_glnxa64_installer.zip && \
    ./install -mode silent -agreeToLicense yes && \
    rm -Rf /mcr-install

ENV LD_LIBRARY_PATH /usr/local/MATLAB/MATLAB_Runtime/v95/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/extern/bin/glnxa64

CMD /bin/sh

搭建 Private Docker Registry

Registry

配置hosts

sudo nano /etc/hosts
10.10.10.10    HOSTNAME

运行registry

docker pull registry:2

sudo docker run -d \
    -p 5000:5000 \
    -v /home/ailab/docker-registry:/var/lib/registry \
    --restart=always \
    --name docker-registry \
    registry:2

修改Docker配置

sudo nano /etc/docker/daemon.json
{
    "live-restore": true,
    "group": "dockerroot",
    "insecure-registries": ["HOSTNAME:5000"]
}

重启Docker Engine

sudo systemctl restart docker

推送镜像

sudo docker tag hello-world:latest HOSTNAME:5000/hello-world:latest
sudo docker push HOSTNAME:5000/hello-world:latest

Registry UI

开启SSH服务

Ubuntu

  • 安装、卸载SSH服务
sudo apt-get install openssh-server
sudo apt-get remove openssh-server
  • 启动、停止、重启SSH服务
sudo service ssh start
sudo service ssh stop
sudo service ssh restart
  • 查询SSH服务状态
service ssh status
  • 配置文件(更改配置需要重启SSH服务)
sudo vi /etc/ssh/sshd_config
  • 连接SSH服务
ssh username@ip -p 22
  • 设置、移除SSH服务开机自启动
sudo update-rc.d ssh defaults
sudo update-rc.d ssh remove
  • 查看SSH服务设置的自启动
ls /etc/rc*
......
......
ls -l /etc/rc2.d/S02ssh
    lrwxrwxrwx 1 root root 13 12月 25 16:33 /etc/rc2.d/S02ssh -> ../init.d/ssh

参考资料

macOS实践

快捷键

  • 系统
Command+I                   显示选中的文件的“显示简介”窗口
Command+W                   关闭当前应用的窗口
Command+Q                   退出当前应用程序(和command+tab配合可快速批量关闭应用程序)
Command+Delete              移到废纸篓
Command+Shift+Delete        清倒废纸蒌,需要确认。
Command+Option+Shift+Delete 清倒废纸蒌,不需要确认。
Command+C                   复制
Command+Option+C            复制文件或者文件夹的路径
Command+V                   粘贴
Command+Option+V            移动(剪切)
Command+Option+D            显示或隐藏 Dock
Command+Control+F           当前窗口全屏
Command+H                   当前窗口隐藏
Command+M                   当前窗口最小化
Command+Option+Power        休眠
Control+Shift+Power         关闭屏幕
Control+F2                  将焦点移到菜单栏
按住 Option ,单击 屏幕右上角。 打开|关闭勿扰模式
  • 功能键
F11         隐藏|打开 所有打开的窗口(回到桌面)
Fn+F3       Command-Mission Control (F3)     显示桌面
Fn+F4       Launchpad
  • 拍摄屏幕快照
Command+Shift+5             随意截取或者录制窗口的图像和视频
Command+Shift+3             将屏幕捕捉到文件
Command+Shift+4             将所选屏幕内容捕捉到文件,或按空格键仅捕捉一个窗口
Command-Shift-Control-3     将屏幕内容捕捉到剪贴板
Command-Shift-Control-4     将所选屏幕内容捕捉到剪贴板,或按空格键仅捕捉一个窗口