Author: Filippo Marcantoni
Course: RBE 577 - Machine Learning for Robotics
Institution: Worcester Polytechnic Institute
This repository contains two main reinforcement learning implementations for Project 3:
A2C/: A single-process implementation of REINFORCE and Advantage Actor-Critic (A2C) on the OpenAI GymLunarLander-v2environment.A3C/: An asynchronous Advantage Actor-Critic (A3C) implementation for a PyBullet KUKA pick-and-place task.
The code includes training, evaluation, checkpoint saving, plotting, and video export for the agent policies.
The project report is available as RBE577_ML_Project3_Report.pdf.
The A2C/ folder implements two policy-gradient methods for the continuous control benchmark LunarLander-v2:
- REINFORCE: Monte Carlo policy gradient with reward-to-go and baseline normalization.
- A2C: Actor-Critic using a learned value function for advantage estimation.
The implementation supports training from configuration JSON files, automatic checkpointing, and reward-history plotting.
- Shared
train.pyentry point for bothreinforceanda2calgorithms. - Actor and critic network modules implemented in
actor.pyandcritic.py. - Observation normalization and environment compatibility between Gym/Gymnasium.
- Evaluation script with deterministic policy execution and optional video export.
A2C/
├── actor.py
├── critic.py
├── compute_objectives.py
├── config_a2c.json
├── config_reinforce.json
├── config.json
├── eval.py
├── train.py
├── utils.py
├── checkpoints/
│ ├── best_actor_critic.pt
│ └── best_reinforce_actor.pt
├── plots/
└── videos/
Training and evaluation are configured using JSON files:
A2C/config_reinforce.json— REINFORCE settingsA2C/config_a2c.json— A2C settings
Common options include:
env_id: environment ID (LunarLander-v2)algorithm:reinforceora2cactor_lr,critic_lrgammahidden_dimnum_episodesmax_ep_stepscheckpoint_pathplot_filename
cd A2C
python train.py --config config_reinforce.jsoncd A2C
python train.py --config config_a2c.jsoncd A2C
python eval.py --config config_a2c.json --checkpoint checkpoints/best_actor_critic.pt --episodes 500cd A2C
python eval.py --config config_reinforce.json --checkpoint checkpoints/best_reinforce_actor.pt --episodes 1 --video reinforce_video1.mp4 --video-seed 101
python eval.py --config config_reinforce.json --checkpoint checkpoints/best_reinforce_actor.pt --episodes 1 --video reinforce_video2.mp4 --video-seed 102
python eval.py --config config_reinforce.json --checkpoint checkpoints/best_reinforce_actor.pt --episodes 1 --video reinforce_video3.mp4 --video-seed 103Video output is written to A2C/videos/.
The A3C/ folder implements the asynchronous advantage actor-critic algorithm for a PyBullet KUKA pick-and-place environment.
The implementation launches multiple worker processes via PyTorch multiprocessing and trains a shared actor-critic network on image-based observations.
- Asynchronous worker processes with shared global parameters.
- CNN-based image preprocessing for the KUKA PyBullet environment.
- Checkpoint saving to
A3C/models/. - Deterministic evaluation and optional success/failure video recording.
A3C/
├── main.py
├── eval.py
├── plot_a3c.py
├── config/
│ ├── a3c.yaml
│ └── common.yaml
├── helpers/
│ ├── __init__.py
│ ├── config.py
│ ├── logger.py
│ ├── metrics.py
│ └── utils.py
├── lib/
│ └── a3c/
│ ├── __init__.py
│ ├── agent.py
│ ├── model.py
│ ├── objectives.py
│ ├── shared_optim.py
│ └── train.py
├── logs/
├── models/
│ ├── a3c_kuka_model_ep1000.pth
│ ├── a3c_kuka_model_ep10000.pth
│ ├── ...
│ └── a3c_kuka_model_final.pth
├── plots/
└── videos/
The A3C configuration is split into:
A3C/config/common.yaml— environment, camera, and device settingsA3C/config/a3c.yaml— A3C training hyperparameters and model architecture settings
Important parameters include:
hyperparameters.num_workershyperparameters.max_episodeshyperparameters.lrnetwork.shared_layersnetwork.actor_hidden_layersnetwork.critic_hidden_layersenv.namedevice
cd A3C
python main.pycd A3C
python eval.py --checkpoint models/a3c_kuka_model_final.pth --episodes 100 --success-threshold 0.5cd A3C
python eval.py --checkpoint models/a3c_kuka_model_final.pth --episodes 100 --success-threshold 0.5 --video a3c_eval.mp4 --video-successes 3 --video-failures 3This project is designed to run in a Python environment with PyTorch, Gym, PyBullet, and standard scientific packages.
A recommended Conda setup is:
conda create -n rl-agent python=3.8 -y
conda activate rl-agent
python -m pip install "pip==23.0.1" "setuptools==65.5.0" "wheel==0.38.4"
conda install -y numpy matplotlib ipython ffmpeg
pip install "imageio[ffmpeg]"
pip install torch==2.4.1+cu121 torchvision==0.19.1+cu121 torchaudio==2.4.1+cu121 \
--index-url https://download.pytorch.org/whl/cu121
pip install gym==0.21.0 Box2D pygame "pyglet<2"
pip install pybullet==3.2.6 pyyamlIf CUDA is unavailable, use the CPU fallback by setting
device: "cpu"inA3C/config/common.yamlor passing--device cputoA3C/eval.py.
A2C/train.pysaves checkpoints and reward plots automatically inA2C/checkpoints/andA2C/plots/.A3C/main.pysaves the final shared policy inA3C/models/a3c_kuka_model_final.pth.A3C/eval.pyreports success rate, average reward, and average episode length for deterministic evaluation runs.- The final project report is in
RBE577_ML_Project3_Report.pdf.