航拍仙人掌识别

Transfer learning is a useful strategy for applications of image like classification and detection when we don’t have enough data to train the model. This also enables us to train the model with little modification in the pre trained architecture, like adding a layer on top of the model and only training the added layer. Unlike training the model from scratch this can be really handy as the number of parameters required to train the model would be less which would ensure less computational cost. This blog explains application of transfer learning to detect if the image has cactus. To do so we shall use a dataset from kaggle.

当我们没有足够的数据来训练模型时,转移学习对于图像的分类和检测等应用是一种有用的策略。 这也使我们能够在预训练的体系结构中进行很少修改的情况下训练模型,例如在模型之上添加一个层并仅训练添加的层。 与从头开始训练模型不同,这非常方便,因为训练模型所需的参数数量会更少,这将确保更少的计算成本。 该博客介绍了转移学习在检测图像中是否有仙人掌的应用。 为此,我们将使用kaggle的数据集。

数据集: (DATASET:)

The dataset is taken from kaggle’s ‘Aerial Cactus Identification’ competition. To read the dataset we can use pandas. Following line does the job of reading the csv file for us.

该数据集来自kaggle的“ 空中仙人掌识别 ”竞赛。 要读取数据集,我们可以使用熊猫。 下一行为我们完成了读取csv文件的工作。

