选自

作者:
参演:韩芳、王淑婷
卷积神经网络可以算是深度神经网络中非常流行的网络。本文从基础开始,介绍了卷积网络的基本原理以及其他相关技术,并利用卷积网络做了一个简单的项目作为示例参考。想要购买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日开始的,所以我的排名现在可能已经下降了......)
我学到了什么
这个项目非常简单,在解决任务的过程中不会遇到任何奇怪的挑战,所以这个项目非常适合入门。
而且由于很多人已经取得了满分,我认为组织者应该创建另一个测试集来提交,最好是难度更高的测试集。
不管怎样,上手这个项目基本上没有什么难度。您可以立即尝试并获得高分。
资料来源:马里奥·姆拉德
卷积神经网络对于各种不同的任务都有效,无论是图像识别还是图像生成。分析图像并不像以前那么困难。当然,只要你尝试,你就可以做到。
所以,选择一个好的卷积神经网络项目,准备高质量的数据,然后开始吧!
原文链接:
# 外贸独立站seo公司
# 您将
# 天猫关键词搜索排名掉了
# 世界读书日营销推广活动
# 优化静态网站
# seo毛利率
# 万华地产营销推广活动
# 发文网站推广文案
# 做seo网站营销推广怎么样
# 预估seo收录量
# 72街品牌营销推广
# 您需要
# 免费seo学习
# 保山定制网站建设
# 晋州专业网站推广方案
# 安宁ai营销推广方案设计
# 南山网络seo优化公司
# 网站建设h 5
# 天津销售行业网站推广
# 甘孜藏族网站建设推广
# 常州抖音seo运营
# seo收割流量
# 这是
# 卷积神经网络(CNN)入门指南
# 从基本原理到实战项目示例
# 您可以
# 的是
# 您的
# 柱状
# 你可以
# 让我们
# 所需
# 所示
# 卷积神经网络(CNN)入门指南:从基本原理到实战项目示例
# 创建一个
# 多个
# 很容易
# 我们可以
# 最喜欢
# 训练器
# 您在
# 文档
# 可以根据
相关文章:
日照网站建设,打造专业品牌形象,助力企业腾飞,专业品牌形象塑造,日照企业网站建设助力腾飞之路
抖音超火特效:阿丽塔、草莓外,白菜叶敷面膜特效在哪?怎么弄?
自己怎么解封微信?帮别人解封微信对自己有影响吗?
周末好去处!带娃畅游书海,国家图书馆儿童馆超赞
淮北网站建设,助力企业互联网转型,打造线上新名片,淮北企业互联网转型新引擎,专业网站建设,塑造线上新形象,淮北企业互联网转型新引擎,专业网站建设,塑造线上新名片
微信备受大众喜爱,忘记密码如何找回或重设?看这里
广州百度推广究竟在推广啥?深度解析百度推广的奥秘
抖音流行短视频应用:如何添加歌词字幕,增强趣味性?
岁末迎新!万亿级金融央企中国太平完成一、二把手更迭?
乐刷客服电话是多少?一文详解乐刷公司总部热线及相关信息
网站优化自然排名与外推平台广告发布,这些推广方式你知道吗?
网络安全概念股龙头揭秘!启明星辰、高鸿股份季报大不同?
微信语音通话不弹出通知?多维度排查调整帮您解决
食药监总局抽检5类食品325批次,12批次不合格
龙岩网站 *** ,打造专业、高效的在线平台,龙岩专业网站定制服务,构建高效在线平台
成都网站建设公司,助力企业互联网转型,打造专业品牌形象,成都专业网站建设,赋能企业互联网升级与品牌塑造
如何设置让对方在主界面隐身,却仍在好友列表的方法?
微信竟有免费不限存放相册空间,快删手机照片视频
鸡西网站建设,打造本地企业互联网新窗口,鸡西企业互联网新门户,专业网站建设服务启航
今天才知道!微信删除和拉黑区别大不同,别再乱用了
泰安网站 *** ,打造个性化企业网站,助力企业腾飞,泰安企业网站定制服务,助力企业数字化转型腾飞
速成网站,新时代在线学习的得力助手,速成网站,新时代在线学习的快速通道,速成网站,新时代在线学习的便捷桥梁
微信十年蜕变:从即时通讯到生活全覆盖,你离不开了吗?
1月12日凰家评测:微信测试新功能,朋友圈内容及图片将被折叠?
实测11家代开发小程序平台,乔拓云为何脱颖而出?
今年7月最好的创意都在这了
微信删除的好友怎么恢复?2025 年最新恢复攻略来啦
全方位策略解析,门户网站推广方案全攻略,门户网站推广策略全解析,全方位推广方案指南,门户网站推广全攻略,策略解析与全方位方案指南
江门网站 *** ,打造个性化企业品牌,助力企业腾飞,江门企业品牌腾飞,个性化网站 *** 助力创新营销,江门企业品牌腾飞,个性化网站 *** 助力创新营销
一键恢复微信记录:无备份也能快速全面恢复聊天数据
莆田网站建设,助力企业数字化转型,打造高效 *** 营销平台,莆田企业数字化升级新引擎,专业网站建设与 *** 营销平台打造
武汉网站建设公司,助力企业互联网发展,打造专属品牌形象,武汉专业网站建设,助力企业塑造卓越品牌形象
湖南网站优化,助力企业提升在线竞争力,湖南地区企业网站优化,打造在线竞争力新优势
微信提现手续费下限降至0.01元,背后原因你知道吗?
杭州网站 *** ,打造个性化企业品牌形象,助力企业腾飞,杭州定制网站 *** ,塑造独特企业品牌,推动企业飞跃,杭州定制网站 *** ,塑造独特品牌形象,助力企业飞跃腾飞
武汉地区性价比之选,便宜做网站,专业服务不打折,武汉高性价比网站 *** 专家,专业服务不缩水
网站建设一条龙服务,一站式解决方案,助力企业互联网发展,一站式企业互联网发展解决方案,网站建设一条龙服务
武汉网站推广,助力企业互联网营销新篇章,武汉网站推广赋能企业,开启互联网营销新时代,武汉网站推广,引领企业迈向互联网营销新时代
抖音惊现900分钟数学解说视频!获赞328万,成新晋流量密码?
梅西代言白酒?被吐槽了?!
微信的诞生与演变:从初登场到全面繁荣,功能如何不断拓展?
西安网站公司,助力企业数字化转型,打造专业 *** 服务平台,西安网站公司,赋能企业数字化转型,构建专业 *** 服务新平台
兰州做网站,一站式服务助力企业互联网转型,兰州企业互联网转型一站式网站服务解决方案
昆明网站设计,打造专业视觉体验,助力企业品牌升级,昆明企业品牌升级,专业网站设计,塑造卓越视觉形象
山东网站 *** ,打造企业 *** 品牌的新引擎,山东企业 *** 品牌重塑,网站 *** 新引擎驱动发展
黑龙江外国语学院举办网络安全教育讲座,共筑文明网络环境
西安网站建设公司,助力企业数字化转型,打造专业 *** 平台,西安专业网站建设,赋能企业数字化升级
001my魔域新服职业推荐:战士近战超猛,法师远程超强
如何管理微信群?退出无用群、分清主次群是关键
厦门网站 *** ,打造专业、高效的在线平台,厦门专业网站定制,构建高效在线服务平台
相关栏目:
【
广告资讯90366 】
【
广告推广18483 】
【
广告优化154267 】
【
广告营销46464 】