ELEC 395 - Week 12
Experiment 12
Road Following
Autonomous Driving with Regression
← Back to Course Home
📋

Laboratory Overview

↑ Go Up

In this laboratory experiment, you will implement an autonomous road-following system for the JetBot using regression-based deep learning. Unlike classification tasks that predict discrete categories, regression predicts continuous values - specifically, the X and Y coordinates of a target point on the road that the robot should follow. By training a neural network to estimate where the robot should navigate, you'll enable autonomous path-following behavior that forms the foundation of self-driving systems. This laboratory brings together computer vision, deep learning, and robotics to create an intelligent system capable of navigating paths without explicit programming.

You'll progress through the complete autonomous driving pipeline: collecting training data by manually labeling target points on road images, training a ResNet-18 neural network to predict steering coordinates using regression, and deploying the trained model for real-time autonomous navigation. The regression approach allows the robot to continuously adjust its trajectory based on visual input, following paths with smooth and natural-looking motion. This hands-on experience demonstrates how modern autonomous vehicles use neural networks to perceive their environment and make continuous control decisions.

What You'll Learn

  • Regression for Control: Applying neural networks to predict continuous steering coordinates rather than discrete classifications
  • Interactive Data Collection: Building training datasets through visual labeling of target navigation points
  • Transfer Learning for Regression: Adapting pre-trained ResNet-18 for coordinate prediction tasks
  • Autonomous Navigation: Implementing real-time path following using regression-based steering control
  • Model Optimization: Deploying neural networks on edge devices with optional TensorRT acceleration
  • Control System Integration: Converting neural network predictions into motor commands for robot navigation

💡 Why This Matters

Autonomous navigation is revolutionizing transportation, logistics, and robotics. Self-driving cars must continuously predict steering angles to follow lanes safely. Warehouse robots need to track paths to transport goods efficiently. Drones require trajectory prediction to navigate complex environments. Agricultural robots must follow crop rows precisely. This laboratory demonstrates the regression-based approach that powers these systems - predicting continuous control values from visual input. By implementing road following on the JetBot, you're learning the core techniques used in full-scale autonomous vehicles, scaled down to an educational platform. The skills you develop here - data collection strategies, regression model training, and real-time inference on edge devices - are directly applicable to industrial autonomous systems, making this laboratory a practical introduction to the technology driving the future of transportation and robotics.

Lab Structure

This laboratory consists of three progressive parts that build upon each other to create a complete autonomous driving system:

  • Part 1: Data Collection - Interactive capture of road images with labeled target coordinates for training
  • Part 2: Model Training - Training a ResNet-18 neural network to predict steering coordinates using regression
  • Part 3: Live Demonstration - Deploying the trained model for real-time autonomous road following with the JetBot
🎯

Learning Objectives

↑ Go Up

By the end of this laboratory session, you will be able to:

  • Implement regression-based autonomous navigation by training neural networks to predict continuous steering coordinates from camera images for path following.
  • Collect and label training data using interactive visual annotation to create datasets mapping road images to target navigation coordinates.
  • Train regression models with transfer learning by adapting ResNet-18 architecture with appropriate loss functions for continuous value prediction.
  • Convert predictions to motor control by translating neural network coordinate outputs into steering and throttle commands for autonomous driving.
  • Deploy models for real-time inference on edge devices, achieving low-latency prediction for responsive autonomous navigation.
  • Apply data augmentation techniques such as horizontal flipping and color jittering to improve model generalization for diverse road conditions.
  • Optimize inference performance using TensorRT optimization for accelerated neural network execution on Jetson hardware.
  • Evaluate autonomous driving systems by testing navigation accuracy, smoothness, and robustness across different path configurations.
📚

Background

↑ Go Up

Regression in Autonomous Driving

Regression is a supervised learning technique that predicts continuous numerical values rather than discrete categories. While classification answers questions like "Is there a stop sign?" with yes or no, regression answers "What steering angle is needed?" with a specific numerical value. In autonomous driving, regression enables vehicles to predict continuous control parameters such as steering angles, throttle positions, and trajectory waypoints. This continuous prediction capability is essential for smooth, human-like driving behavior that adapts fluidly to changing road conditions.

