深度学习狗图片

深度学习 (Deep Learning)

Stuck behind the paywall? Click here to read the full story with my friend link!

卡在收费墙后面? 单击此处 ,与我的朋友链接阅读完整的故事!

According to dogtime.com, there are 266 different breeds of dogs, and by alone thinking about this number, it frightens me to distinguish them. And most of the people, if they’re normal, just know about 5–10 breeds because you don’t see the chapter “266 Different Dog Breeds” in a Bachelor’s Curriculum.

根据dogtime.com的资料 ,有266种不同的狗,单单思考这个数字,我就难以区分它们。 而且大多数人,如果他们是正常人,只知道大约5-10个品种,因为您不会在学士课程中看到“ 266种不同的犬种”一章。

总览 (Overview)

The main aim of this project is to build an algorithm to classify the different Dog Breeds from the dataset.

该项目的主要目的是建立一种算法,以从数据集中对不同的犬种进行分类。

This seems like a simple task but when we think of Machine Learning, then it is not! The Images are in random order, having dogs at random spaces in the images, the images are shot in different lightenings, there is no preprocessing done on the data, it’s just a dataset containing simple dogs pictures.

这似乎是一个简单的任务,但是当我们想到机器学习时,事实并非如此! 图像以随机顺序排列,在图像中的随机空间处有狗,图像以不同的亮光拍摄,没有对数据进行任何预处理,而只是一个包含简单狗图像的数据集。

So, the first step is to give the dataset a look.

因此,第一步是给数据集一个外观。

环境与工具 (Environment and tools)

  • scikit-learn

    scikit学习

  • Keras

    凯拉斯

  • numpy

    麻木

  • Pandas

    大熊猫

  • matplotlib

    matplotlib

数据 (Data)

The Dataset used for this project is Stanford Dogs Dataset. The Dataset contains a total of 20,580 images of 120 different dog breeds.

该项目使用的数据集是Stanford Dogs数据集 。 数据集包含120种不同犬种的20580张图像。

The Stanford Dogs dataset contains images of 120 breeds of dogs from around the world. This dataset has been built using images and annotation from ImageNet for the task of fine-grained image categorization.

斯坦福犬数据集包含来自世界各地的120种犬的图像。 此数据集是使用ImageNet的图像和注释构建的,用于精细图像分类。

导入库 (Importing Libraries)

import osimport sysimport kerasimport tarfileimport numpy as npimport tensorflow as tfimport matplotlib.pyplot as pltfrom keras.models import Sequentialfrom keras.engine.training import Modelfrom sklearn.preprocessing import LabelBinarizerfrom keras.preprocessing.image import ImageDataGeneratorfrom keras.layers import Add, Dropout, Flatten, Dense, Activation

数据预处理 (Data Preprocessing)

I found 5 directories to be unusable and hence, didn’t used them. So, I imported a total of 115 Breeds.

我发现5个目录不可用,因此没有使用它们。 因此,我总共导入了115种。

import cv2BASEPATH = './Images'LABELS = set()paths = []for d in os.listdir(BASEPATH):LABELS.add(d)paths.append((BASEPATH + '/' + d, d))# resizing and converting to RGBdef load_and_preprocess_image(path):image = cv2.imread(path)image = cv2.resize(image, (224, 224))image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)return imageX, y = [], []i = 0for path, label in paths:i += 1# Faulty Directoriesif i == 18 or i == 23 or i == 41 or i == 49 or i == 90: continue if path == "./Images/.DS_Store": continuefor image_path in os.listdir(path):image = load_and_preprocess_image(path + "/" + image_path)X.append(image)y.append(label)

Now, the names of the folder are in this pattern ‘n8725563753-Husky’, hence, we need to clean this up to be left with the ‘Husky’ part of the name.

现在,该文件夹的名称采用此模式'n8725563753-Husky' ,因此,我们需要清理该文件夹,以保留名称中的'Husky'部分。

Y = []# Cleaning the names of the directories/targetsfor i in y:Y.append(i.split('-')[1])

标签二值化器 (Label Binarizer)

This dependency is from sklearn.preprocessing and is used to get a binary representation of strings. Why are we using this here? We can’t use ‘Husky’ as the target in a model, we need to convert it into a usable data type, numeric. Hence, we use this.

此依赖项来自sklearn.preprocessing ,用于获取字符串的二进制表示形式。 我们为什么在这里使用它? 我们无法将“ Husky”用作模型中的目标,我们需要将其转换为可用的数据类型numeric 。 因此,我们使用它。

