This laboratory introduces students to neural network architectures—from basic Artificial Neural Networks (ANN) to Deep Neural Networks (DNN) and Convolutional Neural Networks (CNN). Through hands-on implementation in PyTorch on the NVIDIA Jetson Orin Nano, students will develop a deep understanding of how neural networks learn, train, and make predictions on real-world data.
Neural networks are the foundation of modern AI applications—from computer vision and natural language processing to autonomous vehicles and medical diagnosis. By mastering PyTorch implementation on edge devices like the Jetson Orin Nano, you're preparing for real-world AI deployment scenarios where models must run efficiently on resource-constrained hardware.
This laboratory consists of six progressive parts, each building upon previous concepts:
By the end of this laboratory session, you will be able to:
Artificial Neural Networks (ANNs) are computational models inspired by the human brain's structure and function. They consist of interconnected nodes (neurons) organized in layers that process information. Neural networks have revolutionized fields such as computer vision, natural language processing, and speech recognition due to their ability to learn complex patterns from data.
The fundamental building block of neural networks is the artificial neuron, which receives multiple inputs, applies weights to them, sums them up, adds a bias term, and passes the result through an activation function. When many neurons are connected together in layers, they can learn to represent highly complex functions through a process called training.
Tensors are the fundamental data structure in deep learning frameworks like PyTorch. A tensor is essentially a multi-dimensional array that can represent scalars (0D), vectors (1D), matrices (2D), or higher-dimensional data (3D and beyond). In neural networks, tensors are used to represent inputs, outputs, weights, and intermediate computations.
PyTorch tensors are similar to NumPy arrays but with two key advantages: they can run on GPUs for accelerated computing, and they support automatic differentiation for gradient computation during backpropagation. Understanding tensor operations like reshaping, indexing, and matrix multiplication is essential for building and debugging neural networks.
A basic neural network consists of three types of layers: input layer, hidden layers, and output layer. The input layer receives the raw data, hidden layers perform intermediate computations through weighted connections and activation functions, and the output layer produces the final prediction.
Deep Neural Networks (DNNs) are neural networks with multiple hidden layers, allowing them to learn hierarchical representations of data. Each layer learns increasingly abstract features: early layers might detect edges in images, middle layers detect shapes, and later layers recognize complete objects.
Convolutional Neural Networks (CNNs) are specialized architectures designed for processing grid-like data such as images. They use convolutional layers that apply filters to detect local patterns, pooling layers to reduce dimensionality, and fully connected layers for final classification. While this lab focuses on fully connected networks, understanding CNNs is important for advanced computer vision applications.
Training a neural network involves finding the optimal weights that minimize the difference between predicted outputs and actual targets. This process uses the following key components:
Forward Propagation: Input data flows through the network layer by layer, with each neuron computing a weighted sum of its inputs, adding a bias, and applying an activation function. The final layer produces predictions.
Loss Function: Measures how far the network's predictions are from the true values. Common loss functions include Mean Squared Error (MSE) for regression and Cross-Entropy Loss for classification. The goal of training is to minimize this loss.
Backpropagation: An algorithm that computes gradients of the loss function with respect to each weight in the network. It uses the chain rule from calculus to efficiently propagate error signals backward through the network, determining how much each weight contributed to the error.
Optimization: Once gradients are computed, an optimizer (like Stochastic Gradient Descent or Adam) updates the weights in the direction that reduces the loss. This process repeats for many iterations (epochs) until the network converges to a good solution.
To ensure our neural network generalizes well to new, unseen data, we must carefully evaluate its performance. Simply achieving low training loss is not enough—the model might be overfitting, meaning it memorizes the training data but fails on new examples.
Training vs Validation Split: We divide our dataset into training data (used to update weights) and validation data (used to evaluate performance). By monitoring both training and validation loss, we can detect overfitting: if training loss decreases but validation loss increases, the model is memorizing rather than learning general patterns.
Dropout Regularization: A technique to prevent overfitting by randomly "dropping out" (setting to zero) a fraction of neurons during training. This forces the network to learn robust features that don't depend on any single neuron, improving generalization. During inference (testing), all neurons are active, and their outputs are scaled appropriately.
After training a neural network, we need to save the learned weights so we can use the model later without retraining. PyTorch provides mechanisms to save and load model state, including weights, biases, and optimizer state. This is crucial for deploying models to production environments, such as edge devices like the Jetson Orin Nano.
Understanding model persistence also enables checkpointing during long training runs, allowing you to resume training if interrupted and to save the best-performing model encountered during training.
PyTorch is one of the most popular deep learning frameworks because of its intuitive, Pythonic design and dynamic computational graphs. Unlike static frameworks, PyTorch builds the computation graph on-the-fly, making it easier to debug and allowing for dynamic architectures that change based on input. Its strong support for GPU acceleration and extensive ecosystem of tools make it ideal for both research and production applications.
Before starting the laboratory exercises, watch the following video tutorials from Udacity's "Introduction to Deep Learning with PyTorch" course. These videos provide essential background knowledge and practical demonstrations of the concepts you'll implement in this lab.
Source: Udacity - Introduction to Deep Learning with PyTorch
Chapter: Introduction to PyTorch
Watch all videos from Udacity - Introduction to Deep Learning with PyTorch
Instructions: Complete this quiz after watching the required videos to assess your readiness for the lab. These questions test your understanding of key concepts you'll need during the exercises.
Note: Discuss your answers with your lab instructor before beginning the practical exercises. Understanding these concepts is crucial for successfully completing the lab.
This laboratory is divided into six parts, each focusing on a specific aspect of neural network implementation in PyTorch. Complete each part sequentially, as they build upon each other. Each part includes exercises that you should attempt before viewing the solutions.
1. Attempt exercises independently first - Try to solve each problem before looking at solutions.
2. Solutions are password-protected - Your instructor will provide the password when appropriate.
3. Execute code on Jetson Orin Nano - All exercises are designed to run on your edge device.
4. Document your work - Take screenshots and notes for your lab report.
In this part, you'll learn the fundamentals of PyTorch tensors, which are the building blocks of all neural network computations. You'll practice creating tensors, performing basic operations, reshaping, indexing, and matrix multiplication—skills essential for implementing neural networks.
This part introduces you to building neural network architectures using PyTorch's powerful nn.Module class. You'll learn how to define network layers, apply activation functions, and implement the forward propagation process. Understanding this structure is crucial for creating custom neural networks.
Now you'll learn how to train neural networks through the complete training process. This includes defining loss functions, choosing optimizers, implementing training loops, and performing backpropagation. You'll see how networks learn to minimize loss through iterative weight updates.
In this practical application, you'll train a neural network to classify images from the Fashion-MNIST dataset, which contains 10 categories of clothing items. This real-world task demonstrates how neural networks can learn to recognize patterns in images and make accurate predictions.
Learn how to properly evaluate neural network performance using validation techniques. You'll implement training/validation splits, monitor overfitting, and use dropout regularization. This part teaches you how to ensure your models generalize well to new, unseen data.
The final part covers model persistence—saving your trained models and loading them for later use. This is essential for deploying models to production environments and for checkpointing during long training runs. You'll learn how to save both model architecture and learned weights.
Verify the following are installed on your Jetson Orin Nano:
Verification command:
All necessary code, datasets, and helper functions are included in the six lab parts. Each HTML file is self-contained and ready to execute on your Jetson Orin Nano through a Jupyter Notebook interface.
Before starting the lab exercises, ensure your Jetson Orin Nano is properly configured with PyTorch and CUDA support. Run the verification command above to confirm your setup. If you encounter issues, consult your instructor before proceeding.
Source: Udacity - Introduction to Deep Learning with PyTorch
Chapter: Introduction to PyTorch
Students must submit a comprehensive lab report demonstrating their understanding of neural network implementation and training in PyTorch. The report should showcase practical skills acquired through the six laboratory parts and include evidence of all completed exercises.
Submit your completed lab report by [Insert Deadline - Typically 1 week after lab session]. Late submissions will be penalized according to course policy (10% per day, maximum 3 days).
Your lab report must include the following sections:
For each of the 6 parts:
Before submitting, ensure you have:
Week3_[YourLastName]_[StudentID].pdfWeek3_[YourLastName]_[StudentID]_Code.zipWeek3_Ahmed_202012345.pdf| Component | Points | Criteria |
|---|---|---|
| Title Page & Formatting | 5 | Complete, professional |
| Objectives | 10 | Clear, comprehensive |
| Procedure & Results | 50 | All parts complete, correct code, proper outputs |
| Discussion | 20 | Thoughtful analysis, supported by results |
| Challenges & Solutions | 10 | Detailed problem-solving process |
| Conclusion | 5 | Reflective, insightful |
| Total | 100 |