The road following task demonstrates end-to-end learning, where a neural network learns to map raw camera images directly to steering coordinates without explicit programming of driving rules. During data collection, human operators label target points on road images indicating where the robot should navigate. The neural network learns patterns in the visual data that correspond to correct navigation targets, effectively learning an implicit model of road-following behavior. This approach mirrors how self-driving car companies like Tesla and Waymo use neural networks to process sensor data and generate driving commands, though production systems employ multiple sensors and redundant safety systems beyond the scope of this educational laboratory.

ResNet-18 Architecture for Regression

ResNet-18 (Residual Network with 18 layers) is a convolutional neural network architecture that uses skip connections to enable training of deep networks without gradient vanishing problems. Originally designed for ImageNet classification with 1000 output classes, ResNet-18 can be adapted for regression by replacing its final fully connected layer. For road following, we modify the output layer from 1000 neurons (for classification) to 2 neurons (for X and Y coordinates), transforming the network from a classifier to a regression model. The pre-trained weights from ImageNet provide general feature extractors for visual patterns, which we fine-tune for the specific task of predicting navigation coordinates.

Transfer learning accelerates training and improves performance by leveraging knowledge learned from millions of ImageNet images. The early layers of ResNet-18 detect edges, textures, and basic shapes that are useful for any computer vision task, while later layers learn task-specific features. By fine-tuning a pre-trained model rather than training from scratch, we can achieve strong performance with relatively small datasets - often just a few hundred labeled images. This efficiency is crucial for practical robotics applications where collecting massive datasets is impractical. The regression task uses Mean Squared Error (MSE) loss to minimize the difference between predicted and actual coordinates, encouraging the network to make accurate continuous predictions.

Data Collection Strategy

Effective data collection is critical for successful autonomous driving. The "green dot" labeling approach provides intuitive target specification: operators click on camera images to place a marker indicating where the robot should navigate. This target point should be positioned as far along the desired path as the robot can safely travel in a straight line. On straight sections, the target can be placed near the horizon; on sharp curves, it must be closer to avoid steering the robot off the path. This variable target distance naturally encodes the urgency of steering corrections - tight turns require more immediate responses than gentle curves.

Data diversity is essential for model generalization. Collecting images from various positions (centered, left-offset, right-offset) and angles ensures the network learns to handle diverse scenarios. Including examples where the robot starts partially off the path helps it learn recovery behaviors. The "carrot on a stick" metaphor describes the control strategy: the neural network continuously predicts where the carrot (target point) should be, and a simple proportional controller steers the robot toward it. As the robot moves forward, the network continuously updates its prediction, creating smooth path-following behavior. This approach separates high-level path perception (the neural network's job) from low-level motor control (the proportional controller's job), demonstrating a key principle of hierarchical control in robotics.

Real-Time Inference and TensorRT Optimization

Autonomous driving requires low-latency inference to respond quickly to changing road conditions. Running neural networks on embedded devices like the Jetson Orin Nano presents computational challenges - models must execute fast enough for real-time control (typically 10-30 frames per second) while maintaining accuracy. PyTorch provides a flexible research framework but is not optimized for embedded inference. TensorRT, NVIDIA's inference optimization engine, addresses this by converting PyTorch models to highly optimized representations that execute significantly faster on Jetson hardware.

TensorRT optimization involves several techniques: layer fusion combines multiple operations into single optimized kernels, precision calibration reduces numerical precision from 32-bit to 16-bit floating point without significant accuracy loss, and kernel auto-tuning selects the fastest implementation for each operation. These optimizations can accelerate inference by 2-5x compared to standard PyTorch execution, enabling higher frame rates for more responsive autonomous navigation. The laboratory provides both standard PyTorch and TensorRT-optimized inference paths, allowing comparison of performance trade-offs. Understanding these optimization techniques is valuable for deploying any neural network on resource-constrained edge devices, from robots to IoT devices.

📝

Pre-lab Preparation

↑ Go Up

Complete the following preparation activities before your laboratory session to ensure you understand the fundamental concepts and can work efficiently during the hands-on exercises.

⚠️ Important Notice

No video tutorials are available for this experiment. Review the reference materials carefully and be prepared to work through the interactive notebooks during the laboratory session.

