aws 对象存储_使用AWS Sagemaker进行对象检测,图像分类和语义分割

本文介绍了如何利用AWS Sagemaker进行对象检测、图像分类和语义分割。通过aws对象存储服务,结合Python和计算机视觉库如OpenCV,实现人工智能在视觉任务中的应用。
摘要由CSDN通过智能技术生成

aws 对象存储

Today Artificial Intelligence and Machine Learning go hand in hand. With such an advanced move in the field of technology machines use their own senses to learn new patterns, solving problems, and so on. Image classification, Object detection, and Semantic segmentation are the branches of the same tree.

今天,人工智能和机器学习齐头并进。 随着技术领域的如此先进的发展,机器使用自己的感觉来学习新的模式,解决问题等等。 图像分类,对象检测和语义分割是同一棵树的分支。

In this post, we will be learning about the different techniques such as Classification, Detection, and Segmentation and how we will be using AWS Sagemaker to train and deploy the respective machine learning models.

在本文中,我们将学习分类,检测和分段等不同技术,以及如何使用AWS Sagemaker训练和部署相应的机器学习模型。

But before we move ahead let’s understand the difference between them. Lets first go over two basic definitions that will help you as you learn about each technique:

但是在继续前进之前,让我们了解它们之间的区别。 首先让我们介绍两个基本定义,这些基本定义将在您学习每种技术时为您提供帮助:

  • Labeling: Labeling refers to us taking a dataset of unlabeled images and adding meaningful, informative tags telling you what is in that image.

    标记:标记是指我们获取未标记图像的数据集,并添加有意义的信息标签,告诉您该图像中的内容。
  • Bounding boxes: Bounding boxes are a type of labeling where a box can be created, edited, and deleted, and the box is assigned concepts.

    边界框:边界框是一种标签类型,可以在其中创建,编辑和删除框,并为框分配概念。

What is Image Classification?

什么是图像分类?

This technique is useful if you just need to identify general things like “Is this a beach or is it a pool?”It refers to a type of labeling where an image/video is assigned certain concepts, with the goal of answering the question, “What is in this image/video?”. Moreover, Image Classification is the task of extracting information classes from a multiband raster image. It is a supervised learning problem.

如果您只需要识别诸如“这是海滩还是游泳池?”之类的常规事物,则此技术很有用。它是一种标签类型,其中为图像/视频分配了某些概念,目的是回答问题, “此图像/视频中有什么?”。 此外,图像分类是从多波段光栅图像中提取信息类别的任务。 这是有监督的学习问题。

The Amazon SageMaker image classification algorithm is a supervised learning algorithm that supports multi-label classification. It takes an image as input and outputs one or more labels assigned to that image. It uses a convolutional neural network (ResNet).

Amazon SageMaker图像分类算法是一种支持多标签分类的监督学习算法。 它以图像作为输入,并输出分配给该图像的一个或多个标签。 它使用卷积神经网络(ResNet)。

What is Object Detection?

什么是物体检测?

This technique is useful if you need to identify particular objects in a scene, like the cars parked on a street, versus the whole image. It is a computer vision technique for locating instances of objects in images or videos. Object detection algorithms typically leverage Machine learning or deep learning to produce meaningful results. It uses bounding boxes to tell us where each object is in an image/video. Face detection is one form of object detection.

如果您需要识别场景中的特定对象(例如停在街道上的汽车)和整个图像,则此技术很有用。 它是一种计算机视觉技术,用于定位图像或视频中的对象实例。 对象检测算法通常利用机器学习或深度学习来产生有意义的结果。 它使用边界框来告诉我们每个对象在图像/视频中的位置。 人脸检测是物体检测的一种形式。

The Amazon SageMaker Object Detection algorithm detects and classifies objects in images using a single deep neural network. It is a supervised learning algorithm. The object is categorized into one of the classes in a specified collection with a confidence score that it belongs to the class. Its location and scale in the image are indicated by a rectangular bounding box. It uses the Single Shot multi-box Detector (SSD) framework.

