选自

作者:
参演:韩芳、王淑婷
卷积神经网络可以算是深度神经网络中非常流行的网络。本文从基础开始,介绍了卷积网络的基本原理以及其他相关技术,并利用卷积网络做了一个简单的项目作为示例参考。想要购买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: inherit;overflow-wrap: inherit !important;word-break: inherit !important;">128</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>参数大小将用于放大或缩小输入以匹配您将使用的神经网络。我使用的网络是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日开始的,所以我的排名现在可能已经下降了......)
我学到了什么
这个项目非常简单,在解决任务的过程中不会遇到任何奇怪的挑战,所以这个项目非常适合入门。
而且由于很多人已经取得了满分,我认为组织者应该创建另一个测试集来提交,最好是难度更高的测试集。
不管怎样,上手这个项目基本上没有什么难度。您可以立即尝试并获得高分。
资料来源:马里奥·姆拉德
卷积神经网络对于各种不同的任务都有效,无论是图像识别还是图像生成。分析图像并不像以前那么困难。当然,只要你尝试,你就可以做到。
所以,选择一个好的卷积神经网络项目,准备高质量的数据,然后开始吧!
原文链接:
# 卷积神经网络(CNN)入门指南:从基本原理到实战项目示例
# 卷积神经网络(CNN)入门指南
# 从基本原理到实战项目示例
# 您可以
# 的是
# 您的
# 柱状
# 你可以
# 让我们
# 所需
# 所示
# 这是
# 创建一个
# 多个
# 很容易
# 我们可以
# 最喜欢
# 训练器
# 您在
# 文档
# 可以根据
# 您需要
# 您将
# 天猫关键词搜索排名掉了
# 世界读书日营销推广活动
# 优化静态网站
# seo毛利率
# 万华地产营销推广活动
# 发文网站推广文案
# 做seo网站营销推广怎么样
# 预估seo收录量
# 72街品牌营销推广
# 外贸独立站seo公司
# 免费seo学习
# 保山定制网站建设
# 晋州专业网站推广方案
# 安宁ai营销推广方案设计
# 南山网络seo优化公司
# 网站建设h 5
# 天津销售行业网站推广
# 甘孜藏族网站建设推广
# 常州抖音seo运营
# seo收割流量
相关文章:
广告联盟上推广的产品,广告产品和广告产品哪种更赚钱?
优采云:推动企业采购智能化的行业革新者,宁波快速网站建设
如何选择合适的网站建设空间,如何选择合适的网站建设空间,指南与建议
什么是广告推广?赚钱该怎么做?
联盟行业未来想要持续健康发展该如何去做?
推广的常见的4个另类做法,你是不是也实验过?
福建百度推广预算,一天需要多少?,高效精准营销推广哪里有
做微信营销推广,这5大铁律要时刻牢记!
免费分享一个付费才能学到的推广赚钱项目
共创小助手:赋能团队创新与协作的全新利器,园区关键词排名策划
关键词出词:打造精准内容的秘密武器,怎么把分词变成seo
SEO好吗?助力网站成功的关键之道,众筹网站建设哪家好
怎么把流量变现?10个流量变现方法介绍!
超实用的手机APP试玩赚钱项目玩法分享!
九江网站建设,助力企业互联网转型升级的关键一步,九江企业互联网转型升级的加速器,专业网站建设服务
优化平台:让数字化转型更简单、更高效,徐汇抖音seo招商公司
SEO需要:如何提升网站排名,打造高效营销利器,随州网站推广公司
几个在家就可以赚钱的网上赚钱项目,日赚500不是问题!
2021年网上赚钱方法有哪些?这四个最值得做!
做好了这四步,网络赚钱轻轻松松!
造成网络营销效果不理想的五大误区!
从“官网扒下来”看企业数字化转型的未来,建材行业全网推广营销
优化公司:助力企业腾飞的秘密武器,眉山58同城网站建设
SEO难吗?揭秘SEO背后的真相,让你轻松上手!,长沙营销推广咨询电话
网站赚钱之通过投放、CPC、广告的广告联盟赚钱玩法说明
SEO留痕:数字营销的隐性力量,如何通过SEO优化让品牌更具竞争力,泉州百度移动seo
七个零成本引流的app推广运营技巧,让目标用户主动来访!
SEO精通:让你的内容在搜索引擎中脱颖而出,佛山专业网站建设报价
SEO领站-从零到一打造成功网站排名的秘密,汕尾东莞网站推广
谷歌、阿里妈妈、京东这三家广告联盟平台各自有哪些优势?
优化文字,让表达更精准:提升写作效率的关键,科普网站资源建设
手机赚钱软件有哪些?想通过手机赚钱这10款软件千万不容错过!
cpc广告怎么做才能达到最好的效果?6大cpc广告操作技巧分享!
娱乐型网站和专业型网站做广告联盟推广有什么差别?
SEO软优化:助力网站实现流量爆发的秘密武器,咖啡包装网站推广方法
亚马逊CPC广告投放你不得不知的几个知识点!
伪文章:互联网时代的营销神器,打造品牌的全新突破口,seo 推广排名
SEO使用:如何让你的网站轻松登顶搜索引擎排名,来个网站建设公司推荐
什么是蜘蛛弛?揭秘这个SEO优化背后的神秘工具,宝鸡网站建设网站制作
关键词定位:精准营销的核心利器,让你一招制胜!,金华抖音关键词搜索排名怎么投放
免费发外链,提升网站排名的利器!,优化亚马逊关键词自然排名
SEO笔记:如何打造高效的SEO策略提升网站排名,企业网站优化网站推广
探索自媒体营销的奥秘,从SEO教学反思中汲取智慧,广州seo软件很棒乐云seo专家
SEO建议:如何通过优化提升网站流量,赢得市场竞争,优化网站价格策略研究
关键SEO:提升网站流量与排名的核心策略,小程序智慧营销系统推广
关键效果:如何通过聚焦核心要素,突破瓶颈,创造卓越成就,营销和定向计划怎么推广
无锡网站 *** ,打造个性化企业网站,助力企业腾飞,无锡专业网站定制,塑造企业品牌新形象,无锡专业网站定制,助力企业品牌形象升级
SEO外,如何提升网站整体营销效果?,沈阳企业网站推广服务
SEO是什么意思?揭秘SEO的真正含义与重要性,怀柔区营销网络推广介绍
秀场|直播|在微信*号上进行|直播|将成为一种可能?
*请认真填写需求信息,我们会在24小时内与您取得联系。