Knowledge Assessment Quiz

Test your understanding of regression-based autonomous navigation concepts with these questions:

Question 1: What is the primary difference between classification and regression in machine learning?

  • A) Classification is more accurate than regression
  • B) Classification predicts discrete categories while regression predicts continuous values
  • C) Regression requires more training data than classification
  • D) Classification works only with images while regression works with numbers

Question 2: In the road following task, what do the X and Y coordinates represent?

  • A) The robot's current position on the track
  • B) The target point where the robot should navigate toward
  • C) The distance to the nearest obstacle
  • D) The speed and direction of the robot

Question 3: Why is transfer learning particularly useful for the road following task?

  • A) It eliminates the need for any training data
  • B) Pre-trained features from ImageNet provide strong visual representations, requiring fewer training images
  • C) It automatically labels training data without human intervention
  • D) It makes the neural network run faster on embedded devices

Question 4: What loss function is typically used for training regression models?

  • A) Cross-entropy loss
  • B) Mean Squared Error (MSE)
  • C) Binary classification loss
  • D) Softmax loss

Question 5: In data collection, where should the target point be placed on a sharp turn?

  • A) At the horizon of the image
  • B) Closer to the robot to avoid steering off the path
  • C) Always at the center of the image
  • D) Outside the visible path to encourage aggressive turning

Question 6: How is ResNet-18 modified for the regression task compared to its original ImageNet classification design?

  • A) Additional convolutional layers are added
  • B) The final fully connected layer is replaced to output 2 values (X, Y) instead of 1000 classes
  • C) The entire architecture is rebuilt from scratch
  • D) Skip connections are removed to simplify the model

Question 7: What is the "carrot on a stick" metaphor referring to in road following?

  • A) A physical marker placed on the track for the robot to follow
  • B) The neural network continuously predicts a target point that the robot navigates toward
  • C) A reward system for training the robot
  • D) A method for collecting training data

Question 8: Why is data diversity important in the road following dataset?

  • A) To make the dataset larger for faster training
  • B) To ensure the model learns to handle various positions and angles, improving generalization
  • C) To confuse the neural network and make it learn better
  • D) Data diversity is not important for this task

Question 9: What is the primary benefit of using TensorRT optimization for inference?

  • A) It improves model accuracy
  • B) It significantly accelerates inference speed on embedded devices
  • C) It reduces the amount of training data needed
  • D) It automatically labels training images

Question 10: How are the predicted X and Y coordinates typically normalized in the neural network output?

  • A) They are kept as pixel values from 0 to 224
  • B) They are normalized to a range around -1 to 1 by subtracting the image center and dividing by half the image size
  • C) They are converted to angles in degrees
  • D) No normalization is applied
⚙️

Lab Procedure

↑ Go Up

This laboratory consists of three progressive parts that guide you through building a complete autonomous road-following system. Follow the procedures carefully and document your results at each stage.

Part 1: Data Collection for Road Following

In this part, you will collect training data by manually labeling target navigation points on road images captured from the JetBot's camera. You'll use an interactive Jupyter notebook that displays the live camera feed and allows you to click on images to specify where the robot should navigate. Each click saves an image along with the X and Y coordinates of the target point, creating a dataset that maps visual scenes to desired navigation targets.

Key Topics Covered:

  • Interactive data labeling with clickable image widgets
  • Target point selection strategies for different road configurations
  • Dataset organization and file naming conventions (xy_X_Y_uuid.jpg)
  • Data collection best practices for diverse scenarios
  • Balancing data from straight sections, curves, and recovery positions

⚠️ Data Collection Tips

Collect at least 100-150 images from diverse positions and angles. Include examples where the robot is centered, offset to the left, offset to the right, and at various angles to the path. This diversity is crucial for training a robust navigation model.

Part 2: Training the Road Following Model

With your collected dataset, you'll train a ResNet-18 neural network to predict steering coordinates using regression. The notebook guides you through dataset preparation, model configuration with transfer learning, training loop implementation with Mean Squared Error loss, and model evaluation on test data. You'll monitor training progress through loss curves and save the best-performing model for deployment. The training process typically requires 50-70 epochs and can be completed on the Jetson in 20-30 minutes.