Amazon SageMaker对象检测算法使用单个深度神经网络检测并分类图像中的对象。 它是一种监督学习算法。 该对象被归类为指定集合中的类之一,并且该对象属于该类的置信度得分。 其在图像中的位置和比例由一个矩形边界框指示。 它使用Single Shot Multi-box Detector(SSD)框架。

What is Semantic Segmentation?

什么是语义分割?

Segmentation is a type of labeling where each pixel in an image is labeled with given concepts. Here, whole images are divided into pixel groupings which can then be labeled and classified, with the goal of simplifying an image or changing how an image is presented to the model, to make it easier to analyze. The divided parts of an image are called segments. It’s not a great idea to process the entire image at the same time as there will be regions in the image which do not contain any information. By dividing the image into segments, we can make use of the important segments for processing the image.

分割是一种标记类型,其中图像中的每个像素都使用给定的概念标记。 在这里,整个图像被分为像素组,然后可以对其进行标记和分类,以简化图像或更改将图像呈现给模型的目的,以使其更易于分析。 图像的划分部分称为段。 同时处理整个图像不是一个好主意,因为图像中的某些区域将不包含任何信息。 通过将图像分成多个部分,我们可以利用重要的部分来处理图像。

The Amazon SageMaker semantic segmentation algorithm provides a fine-grained, pixel-level approach to developing computer vision applications. It tags every pixel in an image with a class label from a predefined set of classes.

Amazon SageMaker语义分段算法为开发计算机视觉应用程序提供了一种细粒度的像素级方法。 它使用预定义的一组类中的类标签标记图像中的每个像素。

While human beings have always been able to do all the above in the blink of an eye, it’s taken many years of research, trial, and error to allow computers to emulate us. Nevertheless, today, thanks to computer vision, our devices are finally catching up to our needs. Let’s understand how to build and deploy these image processing models using AWS services.

尽管人类总是能够眨眼间就能完成上述所有操作,但经过多年的研究,试验和错误,计算机才能模仿我们。 尽管如此,今天,由于计算机视觉的原因,我们的设备终于可以满足我们的需求。 让我们了解如何使用AWS服务构建和部署这些图像处理模型。

For this project, we have used Amazon Sagemaker and S3 buckets

在此项目中,我们使用了Amazon Sagemaker和S3存储桶

AWS Sagemaker

AWS Sagemaker

Image for post

There are many cloud platforms available for data scientists for developing and deploying machine learning models. Amazon Sagemaker is one of the popular platforms to deploy machine learning models in a progressive environment. SageMaker removes the heavy lifting from each step of the machine learning process to make it easier to develop high-quality models.

有许多云平台可供数据科学家用于开发和部署机器学习模型。 Amazon Sagemaker是在渐进环境中部署机器学习模型的流行平台之一。 SageMaker消除了机器学习过程中每个步骤的繁重工作,从而使开发高质量模型变得更加容易。

S3 — Simple Storage Service

S3 —简单存储服务

Image for post

S3 is a storage service offered by Amazon, it helps to store and retrieve any amount of data, at any time, from anywhere on the web. It stands for simple storage service and provides cloud storage for various types of web development applications. To upload your data (photos, videos, documents, etc.) to Amazon S3, you must first create an S3 bucket in one of the AWS Regions. You can then upload any number of objects to the bucket.

S3是Amazon提供的一种存储服务,它可以帮助您随时随地从网络上的任何地方存储和检索任何数量的数据。 它代表简单的存储服务,并为各种类型的Web开发应用程序提供云存储。 要将数据(照片,视频,文档等)上传到Amazon S3,您必须首先在一个AWS区域中创建一个S3存储桶。 然后,您可以将任意数量的对象上传到存储桶。

About the dataset, the data is taken from popular IIIT-Oxford Pets Dataset.

关于数据集,数据取自受欢迎的IIIT-Oxford Pets数据集

The architecture of the project

项目的架构

Image for post

步骤(Steps:)

在AWS Sagemaker上创建笔记本实例 (Create a Notebook Instance on AWS Sagemaker)

To begin, go to AWS Management Console and type Amazon Sagemaker in the find service box. Click on Amazon Sagemaker.