encoder = LabelBinarizer()y = encoder.fit_transform(np.array(y))

分割数据 (Splitting Data)

We are using the train_test_split dependency from sklearn.model_selection.

我们正在使用sklearn.model_selection中的train_test_split依赖

train_test_split is a function in Sklearn model selection for splitting data arrays into two subsets: for training data and for testing data. With this function, you don't need to divide the dataset manually.

train_test_splitSklearn模型选择中的一个函数,用于将数据数组分为两个子集 :用于训练数据和用于测试数据。 使用此功能,您无需手动划分数据集。

By default, Sklearn train_test_split will make random partitions for the two subsets. However, you can also specify a random state for the operation.

默认情况下,Sklearn train_test_split将对这两个子集进行随机分区。 但是,您也可以为操作指定随机状态。

from sklearn.model_selection import train_test_splitX = np.array(X)x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.25, random_state=87)

Now, after this, we convert the x_train and x_test sets to ‘float32’ and normalize them.

现在,在此之后,我们将x_trainx_test设置转换为“ float32 ”并将其标准化 。

x_train = x_train.astype("float32") / 255.0x_test = x_test.astype("float32") / 255.0

最初查看数据 (Viewing Data initially)

These are the pictures with which we’ll be making our model learn.

这些是我们将用来使模型学习的图片。

转移学习 (Transfer Learning)

Now, Transfer Learning can be a full topic to be explained on its own, but I’ll just scratch the tip of the iceberg here.

现在,“转移学习”可以是一个完整的话题,可以单独解释,但是在这里,我只涉及冰山一角。

Transfer learning is a machine learning technique where a model trained on one task is re-purposed on a second related task.

转移学习是一种机器学习技术,其中将在一个任务上训练的模型重新用于第二个相关任务。

Why we use Transfer Learning? You don’t want to train a model with millions of nodes, again and again, to use in your projects, hence why you have this concept. The concept of Transfer Learning is that you use a pre-trained model and just retrain some of the layers to adapt it to your requirements.

为什么我们要使用转学? 您不想一次又一次地训练具有数百万个节点的模型以在您的项目中使用,因此为什么会有这个概念。 转移学习的概念是您使用预先训练的模型,而只是重新训练一些层次以使其适应您的需求。

from keras.applications import inception_v3input_size = 224num_classes = 115inception_bottleneck = inception_v3.InceptionV3(weights='imagenet', include_top=False, pooling='avg')temp_train = inception_bottleneck.predict(x_train, batch_size=32, verbose=1)temp_test = inception_bottleneck.predict(x_test, batch_size=32, verbose=1)print('InceptionV3 train bottleneck features shape: {} size: {:,}'.format(temp_train.shape, temp_train.size))print('InceptionV3 test bottleneck features shape: {} size: {:,}'.format(temp_test.shape, temp_test.size))

We set include_top parameter is set to False, which means that we would not import the last layer, Dense layer and we’d use our own layers to adapt the model to our Dataset.

我们设置include_top 参数设置为False,这意味着我们将不导入最后一层Dense层,而将使用我们自己的层使模型适应数据集。

致密层 (Dense Layers)

After this, we add 3 Dense Layers to the model of depths 1024, 512, and 115, number of classes.

此后,我们将3个密集层添加到深度为1024、512和115的类数模型中。

model = Sequential()model.add(Flatten())model.add(Dense(1024, activation='elu'))model.add(Dropout(0.45))model.add(Dense(512, activation='elu'))model.add(Dropout(0.35))model.add(Dense(num_classes, activation='softmax'))

Then, we compile this.

然后,我们对此进行编译。

model.compile(optimizer=’adam’,loss=’categorical_crossentropy’, metrics=[‘accuracy’])

Then, finally train.

然后,最后训练。

history = model.fit(temp_train, Y_train,epochs = 15,batch_size = 32,validation_data = (temp_test, Y_test))

Do you see? We used temp_train and temp_test here instead of x_train and x_test . This is because we wanted to extend our Inception model not to use this Sequential Model to start training from scratch.

你有看到? 我们使用了temp_traintemp_test 在这里而不是x_trainx_test 这是因为我们希望扩展Inception模型,而不是使用此顺序模型从头开始训练。

损失图 (Loss plots)