Key Topics Covered:

  • Custom PyTorch dataset creation for coordinate regression
  • Parsing X and Y values from image filenames
  • Data augmentation with horizontal flips and color jittering
  • Modifying ResNet-18 final layer for 2-output regression
  • Training with MSE loss and Adam optimizer
  • Train/test split and model evaluation

💡 Training Tip

Monitor both training and validation loss. If validation loss stops improving while training loss continues decreasing, you may be overfitting. Consider stopping training early or collecting more diverse data.

Part 3: Live Autonomous Driving Demonstration

Deploy your trained model for real-time autonomous road following. The live demo notebook loads your trained model, captures camera frames, predicts target coordinates, and converts predictions into motor commands for autonomous navigation. You'll implement a proportional controller that steers the robot toward the predicted target point, creating smooth path-following behavior. The laboratory includes both standard PyTorch inference and optimized TensorRT versions for performance comparison.

Key Topics Covered:

  • Loading trained models for inference
  • Real-time image preprocessing and prediction
  • Converting neural network outputs to motor commands
  • Proportional control for steering based on predicted X coordinate
  • Performance monitoring with frame rate and latency
  • Optional TensorRT optimization for accelerated inference

⚠️ Safety Reminder

Always test autonomous navigation in a controlled environment. Start with low speeds and be ready to manually stop the robot if it deviates from the path. Ensure adequate space around the track to prevent collisions.

📋 Procedure Summary

  1. Set up the JetBot on a marked path or track
  2. Run Part 1 to collect 100-150 labeled training images
  3. Transfer dataset to training environment if using external workstation
  4. Execute Part 2 to train the regression model (20-30 minutes)
  5. Download and upload the trained model to JetBot
  6. Run Part 3 to demonstrate autonomous road following
  7. Optionally build TensorRT optimized model and compare performance
  8. Document results, including navigation videos and performance metrics
🔧

Lab Materials

↑ Go Up

Hardware Requirements

  • Jetson Orin Nano Developer Kit: Assembled in Week 1, with JetPack and all required software pre-configured by lab technician
  • JetBot Robot Platform: Including chassis, motors, motor driver, and power management
  • Camera Module: CSI MIPI camera for visual perception
  • Track or Marked Path: Physical road surface with clear boundaries (tape, painted lines, or dedicated track)
  • Power Supply: Fully charged battery pack for mobile operation

Software Environment

  • JupyterLab: Web-based interactive development environment (pre-installed)
  • PyTorch: Deep learning framework for model training and inference
  • TorchVision: Computer vision library with pre-trained models
  • JetBot Python Library: Robot control and camera interface
  • OpenCV: Computer vision operations and image processing
  • TensorRT: NVIDIA inference optimization engine (optional)

📌 Important Setup Note

No software installation required! All necessary libraries and dependencies have been pre-configured by the lab technician on your Jetson Orin Nano. The system is ready for immediate use - simply power on your JetBot and access JupyterLab through your web browser.

Access Information

JupyterLab Access:

  1. Connect your laptop to the same network as the JetBot
  2. Navigate to http://jetbot-[YOUR_ROBOT_NUMBER].local:8888 in your web browser
  3. Enter the password provided by your instructor
  4. Navigate to the week12 folder to access the laboratory notebooks
📚

References

↑ Go Up

Primary Resources

NVIDIA JetBot GitHub Repository: Official JetBot Source Code and Examples
Comprehensive documentation and reference implementations for JetBot projects including road following
JetBot Orin Nano (UAEU): Course Repository – Notebooks, Setup Guides, and Resources
UAEU ELEC 395 course repository with JetBot Orin Nano notebooks and lab materials
Road Following Data Labelling Instructions: Video Tutorial on Data Collection
Demonstrates effective strategies for labeling training data for road following tasks
PyTorch Transfer Learning Tutorial: Official PyTorch Transfer Learning Guide
Detailed explanation of transfer learning techniques and fine-tuning pre-trained models

Technical Documentation

