手把手:我的深度学习模型训练好了,然后要做啥?

本文介绍了深度学习模型训练完成后如何进行部署和优化。通过修改Tensorflow的label_image.py脚本来提高效率,使用Flask构建轻量级API服务器,探讨了横向扩展(增加服务器数量)和纵向扩展(利用GPU和批处理)的可能性。此外,还提到了使用服务发现工具和代理来平衡负载,以及避免网络带宽瓶颈的策略。文章最后提及了一些未涵盖的主题,如硬件部署、模型版本管理和GPU环境的设置。
摘要由CSDN通过智能技术生成

这里写图片描述

大数据文摘作品

编译:姜范波、云舟

本文讲的是如何快速而不求完美地部署一个训练好的机器学习模型并应用到实际中。如果你已经成功地使用诸如Tensorflow或Caffe这样的框架训练好了一个机器学习模型,现在你正在试图让这个模型能够快速的演示,那么读这篇文章就对了。

阅读时长: 10-15分钟


使用前检查清单

  • 检查tensorflow的安装

  • 从 stdin 运行在线分类

  • 在本地运行分类

  • 把分类器放到硬编码(hardcoded)的代理

  • 把分类器放到有服务发现(service discovery)的代理

  • 用一个伪DNS调用分类器


机器学习的实际应用


当我们第一次进入Hive的机器学习空间时,针对我们的实际应用场景,我们已经拥有了数百万张准确标记的图像,这些图像使我们能够在一周之内,从头开始训练最先进的深度卷积神经网络图像分类模型(即随机权重)。然而,在更典型的应用场景中,图像的数量级通常只有数百幅,这种情况下,我建议微调现有的模型。比如,https://www.tensorflow.org/tutorials/image_retraining有一个关于如何微调Imagenet模型(在1.2M图像上训练1000个类别)以对花进行分类的样本数据集(3647个图像, 5个类别)。


上面的Tensorflow教程简要而言,是在安装bazel和tensorflow之后,需要运行以下代码,用大约30分钟的来建模,5分钟来训练:


(
cd "$HOME"</span> &amp;&amp; \&amp;lt;br style="max-width: 100%;">curl -O http:<span class="" style="max-width: 100%; color: rgb(136, 136, 136);">//download.tensorflow.org/example_images/flower_photos.tgz &amp;&amp; \&amp;lt;/span><br style="max-width: 100%;">tar xzf flower_photos.tgz ;<br style="max-width: 100%;">) &amp;&amp; \&amp;lt;br style="max-width: 100%;">bazel build tensorflow/examples/image_retraining:retrain \&amp;lt;br style="max-width: 100%;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tensorflow/examples/image_retraining:label_image \&amp;lt;br style="max-width: 100%;">&amp;&amp; \&amp;lt;br style="max-width: 100%;">bazel-bin/tensorflow/examples/image_retraining/retrain \&amp;lt;br style="max-width: 100%;"> &nbsp;--image_dir <span class="" style="max-width: 100%; color: rgb(136, 0, 0);">"$HOME"/flower_photos \
 --how_many_training_steps=200
&& \
bazel-bin/tensorflow/examples/image_retraining/label_image \
 --graph=/tmp/output_graph.pb \
 --labels=/tmp/output_labels.txt \
 --output_layer=final_result:0 \
 --image=$HOME/flower_photos/daisy/<span class="" style="max-width: 100%; color: rgb(136, 0, 0);">21652746</span>_cc379e0eea_m.jpg</code></pre><p style="margin-right: 8px; margin-left: 8px; max-width: 100%; min-height: 1em; color: rgb(62, 62, 62); font-family: &quot;Helvetica Neue\&amp;amp;quot;, Helvetica, \&amp;amp;quot;Hiragino Sans GB\&amp;amp;quot;, \&amp;amp;quot;Microsoft YaHei\&amp;amp;quot;, Arial, sans-serif&quot;; white-space: normal; widows: 1; line-height: 1.75em;"><br></p><p style="margin-right: 8px; margin-left: 8px; max-width: 100%; min-height: 1em; color: rgb(62, 62, 62); font-family: &quot;Helvetica Neue\&amp;amp;quot;, Helvetica, \&amp;amp;quot;Hiragino Sans GB\&amp;amp;quot;, \&amp;amp;quot;Microsoft YaHei\&amp;amp;quot;, Arial, sans-serif&quot;; white-space: normal; widows: 1; line-height: 1.75em;"><span style="max-width: 100%; color: rgb(51, 51, 51); font-family: 微软雅黑; font-size: 15px; letter-spacing: 2px;">或者,如果你安装了Docker,则可以使用以下预构建的Docker镜像:</span></p><p style="margin-right: 8px; margin-left: 8px; max-width: 100%; min-height: 1em; color: rgb(62, 62, 62); font-family: &quot;Helvetica Neue\&amp;amp;quot;, Helvetica, \&amp;amp;quot;Hiragino Sans GB\&amp;amp;quot;, \&amp;amp;quot;Microsoft YaHei\&amp;amp;quot;, Arial, sans-serif&quot;; white-space: normal; widows: 1; line-height: 1.75em;"><br></p><pre style="max-width: 100%; color: rgb(62, 62, 62); line-height: 25.6px; widows: 1; overflow-x: auto;"><code class="" style="margin-right: 0.15em; margin-left: 0.15em; padding: 0.5em; max-width: 100%; font-size: 0.85em; font-family: Consolas, Menlo, Courier, monospace; white-space: pre; overflow: auto; color: rgb(51, 51, 51); min-width: 400px; background: rgb(248, 248, 248); display: block !important;">sudo docker run -it --net=host li
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值