score = model.evaluate(temp_test, Y_test, verbose=0)print("%s: %.2f%%" % (model.metrics_names[1], score[1]*100))# summarize history for accuracyplt.subplot(211)plt.plot(history.history['accuracy'])plt.plot(history.history['val_accuracy'])plt.title('model accuracy')plt.ylabel('accuracy')plt.xlabel('epoch')plt.legend(['train', 'test'], loc='upper left')# summarize history for lossplt.subplot(212)plt.plot(history.history['loss'])plt.plot(history.history['val_loss'])plt.title('model loss')plt.ylabel('loss')plt.xlabel('epoch')plt.legend(['train', 'test'], loc='upper left')plt.subplots_adjust(right=3, top=3)plt.show()

结果与结论 (Results & Conclusion)

So, after all this, we reached 77.31% accuracy and I’ll be honest, considering the fact that there were 115 different classes, the model did a pretty good job.

因此,毕竟,我们达到了77.31%的准确度,说实话,考虑到存在115个不同的类,该模型做得很好。

可视化结果 (Visualizing results)

for i in range(9):pyplot.subplot(330 + 1 + i)pyplot.xlabel("Actual: " + y_test[i] + ", Predicted: " + results[i])pyplot.imshow(x_test[i], cmap=pyplot.get_cmap('gray'))plt.subplots_adjust(right=3, top=3)pyplot.show()

So, luckily, this is a subset of the data, there is no miss-classification. hehe

因此,幸运的是,这是数据的子集,没有遗漏分类。 呵呵

可以改进的地方 (Improvements that can be made)

I still think that adding one more Dense layer can make a difference and preprocessing the data will surely help but we’ll give it a shot later. :D

我仍然认为,再增加一个“密集”层可以有所作为,对数据进行预处理肯定会有所帮助,但是稍后我们将对其进行介绍。 :D

Alright y’all, I hope this article helps you. Let’s connect on Linkedin!

好的,希望本文对您有所帮助。 让我们在Linkedin上连接!

进一步阅读 (Further Readings)

联络人 (Contacts)

If you want to keep updated with my latest articles and projects follow me on Medium. These are some of my contacts details:

如果您想随时了解我的最新文章和项目,请在Medium上关注我 。 这些是我的一些联系方式:

  • Linkedin

    领英

  • GitHub

    的GitHub

  • Twitter

    推特

Happy Learning. :)

学习愉快。 :)

翻译自: https://medium.com/swlh/deep-learning-for-dog-breed-classification-77ef182a2509

深度学习狗图片


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

相关文章:

  • 机器学习工程师 — Udacity 基于CNN和迁移学习创建狗品种分类器
  • python狗品种识别_使用python+keras来识别狗的品种
  • 【深度学习入门】基于 ResNet50 的狗狗品种识别
  • 狗种类识别
  • 狗的品种识别实战(tf2.0)
  • 【Kaggle项目实战记录】狗的品种识别
  • 基于目标检测的狗品种识别及图像检索
  • 使用深度学习识别狗的品种
  • python狗品种识别_kaggle之本地运行识别狗品种
  • 深度学习—利用TensorFlow2实现狗狗品种品种(resnet50实现)
  • 狗狗分类
  • 狗狗品种中英文翻译
  • 常见狗狗品种大全
  • GooglePlay OAuth使用
  • Redmi Note 9 Pro 5G 换手机重新安装谷歌服务 Google Play
  • Google Play 开发者账户已被终止的通知
  • GooglePlay应用上架完整流程
  • 谷歌play商店_Google Play商店优化的17个技巧
  • 为什么无法运行谷歌play_什么是Google Play积分,以及如何使用它们?
  • 下载谷歌play应用_选择在现有应用中使用Google Play应用签名
  • 谷歌play 数据接口_如何检查,管理和清除Google Play服务存储的数据/缓存
  • Google Play 应用上架流程,谷歌商店上架流程
  • 谷歌商店上架流程_Googleplay 上架流程(2022版)
  • 微信和支付宝子站
  • 如何打开微信dat文件
  • pc网站和手机端h5网站开发接入微信支付
  • Python基于PC版微信实现机器人
  • 微信公众号和同步助手使用
  • 常用企业微信开源SCRM对比
  • 企业微信之——扫码登录

