A robot navigation project exploring two fundamentally different approaches to the same problem β Supervised Learning (ResNet CNN imitating BFS) and Reinforcement Learning (DQN-LSTM learning through trial and error).
| Supervised (ResNet) | Reinforcement (DQN-LSTM) | |
|---|---|---|
| How it learns | Imitates BFS optimal paths | Trial and error with rewards |
| Needs labels? | β Yes β BFS solutions | β No |
| State input | Full grid (3-channel tensor) | 5Γ5 vision window |
| Actions | 8 directions | 4 directions |
| Architecture | ResNet CNN | DQN-LSTM |
| Generalization | Any grid same size | β Random grids, variable density |
| Training time | ~10-15 min | ~30-60 min |
- Random Grid Generation β generates grids with obstacles, robot
R, and targetT - BFS Optimal Pathfinding β finds shortest path (used as training labels)
- Dataset Creation β each BFS step becomes a
(state, action)training pair - ResNet Training β CNN learns to predict next optimal move from grid state
- Simulation β trained model navigates new unseen grids
- Random Grid Generation β new random grid every episode, variable obstacle density
- DQN-LSTM Agent β 5Γ5 vision window, hidden state carries memory between steps
- Reward Shaping β warm/cold signal toward target + revisit penalty
- Fixed Eval Set β 20 fixed grids measure true generalization (like validation set)
- Early Stopping β stops when 90% success rate achieved on eval set
Input (3 channels):
βββ Channel 0: Obstacle map
βββ Channel 1: Robot position
βββ Channel 2: Target position
β
Initial Conv2D (32 filters) + BN + ReLU
β
Residual Block 1 (32 β 32)
β
Residual Block 2 (32 β 128, with 1Γ1 downsample)
β
Flatten β Dropout(0.6) β FC(128) β Dropout(0.6) β FC(8)
β
Output: 8 actions (UP, DOWN, LEFT, RIGHT, diagonals)
Input (30 values):
βββ 5Γ5 vision window (25 values)
β 0.0=free, 0.5=OOB, 1.0=obstacle, 3.0=target
βββ Normalized robot position (2 values)
βββ Normalized target position (2 values)
βββ Exploration progress (1 value)
β
Encoder: Linear(30β128) β LayerNorm β ReLU β Linear(128β128) β LayerNorm β ReLU
β
LSTM(128β128) β carries memory (h,c) between steps
β
Decoder: Linear(128β64) β ReLU β Linear(64β4)
β
Output: 4 Q-values (UP, DOWN, LEFT, RIGHT)
| Metric | Value |
|---|---|
| Training Samples | 5,000 |
| Grid Size | 15Γ15 |
| Obstacle Density | 25% |
| Epochs | 50 (early stopping) |
| Optimizer | Adam (lr=5e-4, wd=5e-3) |
| Loss | CrossEntropyLoss |
| Metric | Value |
|---|---|
| Grid Size | 15Γ15 |
| Obstacle Density | 10%β35% (random each episode) |
| Episodes | 5000β8000 |
| Optimizer | Adam (lr=1e-3, wd=1e-4) |
| Eval Set | 20 fixed grids |
| Best Success Rate | ~70% on unseen random grids |
GridNav-AI/
βββ README.md
βββ requirements.txt
β
βββ src/
β βββ path_finder.py # Supervised ResNet training + simulation
β βββ reinforcement_lesson_2.py # Q-Table (fixed grid)
β βββ reinforcement_lesson_3.py # DQN (position + target)
β βββ reinforcement_lesson_4.py # DQN blind robot (reward shaping)
β βββ reinforcement_lesson_5.py # DQN-LSTM (5Γ5 vision, random grids) β main RL
β βββ reinforcement_lesson_6.py # BPTT (sequence training, experimental)
β
βββ demo/
β βββ app.py # Streamlit home page
β βββ core/
β β βββ grid_utils.py # Shared grid generation + rendering
β β βββ rl_model.py # DQN-LSTM inference + training
β β βββ supervised_model.py # ResNet inference + training
β βββ pages/
β βββ 1_Training.py # Live training (RL + Supervised)
β βββ 2_Inference.py # Side-by-side model comparison
β βββ 3_Grid_Builder.py # Draw custom grids, benchmark models
β
βββ models/
β βββ stage3_best.pth # Best RL model
β βββ supervised_best.pth # Best supervised model
β
βββ examples/
β βββ robot_animation.gif
β βββ stage3_animation.gif
β βββ training_history.png
β βββ stage3_rewards.png
β
βββ .gitignore
pip install -r requirements.txttorch>=2.0.0
numpy>=1.24.0
matplotlib>=3.7.0
tqdm>=4.65.0
pillow>=9.0.0
streamlit>=1.28.0
plotly>=5.17.0
git clone https://github.com/WeskerPRO/GridNav-AI.git
cd GridNav-AIcd src
python path_finder.pycd src
python reinforcement_lesson_5.pycd demo
streamlit run app.pyThe demo has three pages:
- Training β watch RL agent or ResNet train live with real-time curves
- Inference β load trained models, compare RL vs Supervised side by side
- Grid Builder β draw your own maze, benchmark all models + BFS
π‘ Per-episode reward oscillates on random grids β this is expected. Grid difficulty varies each episode. Use success rate on the fixed eval set as the true learning metric (equivalent to validation accuracy).
β οΈ Train on the same grid size you test on. RL model normalizes positions by grid dimensions β a model trained on 15Γ15 expects 15Γ15 inputs.
π§ The model needs the target coordinates in its state to generalize across random grids. Without them, reward shaping sends contradictory signals on different grid layouts.
- β Random grid generator with guaranteed solvable paths
- β BFS optimal pathfinding for label generation
- β ResNet CNN with residual blocks + Dropout regularization
- β Training with early stopping + LR scheduler
- β Q-Table navigation (fixed grid)
- β DQN with position + target coordinates
- β DQN blind robot with reward shaping
- β DQN-LSTM with 5Γ5 vision window
- β Random grid training for generalization
- β Fixed eval set (validation equivalent for RL)
- β Streamlit demo with live training + inference + grid builder
- β BPTT sequence training (experimental)
- β 3D grid pathfinding (experimental)
- π Model generalization improvement (target: 80%+ success rate)
- Fog of war exploration (partial map reveal)
- Larger grid support (35Γ35+)
This project is licensed under the MIT License β free to use, modify, and distribute.
Made with β€οΈ by WeskerPRO
Supervised Learning meets Reinforcement Learning β same robot, two minds.



