部署容器jenkins_使用Jenkins部署用于进行头盔检测的烧瓶容器

部署容器jenkins

Head injuries are a major cause of death, injury and disability among users of motorized two wheel vehicles.The lack or inappropriate use of helmets has been shown to increase the risk of fatalities and injuries resulting from road crashes.Use of helmets has been shown to reduce fatal and serious head injuries by between 20% and 45% among motorized two-wheelers users.

头部受伤是造成两轮机动车辆使用者死亡,伤害和致残的主要原因,头盔的使用不当或使用不当会增加道路交通事故导致死亡和受伤的风险。将机动两轮车用户的致命和严重头部伤害降低20%至45%。

We have developed a web application which gives a count of people wearing and not wearing helmets.Internally the web app uses YOLO Object Detection Algorithm.

我们已经开发了一个Web应用程序,该应用程序可以统计戴头盔和不戴头盔的人数。该Web应用内部使用YOLO对象检测算法

YOLO算法概述: (Overview of the YOLO Algorithm:)

YOLO (You Only Look Once) is a real-time object detection algorithm, which is one of the most effective object detection algorithms.Object detection is a problems in computer vision where we have to recognize what and where i.e. what objects are inside a given image and also where they are in the image.

YOLO(仅查看一次)是一种实时的对象检测算法,是最有效的对象检测算法之一。对象检测是计算机视觉中的一个问题,我们必须识别给定对象中的什么位置图片以及它们在图片中的位置。

This algorithm works by performing only one forward pass, a single CNN simultaneously predicts multiple bounding boxes and class probabilities for those boxes. YOLO trains on full images and directly optimizes detection performance.

该算法仅执行一次前向通过,单个CNN会同时预测多个边界框和这些框的类概率。 YOLO训练完整图像并直接优化检测性能。

Darknet is a framework to train neural networks, it is open source and written in C/CUDA and serves as the basis for YOLO.

Darknet是训练神经网络的框架,它是开源的,用C / CUDA编写,是YOLO的基础。

Clone the repo locally. To compile it, run a make. But first, if we intend to use the GPU capability we need to edit the Makefile in the first two lines, where we tell it to compile for GPU usage with CUDA drivers.The repo comes with multiple configuration files for training on different architectures. We can use it immediately for detection by downloading some pre-trained weights people have created.

在本地克隆仓库。 要进行编译,请运行make 。 但是首先,如果我们打算使用GPU功能,则需要在前两行中编辑Makefile ,然后告诉它使用CUDA驱动程序编译GPU使用情况.repo附带了多个配置文件,用于在不同架构上进行培训。 通过下载人们创建的一些预先训练的权重,我们可以立即将其用于检测。

wget https://pjreddie.com/media/files/yolov3.weights

We can use the above command to download the pretrained weights.These weights have been trained on the COCO dataset, with the 80 classes specified in this list.

我们可以使用上面的命令下载预训练的权重。这些权重已经在COCO数据集中进行了训练, 该列表中指定了80个类别

Devops的角色: (Role of Devops:)

AI模型的问题: (Problems with AI models :)

1] Difficulty with deployment: Data science teams are using a variety of ML platforms, languages, and frameworks that rarely produce production-ready models.

1] 部署困难 :数据科学团队正在使用各种ML平台,语言和框架,这些模型很少产生可用于生产的模型。

2] Constant updates: These applications have a complex lifecycle, including frequent updates that, when done manually, are time-consuming. Model updates also require significant production testing and validation to maintain production model quality.

2] 持续更新 :这些应用程序的生命周期很复杂,其中包括手动进行的频繁更新非常耗时。 模型更新还需要进行大量的生产测试和验证,以保持生产模型的质量。

DevOps manages the dynamic nature of machine learning applications with the ability to frequently update models, including testing and validation of new models. Update models on-the-fly while continuing to serve business applications. It also provides advanced monitoring softwares which can give us various data drift analysis, model-specific metrics, alerts etc.

DevOps通过频繁更新模型(包括测试和验证新模型)的能力来管理机器学习应用程序的动态性质。 在继续服务于业务应用程序的同时,动态更新模型。 它还提供了先进的监控软件,可以为我们提供各种数据漂移分析,特定于模型的指标,警报等。

