Master TensorFlow Basics: From Graphs to MNIST Handwritten Digit Recognition

This tutorial introduces TensorFlow fundamentals—including computational graphs, sessions, tensors, variables, placeholders, and feed_dict—explains why TensorFlow is popular, and walks through a complete MNIST handwritten digit recognition example with code snippets and visualizations.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master TensorFlow Basics: From Graphs to MNIST Handwritten Digit Recognition

Introduction

Deep learning is increasingly applied in many fields such as image recognition, object detection, and speech recognition, attracting newcomers because of high salaries. TensorFlow, the most popular open‑source deep‑learning framework, is especially suitable for beginners.

1. What is TensorFlow?

TensorFlow is Google’s open‑source machine‑learning library released in November 2015 under the Apache 2.0 license.

2. Why TensorFlow?

Key advantages include a Python API, excellent cross‑platform compatibility, lightweight deployment requirements, built‑in visualization tools for experiment management, and a large community that quickly solves most problems.

3. Easy‑to‑use TensorFlow tools

High‑level APIs such as tf.contrib.learn, tf.contrib.slim, and Keras provide simplified interfaces for rapid prototyping.

4. TensorFlow installation

Installation is straightforward; refer to the official documentation for details.

TensorFlow Basics

Programming with TensorFlow can be summarized in two steps: (1) assemble a graph ; (2) execute the graph with a Session .

Graph and Session

TensorFlow is based on a computational graph. A graph consists of nodes (operations) and edges (tensors). The graph defines the computation but does not perform it; the Session provides the runtime context that actually runs the operations.

The four core concepts are:

Tensor : a typed multi‑dimensional array, the edges of the graph.

Operation : a computation unit, the nodes of the graph.

Graph : a collection of tensors and operations that describes the computation.

Session : the execution context that runs the graph.

Variables

Variables store and update model parameters. They must be initialized before use and can be saved to disk with a Saver. Initialization can be done with tf.global_variables_initializer() or tf.variables_initializer() for a subset.

Placeholders and feed_dict

When the exact input values are unknown at graph construction time, tf.placeholder(dtype, shape=None, name=None) defines a placeholder. Actual values are supplied at runtime via the feed_dict argument of Session.run().

MNIST recognition example

The MNIST dataset (55,000 samples, 28×28 grayscale images) is downloaded from Yann LeCun’s website. Each image is flattened to a 784‑dimensional vector. A logistic‑regression model is built with placeholders for X and y, weight W and bias b variables, a softmax output, cross‑entropy loss, and a GradientDescentOptimizer with learning rate 0.5.

Training runs for 1,000 iterations with a batch size of 100. After training, accuracy is evaluated by comparing the predicted label (argmax of the softmax output) with the true label.

Conclusion

We introduced TensorFlow’s graph and session concepts, basic data structures, variable handling, placeholders, and feed_dict, and demonstrated a complete handwritten‑digit recognition pipeline, providing a solid starting point for beginners.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

machine learningPythonTensorFlowMNISTComputational Graph
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.