首先,转到AWS管理控制台,然后在查找服务框中键入Amazon Sagemaker。 单击Amazon Sagemaker。

Image for post

On the next page, in the left menu find and click on Notebook Instances.

在下一页的左侧菜单中,找到并单击“笔记本实例”。

Image for post

Next, enter the name of the notebook instance and create a new role. We have already created a role so we are going to use the existing one. Keep the rest of the settings as default.

接下来,输入笔记本实例的名称并创建一个新角色。 我们已经创建了一个角色,因此我们将使用现有角色。 将其余设置保留为默认设置。

Image for post

And Click on “Create Notebook Instance”.

然后单击“创建笔记本实例”。

Image for post

On the next page, you will see the status is pending. It will take a few minutes.

在下一页上,您将看到状态为待定。 这将需要几分钟。

Image for post
  1. After a few minutes, the status will be “InService”. Now, click on the “Open Jupyter” notebook.

    几分钟后,状态将为“ InService”。 现在,单击“打开Jupyter”笔记本。
Image for post

Once the notebook is open, we can write the code in python, here we will be performing the next steps

打开笔记本后,我们可以用python编写代码,在这里我们将执行下一步

2. Download the Data

2.下载数据

Image for post

3. Extract the Annotation

3.提取注释

Image for post

4. Visualize the data

4.可视化数据

Image for post

5. Setting up Sagemaker

5.设置Sagemaker

Here we set up the linkage and authentication to AWS services. There are three parts to this:

在这里,我们建立了与AWS服务的链接和身份验证。 这包括三个部分:

  • The roles used to give learning and hosting access to your data. This will automatically be obtained from the role used to start the notebook

    用于授予对数据的学习和托管访问权限的角色。 这将从用于启动笔记本的角色中自动获得
  • The S3 bucket that you want to use for training and model data

    您要用于训练和模型数据的S3存储桶
  • The Amazon sagemaker image classification docker image which need not be changed

    无需更改的Amazon sagemaker图像分类docker图像
Image for post

6. Upload the data to S3

6.将数据上传到S3

Now finally we will upload the data to the s3 bucket. We have to make a bucket with AWS S3 to store the dataset.

现在,我们终于将数据上传到s3存储桶。 我们必须使用AWS S3创建存储桶以存储数据集。

Come back to AWS Management Console and Search S3

返回AWS管理控制台并搜索S3

Image for post

Click on Create Bucket button on the AWS console page

单击AWS控制台页面上的Create Bucket按钮

Image for post

Further, give the bucket a name, we gave “petsdataset” in our case. Click next and then create a bucket.

此外,给存储桶起一个名字,在这种情况下,我们给了“ petsdataset”。 单击下一步,然后创建一个存储桶。

Image for post
Image for post

Now we will push the data from the temporary storage to the S3 bucket that we created above.

现在,我们将数据从临时存储推送到上面创建的S3存储桶中。

Image for post

7. Sagemaker Estimator

7.贤者估计器

Now we will set the sagemaker estimator, set a training instance, runtime, and the path where we will save our model.

现在,我们将设置sagemaker估计器,设置训练实例,运行时以及保存模型的路径。

In our case, we have saved the model in the s3 bucket under the output folder.

在本例中,我们已将模型保存在输出文件夹下的s3存储桶中。

Image for post

8. Hyperparameter tuning

8.超参数调整

We will perform some hyperparameter tuning for the model

我们将对该模型执行一些超参数调整

  • num_layers: The number of layers (depth) for the network. We use 18 in these samples but other values such as 50, 152 can be used.

    num_layers :网络的层数(深度)。 我们在这些样本中使用18,但可以使用其他值,例如50、152。

  • num_classes: This is the number of output classes for the new dataset. pets data was trained with 37 output classes.

    num_classes :这是新数据集的输出类别的数量。 宠物数据经过37个输出类别的训练。

  • epochs: Number of training epochs

    纪元 :训练纪元数

  • learning_rate: Learning rate for training

    learning_rate :培训的学习率

  • num_training_samples: This is the total number of training samples.

    num_training_samples :这是训练样本的总数。

  • mini_batch_size: The number of training samples used for each mini-batch. In distributed training, the number of training samples used per batch will be N * mini_batch_size where N is the number of hosts on which training is run

    mini_batch_size :每个微型批次使用的训练样本数。 在分布式培训中,每批使用的培训样本数将为N * mini_batch_size,其中N是运行培训的主机数