In this project we are going to use two common devops tools:1] Docker2] Jenkins

在这个项目中,我们将使用两个常见的devops工具:1] Docker 2] Jenkins

什么是Docker ?? (What is Docker ??)

Docker container provide a way to get a grip on software. We can use it to wrap up an application in such a way that its deployment and runtime issues — how to expose it on a network, how to manage its use of storage and memory and I/O, how to control access permissions — are handled outside of the application itself.

Docker容器提供了一种掌握软件的方法。 我们可以使用它来包装应用程序,从而解决其部署和运行时问题(如何在网络上公开它,如何管理其对存储和内存以及I / O的使用,如何控制访问权限)在应用程序本身之外。

We can run Docker containers on any OS-compatible host (Linux,Windows or MacOs ) that has the Docker runtime installed.

我们可以在安装了Docker运行时的任何与OS兼容的主机(Linux,Windows或MacOs)上运行Docker容器。

詹金斯是什么?? (What is Jenkins ??)

It is an open-source automation tool written in Java with plugins built for Continuous Integration purposes.

这是一个用Java编写的开源自动化工具,带有为持续集成目的而构建的插件。

Continuous Integration :

持续集成 :

  • First, a developer commits the code to the source code repository. Meanwhile, the Jenkins server checks the repository at regular intervals for changes.

    首先,开发人员将代码提交到源代码存储库。 同时,Jenkins服务器会定期检查存储库是否有更改。
  • Then Jenkins server detects the changes that have occurred in the source code repository. Jenkins will pull those changes and will start preparing a new build.

    然后,Jenkins服务器检测到源代码存储库中发生的更改。 詹金斯将撤消这些更改并将开始准备新的版本。
  • If the build fails, then the concerned team will be notified.

    如果构建失败,则将通知相关团队。
  • If built is successful, then Jenkins deploys the built in the test server.

    如果构建成功,则Jenkins会部署内置在测试服务器中。
  • It will continue to check the source code repository for changes made in the source code and the whole process keeps on repeating.

    它将继续检查源代码存储库中是否对源代码进行了更改,并且整个过程不断重复。

Using all the above tools we are going to build the project !!!!!!

使用以上所有工具,我们将构建项目!

程序: (Procedure:)

1] Data Preparation :

1]数据准备

As with any deep learning task, the first most important task is to prepare the dataset . So for this project we need to collect images of various two-wheelers users.

与任何深度学习任务一样,最重要的任务是准备数据集。 因此,对于此项目,我们需要收集各种两轮车用户的图像。

To do so we have used google images downloader extension from Chrome Web store . This extension downloads all the images in the given web page and saves them as a zip file.

为此,我们使用了来自Chrome网上应用店的 Google图片下载器扩展程序。 此扩展程序下载给定网页中的所有图像,并将它们另存为zip文件。

We have downloaded around 350 images.

我们已经下载了约350张图像。

For training a YOLO model on our custom dataset we need to provide images with their respective annotation file ( co-ordinates of the object we want to detect ).Each of the file must be of the below form.

为了在我们的自定义数据集上训练YOLO模型,我们需要为图像提供各自的注释文件(我们要检测的对象的坐标),每个文件都必须采用以下格式。

For annotation purposes we have used a tool called LabelImg.

为了进行注释,我们使用了一个称为LabelImg的工具

This is simple tool used for graphically labeling images. It’s written in Python and uses QT for its graphical interface. It’s an easy, free way to label a few hundred images.

这是用于图形标记图像的简单工具。 它是用Python编写的,并将QT用于其图形界面。 这是标记数百张图像的一种简单,免费的方法。

In this way we have created boxes around each of the class we want the model to detect and after saving we get a text file containing the required class id and the co-ordinates.

这样,我们在希望模型检测的每个类周围创建了框,保存后得到一个包含所需类ID和坐标的文本文件。

In this way we had done it to all the images.

这样,我们对所有图像进行了处理。

Alternatively we could download our required dataset from Open Images Dataset V6.

或者,我们可以从Open Images Dataset V6下载所需的数据集。

2] Training the model

2]训练模型

To train the model we have followed a youtube video.

为了训练模型,我们遵循了youtube视频。