深度学习狗图片_狗品种分类的深度学习相关推荐

  1. python深度学习include框架_《用Python实现深度学习框架》上市

    朋友们,<用Python实现深度学习框架>已经由人民邮电出版社出版上市了.在这本书中,我们带领读者仅用Python+Numpy实现一个基于计算图的深度学习框架MatrixSlow.本书讲解 ...

  2. 基于python的深度学习框架有_《用Python实现深度学习框架》上市

    朋友们,<用Python实现深度学习框架>已经由人民邮电出版社出版上市了.在这本书中,我们带领读者仅用Python+Numpy实现一个基于计算图的深度学习框架MatrixSlow.本书讲解 ...

  3. 深度学习算法原理_用于对象检测的深度学习算法的基本原理

    深度学习算法原理 You just got a new drone and you want it to be super smart! Maybe it should detect whether ...

  4. 深度学习数据扩张_适用于少量数据的深度学习结构

    作者:Gorkem Polat 编译:ronghuaiyang 导读 一些最常用的few shot learning的方案介绍及对比. 传统的CNNs (AlexNet, VGG, GoogLeNet ...

  5. 地质勘查土质分类图片_地质土质分类

    等级: 文件 41KB 格式 doc 内容简介 第一节 土的工程地质分类 一.概述 土的工程地质分类,按其具体内容和适用范围,可以概括的分为三种基本类型 一般性分类:比较全面的综合性分类: 局部性分类 ...

  6. 深度学习课程大纲_一份639页深度学习:Deep Learning硬核课程PPT

    课程名称: Deep Learning 课程地址: https://github.com/glouppe/info8010-deep-learning#info8010---deep-learning ...

  7. 地质勘查土质分类图片_土质的分类表

    土的分类 岩.土名称 开挖方法及工具 一类土(松 软土) 略有粘性的砂土.粉土.腐殖土及疏松的种植土, 泥炭(淤泥) . 用锹.少许用脚蹬或用板锄挖 掘. 二类土(普 通土) 潮湿的粘性土和黄土,软的 ...

  8. 地质勘查土质分类图片_工程土质分类

    土的分类 岩.土名称 开挖方法及工具 一类土 (松软土) 略有粘性的砂土.粉土.腐殖土及疏松的种 植土,泥炭(淤泥). 用锹.少许用脚蹬 或用板锄挖掘. 二类土 (普通土) 潮湿的粘性土和黄土,软的盐 ...

  9. 怎么学习python自动化_会python基础,如何学习自动化办公?

    这个我会! 我也是在有了点python基础之后开始学习自动化办公的,毕竟有时候要处理的表格太烦人了,重复的操作太多,所以我也想到了学习使用python来进行自动化办公. 说到自动化办公.无非就是对一些 ...

最新文章

  1. python批量爬取文档
  2. 影像组学视频学习笔记(9)-T检验(T-test)理论及示例、Li‘s have a solution and plan.
  3. 联邦学习怎样应用在推荐系统中?
  4. BCH的压力测试其实已经开始了
  5. 【图像分割模型】多分辨率特征融合—RefineNet
  6. 【Linux病毒】阿里云+腾讯云服务器的 kdevtmpfsi(H2Miner挖矿蠕虫变种)病毒处理(5个详细步骤)
  7. todolist实现删除的功能_coc-todolist: nvim/vim 的 todolist/task 管理插件
  8. 自定义按键_DNF手游:策划宣布新增自定义按键布局,期待手游新版本的到来
  9. k8s使用helm打包chart并上传到腾讯云TencentHub
  10. 骨髓基质在正常和白血病个体中的细胞图谱|Cell最新(文末有彩蛋)
  11. 最大公约数(Greatest Common Divisor)
  12. 前端一键复制粘贴插件——clipboard.js的使用
  13. Deecamp2019年试题A卷详解和感受
  14. JDBC操作MYSQL数据库
  15. python+django高速公路收费管理系统的设计
  16. 小米8android p慢,给力 小米8青春版获得Android P更新
  17. 计算机主机忘了密码怎么办,如果我忘记了笔记本计算机的开机密码怎么办
  18. 数据库界的《延禧攻略》来了,不看你就输了
  19. 如何写好一个标题?十分钟教你写出优质标题
  20. Ultraedit使用小技巧

热门文章

  1. 实现字典树(前缀树、Trie树)并详解其应用
  2. 【论文阅读】Siamese Neural Network Based Few-Shot Learning for Anomaly Detection in Industrial Cyber-Physi
  3. win32汇编学习的一些摘要
  4. 桌面应用程序UI框架有哪些
  5. 智能餐厅摆动手势点餐人脸识别支付
  6. Java毕设项目电力公司员工安全培训系统(java+VUE+Mybatis+Maven+Mysql)
  7. 【题】【贪心】NKOJ3827 火车运输
  8. 2021-01-19
  9. 真牛!一个Android应届生从上海离职,挥泪整理面经
  10. css3多米诺骨牌动画特效