大数据文摘作品
编译:姜范波、云舟
本文讲的是如何快速而不求完美地部署一个训练好的机器学习模型并应用到实际中。如果你已经成功地使用诸如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> && \&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 && \&lt;/span><br style="max-width: 100%;">tar xzf flower_photos.tgz ;<br style="max-width: 100%;">) && \&lt;br style="max-width: 100%;">bazel build tensorflow/examples/image_retraining:retrain \&lt;br style="max-width: 100%;"> tensorflow/examples/image_retraining:label_image \&lt;br style="max-width: 100%;">&& \&lt;br style="max-width: 100%;">bazel-bin/tensorflow/examples/image_retraining/retrain \&lt;br style="max-width: 100%;"> --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: "Helvetica Neue\&amp;quot;, Helvetica, \&amp;quot;Hiragino Sans GB\&amp;quot;, \&amp;quot;Microsoft YaHei\&amp;quot;, Arial, sans-serif"; 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: "Helvetica Neue\&amp;quot;, Helvetica, \&amp;quot;Hiragino Sans GB\&amp;quot;, \&amp;quot;Microsoft YaHei\&amp;quot;, Arial, sans-serif"; 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: "Helvetica Neue\&amp;quot;, Helvetica, \&amp;quot;Hiragino Sans GB\&amp;quot;, \&amp;quot;Microsoft YaHei\&amp;quot;, Arial, sans-serif"; 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