ResNet Paper: Deep Residual Learning for Image Recognition
Original research paper introducing ResNet architecture and residual connections
TensorRT Documentation: NVIDIA TensorRT Developer Guide
Comprehensive guide to TensorRT optimization techniques for embedded inference
Regression vs Classification: Understanding the Fundamental Difference
Conceptual overview of when to use regression versus classification in machine learning

Additional Learning Resources

End-to-End Learning for Self-Driving Cars: NVIDIA Research Paper
Foundational paper on using neural networks to map raw pixels to steering commands
Data Augmentation Techniques: PyTorch Transforms Documentation
Reference for image augmentation methods to improve model robustness
Autonomous Driving Datasets: Kaggle Autonomous Driving Collections
Large-scale datasets for comparing your results with production-scale autonomous driving data
📄

Lab Report Requirements

↑ Go Up

Your lab report should comprehensively document your experience building and testing the autonomous road-following system. Focus on practical implementation details, experimental observations, and insights gained from hands-on work with regression-based navigation.

Lab Report Structure

1. Cover Page (5 points)

  • Laboratory title: "Week 12: Road Following - Autonomous Driving with Regression"
  • Your full name and student ID
  • Course information: ELEC 395 - AI Applications in Engineering Laboratory
  • Date of laboratory session and submission date
  • Lab partner names (if applicable)

2. Objectives (10 points)

  • List the key learning objectives for autonomous road following
  • State what you aimed to achieve with the JetBot navigation system

3. Procedure and Results (60 points)

  • Part 1 - Data Collection (20 points):
    • Document your path setup and data collection strategy
    • Include screenshots of the interactive labeling interface
    • Show example labeled images with target points in different scenarios
    • Report total number of images collected
  • Part 2 - Model Training (20 points):
    • Present training and validation loss curves
    • Document training parameters used (learning rate, epochs, etc.)
    • Include key code snippets with brief explanations
    • Report final model performance
  • Part 3 - Live Demonstration (20 points):
    • Document autonomous navigation behavior with screenshots/video frames
    • Report inference performance (frame rates)
    • Describe how the robot handled different path sections
    • Include observations on navigation smoothness and accuracy

4. Discussion (20 points)

  • Explain why regression was used instead of classification for this task
  • Discuss how data collection affected model performance
  • Analyze what worked well and what challenges you encountered
  • Describe how you addressed any navigation problems
  • Compare PyTorch vs TensorRT performance (if applicable)

5. Conclusion (5 points)

  • Summarize key insights about regression-based autonomous navigation
  • Reflect on what you learned about end-to-end learning
  • Suggest one or two potential improvements to the system

📋 Submission Checklist

  • ✓ Complete documentation of all three laboratory parts
  • ✓ Clear screenshots of data labeling with diverse examples
  • ✓ Training loss curves and performance metrics
  • ✓ Video demonstration or screenshots of autonomous navigation
  • ✓ Discussion of challenges encountered and solutions applied
  • ✓ Comparison of regression vs classification approaches
  • ✓ Key code snippets with brief explanations
  • ✓ Professional formatting with clear section organization

📤 Submission Format

  • File Format: PDF document (Microsoft Word or LaTeX acceptable before conversion)
  • File Naming: ELEC395_Week12_[YourStudentID]_[YourName].pdf
  • Page Limit: 8-12 pages including figures and code snippets
  • Figures: High-resolution screenshots and clearly labeled diagrams
  • Code: Include key code snippets with brief explanations (not entire notebooks)
  • Submission: Upload to the course learning management system by the deadline
  • Video: Optional video demonstration (up to 2 minutes) showing autonomous navigation can be submitted separately

📊 Grading Rubric

Component Points Evaluation Criteria
Cover Page 5 Complete, professional
Objectives 10 Clear, comprehensive
Procedure & Results 60 All parts documented, clear screenshots, working system
Discussion 20 Analysis of results, challenges, and solutions
Conclusion 5 Reflective, insightful summary
Total 100

Grading Notes:

  • Demonstrated autonomous navigation is required for full credit
  • Screenshots must be clear, labeled, and properly referenced in text
  • Focus on documenting what you did and what you observed
  • Video demonstration (optional) can earn bonus points for exceptional results
  • Late penalty: 10% per day (up to 3 days)
  • Plagiarism will result in zero credit