29 篇文章带有标签 “deep-learning”

Get Started OpenVINO

OpenVINO

Open Visual Inference and Neural network Optimization

OpenVINO 安装

Development

pip 安装

安装 OpenVINO 开发工具

python -m venv openvino_env
  • Linux
source openvino_env/bin/activate
  • Windows
openvino_env\Scripts\activate.bat
python -m pip install --upgrade pip
pip install openvino-dev[onnx,pytorch,kaldi,mxnet,caffe,tensorflow2]==2022.1.0 -i https://mirrors.aliyun.com/pypi/simple/

源代码编译安装(没有成功)👹

Build OpenVINO™ Inference Engine

使用PaddleOCR进行文字识别

安装

pip install paddleocr

测试

import cv2
import numpy as np

from paddleocr import PaddleOCR


ocr = PaddleOCR(use_angle_cls=True)
image_path = 'test.jpg'
img = cv2.imread(image_path)

img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray1 = img_gray[:,:, np.newaxis]
img_gray3 = np.concatenate([img_gray1, img_gray1, img_gray1], axis=-1)

texts = ocr.ocr(img_gray3)
for text in texts:
    """
    box   坐标1         坐标2
          坐标4         坐标3
    """
    box = text[0]
    t = text[1][0]
    score = text[1][1]

可视化(图像上画出文本和得分) import os import shutil import cv2 import numpy as np import uuid from PIL import ImageFo

Building ONNX Runtime

NVIDIA CUDA

单步构建

  • 下载onnxruntime源代码
git clone --recursive https://github.com/microsoft/onnxruntime.git
  • 拉取容器(编译环境)
docker pull nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04
  • 运行容器
docker run -it --name build-onnxruntime-gpu --runtime nvidia \
    -v $(pwd)/onnxruntime:/onnxruntime -w /onnxruntime \
    nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04
  • 更新apt镜像源
sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
apt-get update
  • 安装依赖包
apt-get install language-pack-en git cmake python3 python3-pip -y
  • 修改语言环境
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8
  • 更新pip镜像源
pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/

Dockerfile ONNXRuntime GPU

FROM nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04 AS builder
LABEL maintainer="wang-junjian@qq.com"

#E: Failed to fetch https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2004/x86_64/by-hash/SHA256/f10fc2a7a0d072ddcf141af2ef28f1e97ab4b3a5c3b9bbe34ed845d174fb4979  404  Not Found [IP: 61.155.167.2 443]
#E: Some index files failed to download. They have been ignored, or old ones used instead.
RUN rm /etc/apt/sources.list.d/cuda.list /etc/apt/sources.list.d/nvidia-ml.list

RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    apt-get update && \
    apt-get install language-pack-en git python3 python3-pip -y && \
    DEBIAN_FRONTEND=noninteractive apt-get install cmake -y && \
    locale-gen en_US.UTF-8 && \
    update-locale LANG=en_US.UTF-8

RUN pip3 install numpy -i https://mirrors.aliyun.com/pypi/simple/
// ...

在YOLOv5中运行JupyterLab和TensorBoard

构建可用的JupyterLab和TensorBoard

  • 启动YOLOv5容器
docker run --ipc=host --runtime nvidia -it -p 8888:8888 \
    -v ${dataset_dir}:/usr/src/app/project \
    ultralytics/yolov5:latest
  • 安装版本1的TensorBoard。(解决FAQ1的问题:jupyter-tensorboard 0.2.0不支持高于TensorBoard 2.0的版本。YOLOv5镜像中安装的TensorBoard 2.4的版本。)
pip uninstall tensorboard -y && pip install tensorboard==1.15
  • 运行JupyterLab
jupyter lab --no-browser --ip 0.0.0.0 --port 8888
  • 本地浏览器进行访问
http://ip:8888/lab

