{"id":15414314,"url":"https://github.com/starlitdreams/pacman-convolutional-q-learning","last_synced_at":"2026-04-15T15:43:11.552Z","repository":{"id":257594648,"uuid":"855879733","full_name":"StarlitDreams/pacman-convolutional-q-learning","owner":"StarlitDreams","description":"This project implements a Deep Q-Network (DQN) using PyTorch to train an agent to play Atari's Ms. Pac-Man. It utilizes reinforcement learning with a convolutional neural network (CNN) for image processing. Features include experience replay, frame preprocessing, and CUDA support, with trained model saving and video rendering of gameplay.","archived":false,"fork":false,"pushed_at":"2024-09-18T16:51:05.000Z","size":6519,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-06T02:06:02.257Z","etag":null,"topics":["artificial-intelligence","artificial-neural-networks","atari","cuda","deep-learning","deep-learning-algorithms","deep-q-learning","deeplearning","gymnasium","gymnasium-environment","python","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StarlitDreams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-11T15:52:03.000Z","updated_at":"2024-09-18T16:55:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"15de7dc6-7e08-481a-9bca-0867726436d7","html_url":"https://github.com/StarlitDreams/pacman-convolutional-q-learning","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"7cc5d12ab7c0610abbac0195a0fdc81646c0afeb"},"previous_names":["starlitdreams/pacman-convolutional-q-learning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarlitDreams%2Fpacman-convolutional-q-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarlitDreams%2Fpacman-convolutional-q-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarlitDreams%2Fpacman-convolutional-q-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarlitDreams%2Fpacman-convolutional-q-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StarlitDreams","download_url":"https://codeload.github.com/StarlitDreams/pacman-convolutional-q-learning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246547370,"owners_count":20794970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","artificial-neural-networks","atari","cuda","deep-learning","deep-learning-algorithms","deep-q-learning","deeplearning","gymnasium","gymnasium-environment","python","pytorch"],"created_at":"2024-10-01T17:02:31.450Z","updated_at":"2026-04-15T15:43:11.474Z","avatar_url":"https://github.com/StarlitDreams.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n![DALL·E 2024-09-18 22 05 26 - A retro 8-bit style background in landscape orientation featuring vibrant pixelated elements like clouds, mountains, and stars  The background uses a_ smaller](https://github.com/user-attachments/assets/15736ac3-7ab5-4224-b0bb-f3bb4ac789c7)\n\n## Introduction\n\nThis project implements a Deep Q-Network (DQN) to train an agent to play Atari's *Ms. Pac-Man* using PyTorch and the Gymnasium environment. The agent uses a convolutional neural network (CNN) to process image frames from the game and decide on actions using reinforcement learning principles.\n\n## Features\n\n- **Deep Q-Network (DQN)**: Implements a DQN with experience replay and a target network to stabilize learning.\n- **Ms. Pac-Man Environment**: Uses the Atari *Ms. Pac-Man* environment from Gymnasium to train the agent.\n- **Experience Replay**: A deque buffer stores previous experiences for training the network.\n- **Frame Preprocessing**: Frames are converted to grayscale, resized, and normalized before being fed into the neural network.\n- **CUDA Support**: Leverages GPU computation if available for faster training.\n\n## Installation\n\n1. Clone the repository:\n\n    ```bash\n    git clone https://github.com/yourusername/your-repo-name.git\n    cd your-repo-name\n    ```\n\n2. Install the required Python packages:\n\n    ```bash\n    pip install -r requirements.txt\n    ```\n\n3. Make sure you have [PyTorch](https://pytorch.org/get-started/locally/) installed with CUDA support if you want to train on a GPU.\n\n4. Install [FFmpeg](https://ffmpeg.org/) to render and save videos.\n\n## Usage\n\n### Training the Agent\n\nTo train the agent to play *Ms. Pac-Man*, run the `main.py` script:\n\n```bash\npython main.py\n```\n\nThe agent will train for 2000 episodes, or until the environment is solved with an average score of over 2600. A checkpoint of the trained model will be saved as `checkpoint.pth`.\n\n\n### Watching the Trained Agent\n\nTo watch the agent play using a pre-trained model, run the `show_video.py` script:\n\n```bash\npython show_video.py\n```\n\nIf you have a trained model saved as `checkpoint.pth`, it will load the model and display a video of the agent playing the game.\n\n### Displaying the Video\n\nAfter running `show_video.py`, a video will be created and displayed using the IPython display module. If the video does not display automatically, you can find it saved as `video.mp4` in the project directory.\n\n## Project Structure\n\n```\n├── .gitattributes     # Git configuration file for handling file types\n├── LICENSE            # License file for the project (e.g., MIT License)\n├── README.md          # Project documentation (this file)\n├── checkpoint.pth     # Saved model weights after training\n├── main.py            # The main script to train the agent\n├── requirements.txt   # Python dependencies\n├── show_video.py      # The script to load a trained model and display gameplay\n├── video.mp4          # Generated video of the trained agent playing Ms. Pac-Man\n```\n\n## Hyperparameters\n\n- **Learning Rate**: `1e-4`\n- **Batch Size**: `64`\n- **Gamma**: `0.99`\n- **Epsilon Decay**: `0.995`\n- **Tau**: `1e-3`\n- **Number of Episodes**: `2000`\n- **Max Timesteps per Episode**: `10000`\n\n## Dependencies\n\n- Python 3.9+\n- NumPy\n- PyTorch\n- Gymnasium\n- Pillow\n- ImageIO\n- IPython\n\n## Sample Output\n\nBelow is an example of the output video after the training process is completed:\n\n\n\n![video-ezgif com-video-to-gif-converter](https://github.com/user-attachments/assets/6b06d194-379a-4649-a786-8035ead92a01)\n\n\n\n\n## License\n\nThis project is open-source and licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarlitdreams%2Fpacman-convolutional-q-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarlitdreams%2Fpacman-convolutional-q-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarlitdreams%2Fpacman-convolutional-q-learning/lists"}