Image for post

9. Data Channels

9.数据通道

Image for post

10. Training the model

10.训练模型

Image for post

You can also view information about and the status of a training job using the AWS SageMaker console. Just click on the “Jobs” tab.

您还可以使用AWS SageMaker控制台查看有关培训工作的信息和状态。 只需单击“工作”标签。

11. Deploying model

11.部署模型

Image for post

12. Predicting the results

12.预测结果

Image for post
Image Classification outcome
图像分类结果

When we’re done with the endpoint, we can just delete it and the backing instances will be released.

终结点完成后,我们可以删除它,并且支持实例将被释放

We have used the same dataset for Object Detection and Semantic Segmentation. The first few steps for both Object Detection as well as Semantic Segmentation is quite similar.

我们将相同的数据集用于对象检测和语义分割。 对象检测和语义分割的前几个步骤非常相似。

We will be Downloading and Extracting the data, and creating notebook instances as done above.While preparing data for Sagemaker, we will perform the following steps:

我们将如上所述下载和提取数据,并创建笔记本实例。在为Sagemaker准备数据时,我们将执行以下步骤:

Image for post
Preparing data for Object detection
准备用于对象检测的数据
Image for post
Preparing data for Semantic Segmentation
为语义分割准备数据

We will further upload the data to the S3 buckets and perform hyperparameter tuning

我们将进一步将数据上传到S3存储桶并执行超参数调整

Image for post
Hyperparameter Tuning for Object Detection
用于对象检测的超参数调整
Image for post
Hyperparameter Tuning for Semantic Segmentation
用于语义分割的超参数调整

We will further train, deploy, and predict the outcomes as done above.

如上所述,我们将进一步培训,部署和预测结果。

The outcomes for object detector are as follows:

对象检测器的结果如下:

Image for post
Prediction for Object Detection
物体检测预测
Image for post
Image for post
Output
输出量

The outcomes of semantic segmentation are as follows:

语义分割的结果如下:

Image for post
The outcome for Semantic Segmentation
语义分割的结果

Please take note that all the three projects were performed in different notebook instance of Amazon Sagemaker.

请注意,所有三个项目都是在Amazon Sagemaker的不同笔记本实例中执行的。

The GitHub link for the project is https://github.com/skolungade/AWS-Sagemaker-Image-Classification-Object-Detection-and-Semantic-Segmentation-

该项目的GitHub链接为https://github.com/skolungade/AWS-Sagemaker-Image-Classification-Object-Detection-and-Semantic-Segmentation-

可能有用的参考: (References which might be helpful:)

(2020). Retrieved 3 August 2020, from https://docs.aws.amazon.com/s3/?id=docs_gateway

(2020)。 于2020年8月3日从https://docs.aws.amazon.com/s3/?id=docs_gateway检索

Train Models — Amazon SageMaker. (2020). Retrieved 3 August 2020, from https://docs.aws.amazon.com/sagemaker/latest/dg/train-model.html

训练模型— Amazon SageMaker。 (2020)。 取自2020年8月3日, 网址https://docs.aws.amazon.com/sagemaker/latest/dg/train-model.html

Image Segmentation in Deep Learning: Methods and Applications — MissingLink.ai. (2020). Retrieved 3 August 2020, from https://missinglink.ai/guides/computer-vision/image-segmentation-deep-learning-methods-applications/

深度学习中的图像分割:方法和应用-MissingLink.ai。 (2020)。 于2020年8月3日检索, 网址https://missinglink.ai/guides/computer-vision/image-segmentation-deep-learning-methods-applications/

翻译自: https://medium.com/@kolungade.s/object-detection-image-classification-and-semantic-segmentation-using-aws-sagemaker-e1f768c8f57d

aws 对象存储

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值