df_train=pd.read_csv('/kaggle/input/aerial-cactus-identification/train.csv')df_test = pd.read_csv('/kaggle/input/aerial-cactus-identification/test.csv’)

The csv file has the image id and its corresponding label whether the image has cactus or not. So this is a binary classification problem. To get various statistics about the labels we can use the value_counts method. The following code snippet does it for us.

csv文件具有图像ID及其相应的标签,无论图像是否具有仙人掌。 因此,这是一个二进制分类问题。 要获取有关标签的各种统计信息,我们可以使用value_counts方法。 以下代码段为我们做到了。

df_train[‘has_cactus’].value_counts()

The above code snippet gives us the output of the number of labels from each class.

上面的代码段为我们提供了每个类的标签数量的输出。

To visualize an image from the dataset we can take the help of the opencv library. The following code snippet does the job of showing a picture.

为了可视化来自数据集的图像,我们可以借助opencv库。 以下代码段完成了显示图片的工作。

img=cv2.imread(‘/home/aditya123/Downloads/aerial-cactus-identification/train/0a02cef73a1660adad8fc43b07fa9d23.jpg’)plt.imshow(img)

The output of the above snippet is the following image

上面代码段的输出是下图

预处理: (Preprocessing:)

The dataset provided by kaggle has all the images in one folder and corresponding labels in a separate csv file. To split the data into training and validation set I have used numpy. The first 15000 records are considered as part of the training data whereas the rest are considered as the validation data. To put the data as input to the model I have used the flow_from_dataframe method. This method enables us to use the power of ImageDataGenerator for data augmentation. The given csv file maps the filenames of the training images to their respective classes. Let us see how to do the same in the below code snippet.

kaggle提供的数据集将所有图像保存在一个文件夹中,并将相应的标签保存在单独的csv文件中。 要将数据分为训练和验证集,我使用了numpy。 前15000条记录被视为训练数据的一部分,而其余部分被视为验证数据。 为了将数据输入模型,我使用了flow_from_dataframe方法。 这种方法使我们能够使用ImageDataGenerator的功能进行数据增强。 给定的csv文件将训练图像的文件名映射到它们各自的类。 让我们看看如何在下面的代码片段中执行相同的操作。

datagen = ImageDataGenerator(rescale=1/255)batch_size=150train_generator=datagen.flow_from_dataframe(dataframe=df_train[:15001],directory=train_dir,x_col=’id’, y_col=’has_cactus’,class_mode = ‘binary’,batch_size=batch_size, target_size=(299,299))validation_generator=datagen.flow_from_dataframe(dataframe=df_train[15000:],directory = train_dir,x_col=’id’, y_col=’has_cactus’,class_mode=’binary’,batch_size=batch_size, target_size=(299,299))

As per the image augmentation part I have chosen to rescale the image pixel values within the range 0 to 1. This method creates a batch of image with its corresponding labels where the pixel values are in between 0 and 1. So now our dataset is ready to be input to the model.

根据图像增强部分,我选择在0到1的范围内重新缩放图像像素值。此方法将创建一批带有相应标签的图像,其中像素值介于0和1之间。因此,我们的数据集已准备就绪输入模型。

造型: (Modelling:)

As our dataset is ready after preprocessing, it is the time to build the model. We can always try to create a model from scratch. However it would not be a great idea since it would take a lot of time because of large number of computation. Also there is no guarantee that the model would converge well after the training is over. So we would just reuse the weights of the already existing model that was trained on the imagenet dataset while keeping some parts of the network open for training.

由于我们的数据集经过预处理后就可以使用了,现在该构建模型了。 我们始终可以尝试从头开始创建模型。 但是,这并不是一个好主意,因为大量的计算会花费很多时间。 同样,也不能保证训练结束后模型可以很好地收敛。 因此,我们只需要重用在imagenet数据集上已训练的现有模型的权重,同时使网络的某些部分保持开放状态即可进行训练。

In this problem we would use the inceptionv3 architecture. The detailed analysis of this model can be found at https://arxiv.org/pdf/1409.4842.pdf. Here we are concerned with the implementation of the model. This model has 48 layers. And has been trained with the imagenet dataset which has 1000 classes. Since this model has been trained on such wide range images it has ability to learn the feature representation of any image.

在这个问题中,我们将使用inceptionv3体系结构。 可在https://arxiv.org/pdf/1409.4842.pdf上找到此模型的详细分析。 在这里,我们关注模型的实现。 该模型有48层。 并已使用具有1000个类别的imagenet数据集进行了训练。 由于已经在如此宽范围的图像上训练了该模型,因此它具有学习任何图像的特征表示的能力。

To load the model we can take the help of keras library. The following code snippet does the loading of the model.

要加载模型,我们可以借助keras库。 以下代码段将加载模型。

model =InceptionV3(weights=’imagenet’,include_top=False,input_shape=(299,299,3))

Here we have mentioned the input shape as (299,299,3) as that is the shape in which the original model had got inputs.

在这里,我们将输入形状称为(299,299,3),因为它是原始模型获得输入的形状。

We have the option of freezing the weight of original architecture or we can train some part of it with our new dataset. Here I have chosen to train some part of the original architecture. For example the following code snippet freezes the weight of the original architecture upto the 5th layer(1st 5 layer).

我们可以选择冻结原始架构的权重,也可以使用新的数据集训练其中的一部分。 在这里,我选择训练原始体系结构的某些部分。 例如,以下代码片段将原始体系结构的权重冻结到了第5层(第1 5层)。

for layer in model.layers[:5]:    layer.trainable = False

The weight of the remaining 43 layers shall change using our training dataset.

其余43层的权重将使用我们的训练数据集进行更改。

Similarly we can create rest part of the architecture. Here we would create a dense layer so that it can be used for classification. To put the features generated by the earlier layers into the dense layer we need to flatten it first. This dense layers would take the output of the inception net as input.

同样,我们可以创建架构的其余部分。 在这里,我们将创建一个密集层,以便将其用于分类。 要将早期图层生成的要素放到密集图层中,我们需要先对其进行展平。 此密集层将初始网络的输出作为输入。

x = model.outputx = Flatten()(x)x = Dense(256,activation = ‘relu’)(x)x = Dropout(0.2)(x)x = Dense(512,activation=”relu”)(x)x = Dropout(0.2)(x)pred = Dense(1,activation=’sigmoid’)(x)

Here we have chosen the activation function as sigmoid as it is a binary classification problem. Using the keras functional api we can define the final model as

在这里,我们选择激活函数为S型,因为它是一个二进制分类问题。 使用keras功能api,我们可以将最终模型定义为

model_final = Model(inputs=model.input,outputs = pred)

To train the model later with fit_generator we need to specify a loss function,an optimizer and a metric to monitor. The following code snippet does the same.

为了稍后使用fit_generator训练模型,我们需要指定损失函数,优化器和要监控的指标。 以下代码段执行相同的操作。

model_final.compile(optimizer=’Adam’,loss=’binary_crossentropy’,metrics=[‘acc’])

Now let us try to understand the fit_generator method. This fit_generator method is really good when the dataset we use is very large. Also this is a really useful when image augmentation is applied on the image. Since during the image data augmentation the database we use is no longer static fit_generator which accepts data in batches is really handy.

现在让我们尝试了解fit_generator方法。 当我们使用的数据集非常大时,这种fit_generator方法非常好。 当在图像上应用图像增强时,这也非常有用。 由于在图像数据扩充期间,我们使用的数据库不再是static fit_generator ,它可以分批接收数据,因此非常方便。

Let us look another parameter of the fit_generator method which is the steps_per_epoch. We have defined as the number of training data points divided the batch size. It is a very important parameter as it tells the model when a new epoch starts. The data generator is supposed to run infinitely which means it has no ability to know when a new epoch starts. So this parameter helps in knowing when a new epoch starts.

让我们看一下fit_generator方法的另一个参数,即steps_per_epoch 。 我们定义为训练数据点的数量除以批次大小 。 这是一个非常重要的参数,因为它告诉模型新的纪元何时开始。 数据生成器应该无限运行,这意味着它无法知道新纪元何时开始。 因此,此参数有助于了解新纪元何时开始。

training_steps=train_generator.n/train_generator.batch_sizeval_steps=validation_generator.n//validation_generator.batch_sizemodel_final.fit_generator(train_generator,steps_per_epoch=training_steps,validation_data=validation_generator,validation_steps=val_steps)

The above code snippet describes the method we discussed to train the model.

上面的代码段描述了我们讨论的训练模型的方法。

Here I have run the model only for one epoch. After that I have got a validation accuracy of 77 percent. By trying different architecture we can achieve better result and accuracy.

在这里,我只运行了一个时期的模型。 之后,我的验证精度为77%。 通过尝试不同的体系结构,我们可以获得更好的结果和准确性。

The link to the whole code can be found at https://github.com/mohantyaditya/Aerial-Cactus-Detection.

整个代码的链接可以在https://github.com/mohantyaditya/Aerial-Cactus-Detection找到。

翻译自: https://medium.com/analytics-vidhya/aerial-cactus-identification-using-transfer-learning-49c7f98e2259

航拍仙人掌识别


http://www.taodudu.cc/news/show-4204387.html

相关文章:

  • 仙人掌的图片识别
  • 13. 中国古代数学家张丘建在他的《算经》中提出了一个著名的“百钱百鸡问题”:一只公鸡值5钱,一只母鸡值3钱,三只小鸡值1钱,现在要用百钱买百鸡,请问公鸡、母鸡、小鸡各多少只?
  • 中国古代数学家张丘建在他的《算经》中提出了著名的“百钱买百鸡问题”:鸡翁一,值钱五,鸡母一,值钱三,鸡雏三,值钱一,百钱买百鸡,问翁、母、雏各几何?
  • 第十三题:中国古代数学家张丘建在他的《算经》中提出了一个著名的“百钱百鸡问题”:一只公鸡值5钱,一只母鸡值3钱,三只小鸡值1钱,现在要用百钱买百鸡,请问公鸡、母鸡、小鸡各多少只?
  • 中国古代数学家张丘建在他的《算经》中提出了一个著名的“百钱百鸡问题”:一只公鸡值5钱,一只母鸡值3钱,三只小鸡值1钱,现在要用百钱买百鸡,请问公鸡、母鸡、小鸡各多少只?
  • python算法1.5百钱百鸡
  • 百钱买百鸡,​ 我国古代数学家张丘建在《算经》一书中提出的数学问题:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。​ 百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?
  • The Fun Of Algorithm - Day4 - 百钱百鸡问题
  • 我国古代数学家张丘建在《算经》一书中曾提出过著名的“百钱买百鸡”问题,该问题叙述如下: 鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一;百钱买百鸡,则翁、母、雏各几何?
  • java请输入第一个人,Java-每日编程练习题③
  • 【附源码】计算机毕业设计JAVA中国历史网站
  • 【C++】公元前五世纪,我国古代数学家张丘建在《算经》一书中提出了“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?请设计一个“高效”的算法求解。
  • 由祖冲之圆周率洞悉——古中国数学家的计算力真是惊人
  • 中国古代数学家张丘建在他的《算经》中提出了一个著名的“百钱百鸡问题”:一只公鸡值五钱,一只母鸡值三钱,三只小鸡值一钱,现在要用百钱买百鸡,请问公鸡,母鸡,小鸡各多少只?
  • 割圆术c语言程序设计,组图:千古绝技 中国古代数学家的割圆术
  • 6.17 C语言练习(百钱百鸡问题:中国古代数学家张丘建在他的《算经》中提出了著名的“百钱买百鸡问题”:鸡翁一,值钱五,鸡母一,值钱三,鸡雏三,值钱一,百钱买百鸡,问翁、母、雏各几何?)
  • SEM纳米颗粒图像粒径分析 基于ImageJ
  • 四象限法推导lm曲线_SEM数据分析四象限方法
  • 失效分析
  • SEM测试功能
  • SEM数据分析之做好关键词报告
  • SEM代码篇----R详细实现(SEM 2)
  • SEM测试优点与特点
  • SEM数据该如何分析?
  • SEM推广,如何做客户心理分析呢?
  • sem常用的数据分析方法有哪些
  • 怎样共享苹果Mac上的 Wi-Fi 密码?
  • mac 设置优先连接的wifi
  • iPhone共享WIFI密码到Macbook - 无需在Mac上使用WIFI万能钥匙
  • macos修改WIFI共享功能的默认网段

航拍仙人掌识别_使用转移学习识别空中仙人掌相关推荐

  1. 利用深度学习进行交通灯识别_通过深度学习识别交通信号灯

    利用深度学习进行交通灯识别 by David Brailovsky 戴维·布雷洛夫斯基(David Brailovsky) 通过深度学习识别交通信号灯 (Recognizing Traffic Lig ...

  2. 验证码识别 java 深度学习_使用深度学习识别验证码注解

    前言 在抓取一些网站的时候难免会遇到一些验证码.想起去年接触过一段时间的验证码识别技术,所以把之前使用的开源的cnn识别再拿出来做个注解.加深理解,也方便以后的使用.希望能对大家有所帮助! 正文 网上 ...

  3. 深度学习 场景识别_使用深度学习进行自然场景识别

    深度学习 场景识别 Recognizing the environment in one glance is one of the human brain's most accomplished de ...

  4. bp神经网络数字识别matlab_卷积神经网络学习识别手写数字时的可视化

    观看此神经网络了解在整个模型训练中可视化卷积层激活 Image by Sian Molloy 警告,该文章有不少大尺寸的图. 动机 与其他机器学习技术相比,深度学习的主要优势在于它能够自动学习输入数据 ...

  5. ocr语种识别_利用OCR图文识别,快速帮你提取文字信息

    我们在浏览网页.读书的时候,经常找到我们感兴趣的资料,有时候一些纸质文字或图片是无法复制保存的,那么为了方便这类信息的提取.编辑保存,中安未来特研发了OCR图文识别技术: 中安未来OCR图文识别技术是 ...

  6. 什么叫侧面指纹识别_哪种指纹识别方式好?侧边指纹识别可能会成为主流

    我以前没有用过背面的指纹.从手机到现在,前置解屏都是一个被认为是理所当然的,甚至升级也应该是屏幕下的指纹.然而,有了小米8,突然觉得指纹解锁实际上不是一个非常重要的问题.首先,如果是前置指纹解屏的话, ...

  7. ocr 超时小票识别_票总管-发票识别核验利器

    发票在我们生活中扮演者十分重要的角色,发票是我们进行消费的凭证,也是我们进行报销的有力工具.然而随着生活水平的不断提升,发票种类的增多,给公司财务报销带来严重的负担.如何对公司发票有效分类则是另财务头 ...

  8. 用python做一个车牌识别_如何用 Python 识别车牌

    车牌识别在高速公路中有着广泛的应用,比如我们常见的电子收费(ETC)系统和交通违章车辆的检测,除此之外像小区或地下车库门禁也会用到,基本上凡是需要对车辆进行身份检测的地方都会用到. 简介 车牌识别系统 ...

  9. 人脸识别与膜虹识别_指纹、人脸识别、虹膜识别,告诉你谁才是黑科技

    [华强智慧网讯] 随着物联网应用逐渐丰富,生物识别技术迎来了大显身手的机会--这很容易理解,在万物互联的时代,数据安全重要性不言而喻,市场需要一种更加靠谱的与机器进行交互的方式,生物识别技术能担当这一 ...

最新文章

  1. 帕斯卡三角形(Pascal's triangle)
  2. RDKit | 从ChEMBL数据库提取大分子HELM单体(XML转换为DataFrame并搜索部分结构)
  3. 汉字的理据与造字取向
  4. C语言的time函数
  5. python流程控制-python简单流程控制
  6. photoshop基础教程视频-贺叶铭-传智播客-笔记
  7. OS_CORE.C(3)
  8. HIbernate实现增、删、改、查。
  9. 完全相同的4个小矩形如图所示放置_分享 | 你想知道的100个桥梁知识点!
  10. android studio真机调试失败,【Android】Android Studio真机调试的问题统整
  11. php文件代码格式化,php代码格式化工具(phpCodeBeautifier)
  12. 总结——达内视频(二)
  13. IT,大一,这里我有点建议
  14. 【大数据语言】怎样利用Python爬虫,高效获取大规模数据
  15. matlab画直方图并拟合泊松分布,将泊松分布拟合为数据(直方图+直线)
  16. git 使用代理加速
  17. Zotero+坚果云的文献二三事
  18. Kafka 发送消息 Idempotent -- Spring 整合
  19. 智能手机怎么玩java游戏_智能手机可以在普通手机上玩Java游戏吗?
  20. 【ASM】ASM基础知识

热门文章

  1. CCF BDCI大赛急速报名,OneFlow四大训练赛题等你来战
  2. org.dom4j.Document的主要用法
  3. 解决微擎人人商城分销中心无法生成推广二维码、商品二维码的问题
  4. MMD->Unity一站式解决方案
  5. 云呐|fsu动环监控维修,fsu动环监控单元是什么
  6. 租车汽车租赁系统开发
  7. 成功安装ubuntu一些东西
  8. ThreadPoolExecutor(四)——Interrupt
  9. git服务器更换IP地址后本地仓库设置
  10. iptables 一些命令