选自
作者:
参演:韩芳、王淑婷
卷积神经网络可以算是深度神经网络中非常流行的网络。本文从基础开始,介绍了卷积网络的基本原理以及其他相关技术,并利用卷积网络做了一个简单的项目作为示例参考。想要购买CNN的朋友不要错过哦~
首先,我们看一下下面的照片:
图片来源:
这不是真实的照片。您可以创建一个新窗口来打开它,放大并查看马赛克。
这张照片居然是AI生成的,是不是看起来很真实?
亚历克斯和朋友们公布这项技术才过去了七年。这是一项每年举办一次的大型图像识别竞赛,可识别从阿拉斯加雪橇犬到卫生纸应用等 1000 多个类别。后来他们又创造了一个,并以遥遥领先第二名的成绩赢得了比赛。
这项技术就是卷积神经网络。它是深度神经网络的一个分支,特别擅长处理图像。
图片来源:
上图是多年来赢得挑战的软件产生的错误率。可以发现,2016年错误率下降到了5%,已经超越了人类水平。
深度学习的引入更多的是打破规则而不是改变规则。
卷积神经网络架构
那么问题来了,卷积神经网络是如何工作的呢?
卷积神经网络之所以优于其他深度神经网络,是由于其特殊的运算。 CNN 不是一次只计算图像中的单个像素,而是组合来自多个像素(例如上图中的 3*3 像素)的信息,因此能够理解时间模式。
此外,CNN可以“看到”一组像素组合成直线或曲线。由于深度神经网络通常是多层卷积的堆叠,通过上一层得到一条直线或曲线后,下一层不再将像素组合起来,而是将线条组合成形状,逐层进行,直到一张完整的图片。
深度卷积神经网络图来自
要深入理解CNN,你需要学习很多基础知识,比如什么是,什么是层。但现在有很多优秀的开源项目,你可以直接基于它们来学习和利用。
这就引入了另一种技术——迁移学习。
迁移学习
迁移学习使用经过训练的深度学习模型来学习特定任务。
例如,如果您在火车调度公司工作,您希望在不增加劳动力的情况下预测火车是否会晚点。
你绝对可以使用网上的卷积神经网络模型,比如2015年的冠军。用火车图片重新训练网络,相信我,你不会对结果感到失望。
迁移学习有两个主要优点:
图像分类到图像生成
通过迁移学习,出现了许多有趣的想法。既然我们可以处理图像并识别图像中的信息,为什么我们不自己生成图像呢?
因为斯汀!
生成对抗网络由此应运而生。
朱俊彦等人提出。
给定一定的输入,该技术可以生成相应的图像。
如上图所示,可以根据一幅画生成对应的真实照片,可以根据草图生成背包的照片,甚至可以进行超分辨率重建。
超分辨率生成对抗网络
太棒了,对吧?
当然,您可以学习构建这些网络。但如何开始呢?
卷积神经网络教程
首先你要知道,上手很容易,但掌握却没那么容易。
让我们先从基础开始。
图片来源:上
航拍仙人掌鉴定
在这个学习项目中,您的任务是识别航拍图像中是否存在柱状仙人掌。
是不是看起来非常简单呢?
提供了 17,500 张图像,其中 4,000 张未标记为测试集。如果你的模型能够正确标记 4000 张图像,它将获得 1 或 100% 的满分。
找了很久,终于找到了下面这个非常适合初学者的项目。
仙人掌
此图像与上面的图像类似。它的尺寸为 32*32,带或不带柱状仙人掌。因为是航拍,所以包含了各种角度。
那么你需要什么?
构建一个卷积神经网络
是的,-深度学习中最流行的语言。至于深度学习框架,你有很多选择,你可以一一尝试:
,最流行的深度学习框架,由 工程师构建,拥有最多的贡献者和粉丝。由于社区比较大,当你遇到问题时可以很容易找到解决方案。他们的高级 API keras 在初学者中非常受欢迎。
,我最喜欢的深度学习框架。因此,纯实现继承了各种优点和缺点。开发人员可以轻松上手。它也有提供抽象的库,就像 Keras 一样。
MXNet,一个开发的深度学习框架。
, 的前身。
CNTK,微软开发的深度学习框架。
本教程中使用的是我最喜欢并使用过的。
在开始之前,您需要安装它。浏览官方网站并下载您需要的版本。你需要确保的是你必须使用3.6+版本,否则你需要使用的一些库将不被支持。
现在,打开命令行或终端并安装以下库:
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">pip install numpy <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />pip install pandas <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />pip install jupyter<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>Numpy 用于存储输入图像、处理 CSV 文件和编码。
然后,去官网下载需要的版本,如果想加快训练速度,就安装CUDA版本,且版本至少为1.0以上。
完成上述操作后,安装并:
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">pip install torchvision <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />pip install fastai<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>运行命令,打开,它将打开一个浏览器窗口。
现在所需的环境已经配置完毕,让我们开始吧。
准备数据
导入所需代码:
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;"><span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">import</span> numpy <span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">as</span> np<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /><span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">import</span> pandas <span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">as</span> pd <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /><span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">from</span> pathlib <span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">import</span> Path <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /><span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">from</span> fastai <span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">import</span> * <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /><span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">from</span> fastai.vision <span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">import</span> * <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /><span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">import</span> torch <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />%matplotlib inline<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>基本上任何任务都需要 Numpy。 Torch 是您的深度学习库。用于显示图表。
您可以从下方大赛官网下载数据。
解压缩 zip 文件并将其放入文件夹中。
假设你的名字叫仙人掌。您的文件夹结构将如下所示:
Train 文件夹包含所有训练图像。
Test 文件夹用于存放提交的测试图像。
Train CSV 文档包含训练数据信息,将图像名称映射到列。如果该列存在,则值为 1,否则为 0。
提交所需的格式为 CSV。文件名与 Test 文件夹中的图像相对应。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">train_df = pd.read_csv(<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">"train.csv"</span>)<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>将训练 CSV 文档加载到数据框中。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">data_folder = Path(<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">"."</span>) <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />train_images = ImageList.from_df(train_df, path=data_folder, folder=<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">'train'</span>)<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>使用将数据帧映射到训练文件夹中的图像的方法创建负载生成器。
数据增强
这是一种从现有数据创建更多数据的技术。猫的图片水平翻转后仍然是猫的图片。但通过这样做,您可以将数据增加一倍、四倍甚至 16 倍。
如果你的数据量不大,可以尝试这个方法。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">transformations = get_transforms(do_flip=<span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">True</span>, flip_vert=<span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">True</span>, max_rotate=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">10.0</span>, max_zoom=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">1.1</span>, max_lighting=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">0.2</span>, max_warp=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">0.2</span>, p_affine=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">0.75</span>, p_lighting=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">0.75</span>)<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>提供了执行这些操作的函数。您可以通过水平翻转、垂直翻转、旋转、放大、增加亮度/亮度或添加仿射变换来增强数据。
您可以使用我上面提供的参数来尝试图片的外观。或者你可以详细阅读官方文档。
然后,对图像序列进行上述预处理。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">train_img = train_img.transform(transformations, size=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height:
参数大小将用于放大或缩小输入以匹配您将使用的神经网络。我使用的网络是2017年最佳论文奖的成果。需要输入的图片尺寸为128*128。
准备训练
看完数据,我们就来到了深度学习最关键的一步——训练。这个过程也是深度学习中学习的起源。网络从您的数据中学习,并根据学习的结果调整其参数,直到获得更好的数据结果。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">test_df = pd.read_csv(<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">"sample_submission.csv"</span>) <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />test_img = ImageList.from_df(test_df, path=data_folder, folder=<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">'test'</span>)<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />train_img = train_img <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /> .split_by_rand_pct(<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">0.01</span>) <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /> .label_from_df() <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /> .add_test(test_img) <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /> .databunch(path=<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">'.'</span>, bs=<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">64</span>, device=torch.device(<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">'cuda:0'</span>)) <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /> .normalize(imagenet_stats)<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>
在训练步骤中,需要将训练数据分成一小部分作为验证集。您不能使用此数据进行训练,因为它仅用于验证。当你的卷积神经网络在验证集上表现良好时,它很可能也可以在测试集上提交更好的结果。
提供了方便上述操作的函数。
函数可以进行批处理。由于GPU内存限制,我的batch size是64。如果你没有GPU,请忽略这个参数。
之后,由于您使用的是预先训练的网络,因此请使用该函数对图像进行归一化。该函数根据预训练模型的训练方式对输入图像进行标准化。
将测试数据添加到训练数据列表中可以使以后的预测更加容易,从而无需进行额外的预处理。请记住,这些图像不能用于训练或验证。这只是为了确保训练图像和测试图像以完全相同的方式进行预处理。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">learn = cnn_learner(train_img, models.densenet161, metrics=[error_rate, accuracy])<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>目前数据准备工作已经完成。现在,使用 来创建一个训练器。如上所述,我将其用作预训练网络。当然,您也可以选择其他提供的网络。
单循环技术
现在您可以开始训练了。然而,包括卷积神经网络在内的深度学习训练中的一个大问题是如何选择正确的学习率。学习率决定了梯度下降过程中更新参数时误差减少的程度。
如上图所示,较大的学习率使得训练过程更快,但更容易错过误差边界,甚至跳出可控范围而无法收敛。然而,当使用稍小的学习率时,训练过程会变慢但不会发散。
因此,选择合适的学习率非常重要。我们想要找到足够大的正确学习率而不会使训练发散。
但这说起来容易做起来难。
因此,一个名叫史密斯的人提出了单期策略。
简单来说,就是先暴力搜索几种不同的学习率,然后选择最接近最小误差但仍有改进空间的。代码如下:
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">learn.lr_find() <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />learn.recorder.plot()<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>您将得到以下输出:
最小误差值在10^-1,所以我们可以使用比这个值稍小的学习率,比如3*10^-2。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">lr = <span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">3e-02</span> <br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />learn.fit_one_cycle(<span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">5</span>, slice(lr))<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>训练几个epoch(这里我选择5个,不太大也不太小)并查看结果。
等等,这是怎么回事? !
验证集准确率达到100%!训练过程其实非常高效,只用了六分钟。这是多么大的祝福啊!在实践中,您可能需要多次迭代才能找到正确的算法。
我等不及要提交了!哈哈。让我们预测并提交测试集结果。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">preds,_ = learn.get_preds(ds_type=DatasetType.Test) test_df.has_cactus = preds.numpy()[:, <span class="hljs-number" style="box-sizing: border-box;font-size: inherit;color: rgb(174, 135, 250);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">0</span>]<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>由于测试图像之前已放入训练图像列表中,因此无需对测试图像进行预处理。
<p style='margin-bottom:15px;color:#555555;font-size:15px;line-height:200%;text-indent:2em;'> <pre style="box-sizing: border-box;font-size: 16px;color: rgb(62, 62, 62);line-height: inherit;text-align: start;background-color: rgb(255, 255, 255);"><code class="python language-python hljs" style="box-sizing: border-box;margin-right: 2px;margin-left: 2px;padding: 0.5em;font-size: 14px;color: rgb(169, 183, 198);line-height: 18px;border-radius: 0px;background: rgb(40, 43, 46);font-family: Consolas, Inconsolata, Courier, monospace;display: block;overflow-x: auto;letter-spacing: 0px;overflow-wrap: normal !important;word-break: normal !important;overflow-y: auto !important;">test_df.to_csv(<span class="hljs-string" style="box-sizing: border-box;font-size: inherit;color: rgb(238, 220, 112);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">'submission.csv'</span>, index=<span class="hljs-keyword" style="box-sizing: border-box;font-size: inherit;color: rgb(248, 35, 117);line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">False</span>)<br style="box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" /></code></pre></p>上面的代码行将创建一个 CSV 文件,其中包含 4000 个测试图像的名称以及每个图像是否包含仙人掌标签。
当我尝试提交时,我发现CSV需要通过core提交,这是我之前没有注意到的。
图片来源:
幸运的是,核心的运行方式非常相似。您可以完全复制并粘贴您在此处创建的内容并提交。
然后,Duang~完成了!
我的天啊!分数结果是0.9999,已经非常不错了。当然,如果你第一次就得到这么好的成绩,应该还有改进的空间。
于是,我调整了网络结构,再次尝试。
得分1!我做到了! !所以你也可以,其实没那么难。
(另外,这个排名是从4月13日开始的,所以我的排名现在可能已经下降了......)
我学到了什么
这个项目非常简单,在解决任务的过程中不会遇到任何奇怪的挑战,所以这个项目非常适合入门。
而且由于很多人已经取得了满分,我认为组织者应该创建另一个测试集来提交,最好是难度更高的测试集。
不管怎样,上手这个项目基本上没有什么难度。您可以立即尝试并获得高分。
资料来源:马里奥·姆拉德
卷积神经网络对于各种不同的任务都有效,无论是图像识别还是图像生成。分析图像并不像以前那么困难。当然,只要你尝试,你就可以做到。
所以,选择一个好的卷积神经网络项目,准备高质量的数据,然后开始吧!
原文链接:
# 杭州抖音seo公司如何
# 您将
# 南皮互联网营销广告推广
# 坪山网站自动优化哪家强
# 品牌网站建设推进方案
# 网站优化合同法
# 莆田seo抖音搜索排名
# 乐平综合网站建设哪家好
# 山西响应式网站建设外包
# 洛阳优化网站建设
# 行业网站建设功能
# 您需要
# 郑州快手营销推广
# 衡阳俄语网站推广公司
# 江苏网站建设文案模板
# seo网站推广与搜索引擎优化
# 房山区省电网络营销推广
# 律师 推广 网站
# 五河网站建设哪家好
# 衡阳seo优化工作报价
# 食品城营销推广
# 西安关键词排名前十最专业
# 这是
# 卷积神经网络(CNN)入门指南
# 从基本原理到实战项目示例
# 您可以
# 的是
# 您的
# 柱状
# 你可以
# 让我们
# 所需
# 所示
# 卷积神经网络(CNN)入门指南:从基本原理到实战项目示例
# 创建一个
# 多个
# 很容易
# 我们可以
# 最喜欢
# 训练器
# 您在
# 文档
# 可以根据
相关文章:
在联盟上推广产品成功赚钱的四种方式!
新手做广告联盟广告推广赚钱的几个注意事项!
惊掉下巴!趣头条严查广告联盟代理商,*广告也敢放!
怎么看以前的聊天记录?这些查看微信聊天记录的方法请收好 如何摆脱恶意网站推广员
化妆品批文办理、报关及标签制作全流程解析!报关价格500/票 有哪些外贸网站推广的书
微信聊天背景图怎么设置?3d建模相关操作步骤来啦
如何做好广告营销推广?广告营销推广的4个有效方法!
广告投放花钱也要花得值,效果才是花钱投广告的目的!
广告推广怎么做比较好?推广的应用场景和产品分析!
来推广告联盟为您揭露网上兼职骗局套路,防止入坑!
3种非常火爆的APP推广方法以及实用小技巧分享!
竞价广告该如何投放,有什么技巧可借鉴的?
微信营销新玩法之#话题标签引流吸粉玩法分享!
网站不同时期的SEO网络推广计划,该如何制定? 0755seo
盘龙70秒短视频大赛开通抖音投稿渠道,万元大奖等你拿 曰韩网站推广流程
网赚赚钱项目的本质到底是什么?
社交app推广引流的6大方式
如何鼓励联盟营销的伙伴来推广我们的商品以及服务?
下班后做什么赚钱项目可以日赚500+?我来告诉你!
【收藏】分享10个普通人可以操作的有效引流方法
如何做好微信营销?只需要做好这几步就可以了!
十大实用且有效的网站赚钱常见方法!你知道几个?
英国委托书公证认证如何办理?快速流程及注意事项全解析 单个关键词优化排名做法
国外广告联盟很赚钱,为什么却很少人做?
送给客户的早安问候语,温暖舒心缩短情感距离 深圳便宜的网站优化方式
百青藤广告联盟的优势以及不足分析!
现代职场加班管理难题待解!如何用记录佐证事实? 河源湖南网站建设
qq群营销技巧有哪些?如何做好qq群营销实现精准引流?
利用SEO关键词排名和单页网站日赚500+的实战经验分享!
网站主动引流推广赚钱该怎么做?这6个方法简单又实用!
教你一个日赚500+的广告推广方法,另类游戏推广!
介绍8个非正规的app推广引流方式
网站营销之seo优化排名的好处以及如何提升转化效果
网站赚钱之通过投放、CPC、广告的广告联盟赚钱玩法说明
相亲粉、交友粉、引流思路分享,这么做快速有效!
电商领域SEO革新:从流量争夺到全链路营销效能跃升 怀远网站推广
广告投放怎么做?互联网广告投放方式都有哪些?
新手所必须了解的推广赚钱的5大主流推广方式!
广告推广赚钱是什么意思?怎么做?
开发完app之后,app运营推广应该这么做!
注册推广月入过万项目玩法介绍,十足的干货!
如何通过建立个人博客网站推广联盟产品赚钱呢?
广告推广怎么做最有效?5个最有效的线上推广方式分享!
想做国外问卷调查赚钱,你的明确这3个问题!
今晚播出!秋季开学季·安全自护第一课内容有哪些? 新郑市网站推广平台
app促活怎么做?app促活的三个小技巧!
app推广怎么做更好?app产品的5个营销思路!
做赚钱有这么多好处,赶紧来看看!
同城服务类APP推广引流实操干货分享!
微博推广营销的过程中有什么注意事项?如何做好微博推广?
相关栏目:
【
广告资讯90366 】
【
广告推广18483 】
【
广告优化154267 】
【
广告营销46464 】