FAQ Launcher Error - Invalid response: 500 Internal Server Error Uncaught exception POST /api/tensorboard?1609481325314 (192.168.1.

使用YOLOv5训练自定义数据集

在 Ubuntu20.04 系统上使用4张GPU卡基于容器训练模型。

准备数据

project
├── data.yaml           #数据集配置文件
├── models              #网络模型(可以使用下面的脚本自动生成)
│   ├── yolov5s.yaml    #Small
│   ├── yolov5m.yaml    #Medium
│   ├── yolov5l.yaml    #Large
│   └── yolov5x.yaml    #XLarge
├── images              #图片
│   ├── train           #训练集
│   │   ├── 000001.jpg
│   │   ├── 000002.jpg
│   │   └── 000003.jpg
│   └── val             #验证集
│       ├── 000010.jpg
│       └── 000011.jpg
├── labels              #YOLO格式的标注
│   ├── train           #训练集
│   │   ├── 000001.txt
│   │   ├── 000002.txt
│   │   └── 000003.txt
│   └── val             #验证集
│       ├── 000010.txt
│       └── 000011.txt
├── test                #测试图片
└── output              #推理后的标注图片

构建环境

  • 拉取镜像
$ docker pull ultralytics/yolov5:latest
  • 运行容器
$ docker run --ipc=host --runtime=nvidia -it --name project_name-yolov5 \
    -v project_dir:/usr/src/app/project ultralytics/yolov5:latest

使用RetinaNet算法训练自定义数据集

训练自己的数据集

标注数据

LabelImg

#标注后的目录结构
project
└── labelimg
    ├── 20190128155421222575013.jpg
    ├── 20190128155421222575013.xml
    ├── 20190128155703035712899.jpg
    ├── 20190128155703035712899.xml
    ├── 20190129091126392737624.jpg
    └── 20190129091126392737624.xml

构建镜像

  • 拉取
$ sudo docker pull gouchicao/keras-retinanet:latest
  • 手动构建
FROM gouchicao/tensorflow:2.2.0-gpu-jupyter-opencv4-pillow-wget-curl-git-nano
LABEL maintainer="wang-junjian@qq.com"
WORKDIR /
RUN mkdir -p /root/.keras/models/ && \
    wget -O /root/.keras/models/ResNet-50-model.keras.h5 https://github.com/fizyr/keras-models/releases/download/v0.0.1/ResNet-50-model.keras.h5
RUN git clone --depth 1 --recurse-submodules https://github.com/gouchicao/keras-retinanet.git
WORKDIR /keras-retinanet/keras-retinanet
# 提前安装指定版本 keras==2.3.1 解决错误 TypeError: type object got multiple values for keyword argument 'training'
RUN pip install keras==2.3.1 && \
    pip install . && \
    python setup.py build_ext --inplace
WORKDIR /keras-retinanet

将注释从PASCAL VOC转换为YOLO Darknet

PASCAL VOC(Visual Object Classes) 格式

格式

  • 每张图片对应一个xml标注文件。
  • object  标注的对象,一张图片可以有1个或者多个
  • name  类别名
  • bndbox 标注的边框(使用的坐标信息)
  • difficult 目标是否难以识别(0表示容易识别)

0001.xml <annotation> <folder>car</folder> <filename>0001.jpg</filename> <path>/dataset/car/0001.

构建YOLOv4容器应用在自定义数据集上

构建YOLOv4容器

  • 编写Dockerfile
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04
LABEL maintainer="wang-junjian@qq.com"

#auto install tzdata(opencv depend)
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
    git wget nano \
    libopencv-dev python3-opencv \
    && rm -rf /var/lib/apt/lists/*

#set your localtime
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

WORKDIR /
// ...
  • 构建容器
docker build -t darknet:latest-gpu-yolov4 .

创建工程 工程目录结构 ├── yolov4.conv.137 预训练模型 ├── darknet └── project 工程目录 ├── backup 存储模型训练时权重值 ├── cfg 配置目录 │ ├── train.