mirror of
https://github.com/clearlinux/clear-linux-documentation.git
synced 2026-04-29 03:23:42 +00:00
341 lines
20 KiB
HTML
341 lines
20 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html lang="en" data-content_root="../">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
||
<title>TensorFlow* machine learning — Documentation for Clear Linux* project</title>
|
||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/bizstyle.css?v=5283bb3d" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
|
||
|
||
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
|
||
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
|
||
<script src="../_static/copybutton.js?v=a56c686a"></script>
|
||
<script src="../_static/bizstyle.js"></script>
|
||
<link rel="canonical" href="https://clearlinux.github.io/clear-linux-documentation/tutorials/tensorflow-machine-learning.html" />
|
||
<link rel="icon" href="../_static/favicon.ico"/>
|
||
<link rel="author" title="About these documents" href="../about.html" />
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="VMware* Workstation Pro" href="vmware-workstation.html" />
|
||
<link rel="prev" title="Samba Server" href="smb-server.html" />
|
||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||
<!--[if lt IE 9]>
|
||
<script src="_static/css3-mediaqueries.js"></script>
|
||
<![endif]-->
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="vmware-workstation.html" title="VMware* Workstation Pro"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="smb-server.html" title="Samba Server"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Documentation for Clear Linux* project</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Tutorials</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">TensorFlow* machine learning</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="tensorflow-machine-learning">
|
||
<span id="machine-learning"></span><h1>TensorFlow* machine learning<a class="headerlink" href="#tensorflow-machine-learning" title="Link to this heading">¶</a></h1>
|
||
<p>This tutorial demonstrates the installation and execution of a TensorFlow*
|
||
machine learning example on Clear Linux* OS. It uses a Jupyter* Notebook and MNIST
|
||
data for handwriting recognition.</p>
|
||
<p>The initial steps show how to set up a Jupyter kernel and run a Notebook
|
||
on a bare-metal Clear Linux OS system.</p>
|
||
<nav class="contents local" id="contents">
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#prerequisites" id="id9">Prerequisites</a></p></li>
|
||
<li><p><a class="reference internal" href="#set-up-a-jupyter-notebook" id="id10">Set up a Jupyter Notebook</a></p></li>
|
||
<li><p><a class="reference internal" href="#run-the-jupyter-machine-learning-example-code" id="id11">Run the Jupyter machine learning example code</a></p></li>
|
||
<li><p><a class="reference internal" href="#related-topics" id="id12">Related topics</a></p></li>
|
||
</ul>
|
||
</nav>
|
||
<section id="prerequisites">
|
||
<h2><a class="toc-backref" href="#id9" role="doc-backlink">Prerequisites</a><a class="headerlink" href="#prerequisites" title="Link to this heading">¶</a></h2>
|
||
<p>This tutorial assumes you have installed Clear Linux OS on your host system. For
|
||
detailed instructions on installing Clear Linux OS on a bare metal system, follow the
|
||
<a class="reference internal" href="../get-started/bare-metal-install-desktop.html#bare-metal-install-desktop"><span class="std std-ref">bare metal installation tutorial</span></a>.</p>
|
||
<p>Before you install any new packages, update Clear Linux OS with the following command:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>swupd<span class="w"> </span>update
|
||
</pre></div>
|
||
</div>
|
||
<p>After your system is updated, add the following bundles to your system:</p>
|
||
<ul class="simple">
|
||
<li><p><strong class="command">machine-learning-web-ui</strong>: This bundle contains the Jupyter application.</p></li>
|
||
<li><p><strong class="command">machine-learning-basic</strong>: This bundle contains TensorFlow
|
||
and other useful tools.</p></li>
|
||
</ul>
|
||
<p>To install the bundles, run the following commands in your <code class="file docutils literal notranslate"><span class="pre">$HOME</span></code>
|
||
directory:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>swupd<span class="w"> </span>bundle-add<span class="w"> </span>machine-learning-web-ui
|
||
|
||
sudo<span class="w"> </span>swupd<span class="w"> </span>bundle-add<span class="w"> </span>machine-learning-basic
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="set-up-a-jupyter-notebook">
|
||
<h2><a class="toc-backref" href="#id10" role="doc-backlink">Set up a Jupyter Notebook</a><a class="headerlink" href="#set-up-a-jupyter-notebook" title="Link to this heading">¶</a></h2>
|
||
<p>With all required packages and libraries installed, set up the file structure
|
||
for the Jupyter Notebook.</p>
|
||
<ol class="arabic">
|
||
<li><p>In the <code class="file docutils literal notranslate"><span class="pre">$HOME</span></code> directory, create a directory for the Jupyter
|
||
Notebooks named <code class="file docutils literal notranslate"><span class="pre">Notebooks</span></code>.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>mkdir<span class="w"> </span>Notebooks
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Within <code class="file docutils literal notranslate"><span class="pre">Notebooks</span></code>, create a directory named <code class="file docutils literal notranslate"><span class="pre">Handwriting</span></code>.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>mkdir<span class="w"> </span>Notebooks/Handwriting
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Change to the new directory.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span><span class="w"> </span>Notebooks/Handwriting
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Copy the <code class="file docutils literal notranslate"><span class="pre">MNIST_example.ipynb</span></code> file into the <code class="file docutils literal notranslate"><span class="pre">Handwriting</span></code>
|
||
directory.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>After installing the <strong class="command">machine-learning basic</strong> bundle, you can find the example code under
|
||
<code class="file docutils literal notranslate"><span class="pre">/usr/share/doc/tensorflow/MNIST_example.ipynb</span></code>.</p>
|
||
</div>
|
||
</li>
|
||
</ol>
|
||
<p>The example code downloads and decompresses the MNIST data directly into the
|
||
<code class="file docutils literal notranslate"><span class="pre">./mnist</span></code> directory. Alternatively, download the four files directly
|
||
from the Yann LeCun’s <a class="reference external" href="http://yann.lecun.com/exdb/mnist/">MNIST Database website</a> and save them into a
|
||
<code class="file docutils literal notranslate"><span class="pre">mnist</span></code> directory within the <code class="file docutils literal notranslate"><span class="pre">Handwriting</span></code> directory.</p>
|
||
<p>The files needed are:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference external" href="http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz">train-images-idx3-ubyte.gz</a>: Training set images (9912422 bytes)</p></li>
|
||
<li><p><a class="reference external" href="http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz">train-labels-idx1-ubyte.gz</a>: Training set labels (28881 bytes)</p></li>
|
||
<li><p><a class="reference external" href="http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz">t10k-images-idx3-ubyte.gz</a>: Test set images (1648877 bytes)</p></li>
|
||
<li><p><a class="reference external" href="http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz">t10k-labels-idx1-ubyte.gz</a>: Test set labels (4542 bytes)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="run-the-jupyter-machine-learning-example-code">
|
||
<h2><a class="toc-backref" href="#id11" role="doc-backlink">Run the Jupyter machine learning example code</a><a class="headerlink" href="#run-the-jupyter-machine-learning-example-code" title="Link to this heading">¶</a></h2>
|
||
<p>With Clear Linux OS, Jupyter, and TensorFlow installed and configured, you can
|
||
run the example code.</p>
|
||
<ol class="arabic">
|
||
<li><p>Go to the <code class="file docutils literal notranslate"><span class="pre">($HOME)/Notebooks</span></code> directory and start Jupyter with the
|
||
following commands:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span><span class="w"> </span>~/Notebooks
|
||
|
||
jupyter<span class="w"> </span>notebook
|
||
</pre></div>
|
||
</div>
|
||
<p>The Jupyter server starts and opens a web browser showing the Jupyter file
|
||
manager with a list of files in the current directory, as shown in
|
||
Figure 1.</p>
|
||
<figure class="align-default" id="id1">
|
||
<img alt="Jupyter file manager" src="../_images/machine-learning-1.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 1: The Jupyter file manager shows the list of available files.</span><a class="headerlink" href="#id1" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
</li>
|
||
<li><p>Click on the <code class="file docutils literal notranslate"><span class="pre">Handwriting</span></code> directory. The <code class="file docutils literal notranslate"><span class="pre">MNIST_example.ipynb</span></code>
|
||
file created earlier should be listed there, as shown in Figure 2.</p>
|
||
<figure class="align-default" id="id2">
|
||
<img alt="Example file within the Jupyter file manager" src="../_images/machine-learning-2.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 2: The example file within the Jupyter file manager.</span><a class="headerlink" href="#id2" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
</li>
|
||
<li><p>To run the handwriting example, click on the <code class="file docutils literal notranslate"><span class="pre">MNIST_example.ipynb</span></code>
|
||
file to load the notebook, as shown in Figure 3.</p>
|
||
<figure class="align-default" id="id3">
|
||
<img alt="The loaded MNIST_example notebook" src="../_images/machine-learning-3.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 3: The loaded MNIST_example notebook within the Jupyter file
|
||
manager.</span><a class="headerlink" href="#id3" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
</li>
|
||
<li><p>Click the <img alt="run-cell" src="../_images/run-cell-button.png" /> button to execute the code in the current cell and
|
||
move to the next.</p></li>
|
||
<li><p>Select the <span class="guilabel">In [2]</span> cell and click the <img alt="run-cell" src="../_images/run-cell-button.png" /> button to load
|
||
the MNIST data. The successful output is shown on Figure 4.</p>
|
||
<figure class="align-default" id="id4">
|
||
<img alt="Successful import of MNIST data" src="../_images/machine-learning-4.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 4: Output after successfully importing the MNIST data.</span><a class="headerlink" href="#id4" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
<p>After the MNIST data is successfully downloaded and extracted into the
|
||
<code class="file docutils literal notranslate"><span class="pre">mnist</span></code> directory within the <code class="file docutils literal notranslate"><span class="pre">($HOME)/Notebooks/Handwriting</span></code>
|
||
directory, four .gz files are present and the four data sets are created:
|
||
<cite>trainX</cite>, <cite>trainY</cite>, <cite>testX</cite> and <cite>testY</cite>.</p>
|
||
</li>
|
||
<li><p>To inspect the imported data, the function in <span class="guilabel">In [3]</span> first
|
||
instructs Jupyter to reshape the data into an array of 28 x 28 images and to
|
||
plot the area in a 28 x 28 grid. Click the <img alt="run-cell" src="../_images/run-cell-button.png" /> button twice to show
|
||
the first two digits in the <cite>trainX</cite> dataset. An example is shown in
|
||
Figure 5.</p>
|
||
<figure class="align-default" id="id5">
|
||
<img alt="Function to reshape data." src="../_images/machine-learning-5.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 5: A function reshapes the data and displays the first two
|
||
digits in the <cite>trainX</cite> dataset.</span><a class="headerlink" href="#id5" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
</li>
|
||
<li><p>The <span class="guilabel">In [4]</span> cell defines the neural network. It provides the
|
||
inputs, defines the hidden layers, runs the training model, and sets up
|
||
the output layer, as shown in Figure 6. Click the <img alt="run-cell" src="../_images/run-cell-button.png" /> button four
|
||
times to perform these operations.</p>
|
||
<figure class="align-default" id="id6">
|
||
<img alt="Defining, building and training the neural network model" src="../_images/machine-learning-6.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 6: Defining, building, and training the neural network model.</span><a class="headerlink" href="#id6" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
</li>
|
||
<li><p>To test the accuracy of the prediction that the system makes, select the
|
||
<span class="guilabel">In [8]</span> cell and click the <img alt="run-cell" src="../_images/run-cell-button.png" /> button. In this example,
|
||
the number 6 was predicted with a 99% accuracy, as shown in Figure 7.</p>
|
||
<figure class="align-default" id="id7">
|
||
<img alt="Prediction example" src="../_images/machine-learning-7.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 7: The system predicts a number providing the accuracy of the
|
||
prediction.</span><a class="headerlink" href="#id7" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>To retest the accuracy of a random data point’s prediction, run the
|
||
cell <span class="guilabel">In [8]</span> again. It will take another random data point
|
||
and predict its value.</p>
|
||
</div>
|
||
</li>
|
||
<li><p>To check the accuracy for the whole dataset, select the <span class="guilabel">In [10]</span>
|
||
cell and click the <img alt="run-cell" src="../_images/run-cell-button.png" /> button. Our example’s accuracy is
|
||
calculated as 97.17%, as shown in Figure 8.</p>
|
||
<figure class="align-default" id="id8">
|
||
<img alt="System's accuracy" src="../_images/machine-learning-8.png" />
|
||
<figcaption>
|
||
<p><span class="caption-text">Figure 8: The system’s accuracy for the entire data set.</span><a class="headerlink" href="#id8" title="Link to this image">¶</a></p>
|
||
</figcaption>
|
||
</figure>
|
||
</li>
|
||
</ol>
|
||
<p>For more in-depth information on the model used and the mathematics it entails,
|
||
visit the TensorFlow tutorials
|
||
<a class="reference external" href="https://www.tensorflow.org/get_started/mnist/beginners">TensorFlow MNIST beginners demo</a> and <a class="reference external" href="https://www.tensorflow.org/get_started/mnist/pros">TensorFlow MNIST pros demo</a>.</p>
|
||
<p><strong>Congratulations!</strong></p>
|
||
<p>You have successfully installed a Jupyter kernel on Clear Linux OS. In addition, you
|
||
trained a neural network to successfully predict the values contained in a
|
||
data set of hand-written number images.</p>
|
||
</section>
|
||
<section id="related-topics">
|
||
<h2><a class="toc-backref" href="#id12" role="doc-backlink">Related topics</a><a class="headerlink" href="#related-topics" title="Link to this heading">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><a class="reference external" href="http://yann.lecun.com/exdb/mnist/">MNIST Database website</a></p></li>
|
||
<li><p><a class="reference external" href="https://www.tensorflow.org/get_started/mnist/beginners">TensorFlow MNIST beginners demo</a></p></li>
|
||
<li><p><a class="reference external" href="https://www.tensorflow.org/get_started/mnist/pros">TensorFlow MNIST pros demo</a></p></li>
|
||
<li><p><a class="reference external" href="http://jupyter.org/">Jupyter main website</a></p></li>
|
||
<li><p><a class="reference external" href="https://jupyter.readthedocs.io/en/latest/index.html">Jupyter documentation</a></p></li>
|
||
<li><p><a class="reference external" href="https://en.wikipedia.org/wiki/MNIST_database">MNIST at Wikipedia</a></p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="Main">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../_static/clearlinux.png" alt="Logo of Clear Linux* Project Docs"/>
|
||
</a></p>
|
||
<div>
|
||
<h3><a href="../index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">TensorFlow* machine learning</a><ul>
|
||
<li><a class="reference internal" href="#prerequisites">Prerequisites</a></li>
|
||
<li><a class="reference internal" href="#set-up-a-jupyter-notebook">Set up a Jupyter Notebook</a></li>
|
||
<li><a class="reference internal" href="#run-the-jupyter-machine-learning-example-code">Run the Jupyter machine learning example code</a></li>
|
||
<li><a class="reference internal" href="#related-topics">Related topics</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="smb-server.html"
|
||
title="previous chapter">Samba Server</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="vmware-workstation.html"
|
||
title="next chapter">VMware* Workstation Pro</a></p>
|
||
</div>
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../_sources/tutorials/tensorflow-machine-learning.rst.txt"
|
||
rel="nofollow">Show Source</a></li>
|
||
</ul>
|
||
</div>
|
||
<search id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</search>
|
||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="vmware-workstation.html" title="VMware* Workstation Pro"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="smb-server.html" title="Samba Server"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Documentation for Clear Linux* project</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Tutorials</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">TensorFlow* machine learning</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2022 Intel Corporation. All Rights Reserved..
|
||
Last updated on Nov 04, 2024.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
|
||
</div>
|
||
</body>
|
||
</html> |