Changed all the config files according to our requirements and started the training process.

根据我们的要求更改了所有配置文件,并开始了培训过程。

We have trained the model for 910 epochs and at this is point the model had a loss of only 1.8.

我们已经为910个时代训练了该模型,此时该模型的损失仅为1.8。

This has taken around 4 hours 这花了大约4个小时

3] Creating a Flask Application

3]创建一个Flask应用程序

Flask is a web framework which provides us with tools, libraries and technologies that allow us to build a web application. This web application can be some web pages, a blog, a wiki or go as big as a web-based calendar application or a commercial website.

Flask是一个Web框架,可为我们提供工具,库和技术,使我们能够构建Web应用程序。 该Web应用程序可以是某些网页,博客,Wiki,也可以和基于Web的日历应用程序或商业网站一样大。

For the project we built a flask app which accepts an image from the user and then gets the predictions from the yolo model to display the results on a new page.

对于该项目,我们构建了一个flask应用程序,该应用程序接收来自用户的图像,然后从yolo模型获取预测,以在新页面上显示结果。

This app shows the image with all the people wearing and not wearing helmets by drawing bounding boxes.Then shows the count of the respective classes.

该应用程序通过绘制边界框来显示所有戴着头盔或不戴着头盔的人的图像,然后显示相应类别的计数。

现在是DevOps的一部分 (Now comes the part of DevOps)

4] Jenkins JOB-1

4]詹金斯(Jenkins)JOB-1

Whenever the developer commits new code to github this job is triggered.

每当开发人员将新代码提交到github时,都会触发此作业。

Poll SCM is used to monitor the github repo periodically 轮询SCM用于定期监视github存储库

5] Jenkins JOB-2

5]詹金斯(Jenkins)JOB-2

The container is created and “app.py” file is executed.This job is executed only when JOB-1 is stable.

创建容器并执行“ app.py”文件。仅当JOB-1稳定时才执行此作业。

6] Jenkins JOB-3

6]詹金斯(Jenkins)JOB-3

This job is purely for monitoring purpose.It is built periodically and checks whether our container is running our not . In case the container is down it launches a new container and also notifies the developer.

这项工作纯粹是出于监视目的。它是定期构建的,并检查我们的容器是否正在运行。 如果容器出现故障,它将启动一个新容器并通知开发人员。

网站截图 (Screenshots of the Website)

1] Choose the image :

1]选择图像:

2] Click Predict :

2]点击预测:

3] Click Get-result :

3]点击获取结果:

Testing another image :

测试另一张图片:

We had also tried with videos but the detection time was very high per frame.The model has taken around 2 sec/frame.

我们也尝试过使用视频,但是每帧的检测时间非常高,模型花费了大约2秒/帧的时间。

未来范围 (Future Scope)

In the near future when camera quality gets better and cost gets cheaper we can also detect the number plates for sending a notice and penalty to the person who isn’t wearing safety gear while driving. This can easily be automated, eliminating the need of traffic police to focus on more daunting tasks.

在不久的将来,当摄像头质量变得更好,成本变得更便宜时,我们还可以检测到车牌,以向未佩戴安全装置的人发送通知和罚款。 这可以很容易地实现自动化,而无需交警专注于更艰巨的任务。

Github link:

Github链接:

Project Contributors: J. CHETHAN AVINASH

项目贡献者:J. CHETHAN AVINASH

结论 (Conclusion)

This is just a basic setup to integrate Deep Learning models with DevOps.We can use another popular tool called “Kubernetes”. Kubernetes has the capability to monitor the containers and also scale them when the load increases.In today’s world many companies are using cloud services to deploy their applications and maintain them with zero downtime.

这只是将深度学习模型与DevOps集成的基本设置。我们可以使用另一个流行的工具“ Kubernetes ”。 Kubernetes能够监视容器并在负载增加时对其进行扩展。当今世界,许多公司正在使用云服务来部署其应用程序并以零停机时间对其进行维护。

Thank you for the time….

谢谢您的时间...。

翻译自: https://medium.com/@rohan6820/deploying-a-flask-container-for-helmet-detection-by-using-jenkins-6a09e410df47

部署容器jenkins

你可能感兴趣的:(docker)