{"id":19820287,"url":"https://github.com/strcoder4007/need-for-speed-self-driving","last_synced_at":"2026-05-14T04:36:03.341Z","repository":{"id":247543632,"uuid":"825677903","full_name":"strcoder4007/Need-For-Speed-Self-driving","owner":"strcoder4007","description":"Training a ConvNet to play Need for Speed Most Wanted only by looking at the game, just like humans learn. Using AlexNet, OpenCV, Tensorflow 2","archived":false,"fork":false,"pushed_at":"2024-07-14T14:11:26.000Z","size":15776,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-11T08:30:14.477Z","etag":null,"topics":["cnn","convolutional-neural-networks","needforspeed","nfsmw","opencv-python","tensorflow2"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"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/strcoder4007.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-07-08T09:47:46.000Z","updated_at":"2024-08-09T18:27:01.000Z","dependencies_parsed_at":"2025-01-11T08:37:00.519Z","dependency_job_id":null,"html_url":"https://github.com/strcoder4007/Need-For-Speed-Self-driving","commit_stats":null,"previous_names":["strcoder4007/needforspeedmw-convnet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strcoder4007%2FNeed-For-Speed-Self-driving","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strcoder4007%2FNeed-For-Speed-Self-driving/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strcoder4007%2FNeed-For-Speed-Self-driving/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strcoder4007%2FNeed-For-Speed-Self-driving/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strcoder4007","download_url":"https://codeload.github.com/strcoder4007/Need-For-Speed-Self-driving/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241176617,"owners_count":19922732,"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":["cnn","convolutional-neural-networks","needforspeed","nfsmw","opencv-python","tensorflow2"],"created_at":"2024-11-12T10:22:40.119Z","updated_at":"2026-05-14T04:35:58.320Z","avatar_url":"https://github.com/strcoder4007.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Need For Speed Most Wanted Self Driving using Convolution Neural Net\n\n\n\u003ch3\u003e\u003ci\u003eWork in Progress...\u003c/i\u003e\u003c/h3\u003e\n\nMaking an AI which can play Need for Speed Most Wanted only by looking at the game, just like humans learn.\n\nYoutube: https://youtu.be/aJ91NBZnFdM\n\n![Edge Detection](/images/nfsmw1.gif)\n\n## Data Gathering\nCaptured gameplay using python script found in `grabscreen.py`. Run `main.py` to capture screen while playing the game. \nI collected 200,000 images with their corresponding labels i.e keys `w`, `a`, `d`, `wa`, `wd`.\n\n## Training\nThe model was first trained using AlexNet model. Later found out `InceptionResNetV2` performs better and goes deeper to find the artifacts. I trained it on 80,000 manually generated images.\nIn total it took around 2 hours of training on a local Nvidia RTX 4070 Ti Super (16GB).\n\n### Pre-trained Model\nTrained NFS Most Wanted model: https://drive.google.com/file/d/1w0dz0DuLSFUyZmeK18SSDf32u70LbE_M/view?usp=sharing\n\n### Tensorboard Logs\n![Training](/images/training.png)\n\n## Things left to add:\n- [ ] Joystick controls to improve accuracy.\n- [x] Replace AlexNet Model with InceptionResNetV2 Model.\n- [ ] Capturing more data, ideally 1 million images, the model showed signs of improvement until the end.\n- [ ] Write a bot to generate training data as it is tedious to play the same route over and over again.\n- [x] Give the model all 3 color channel input to improve accuracy.\n- [ ] Reinforcement Learning. \n\n## Installation\nCode and software only runs on Windows, and is developed on Windows 11. Although after gathering data on Windows we can train on Linux, but the game runs natively on Windows, as do gamepads and virtual gamepads.\n1. Install Need for Speed Most Wanted (2005)\n2. Install Patch v1.3 for Need for Speed Most Wanted (2005)\n3. Install [NFSMW Extra Options](https://github.com/ExOptsTeam/NFSMWExOpts/releases) (v10.0.0.1338)\n4. Copy configuration for [NFSMW Extra Options](https://github.com/ExOptsTeam/NFSMWExOpts/releases) (`extra/NFSMWExtraOptionsSettings.ini`) to `C:\\Program Files (x86)\\EA GAMES\\Need for Speed Most Wanted\\scripts` \n\n## Reading Data from the Game (Gather training data)\n**start the game:**\n1. Start NFS:MW\n2. Quick Race -\u003e Custom Race -\u003e Circuit\n3. Heritage Heights (or any other)\n4. Laps: 1 or more. (NFSMW ExtraOps required to have more than 6 laps)\n5. Traffic Level: None\n6. Opponents: 0\n7. Difficulty: Any (irrelevant)\n8. Catch Up: Any (irrelevant)\n9. Transmission: Automatic (Manual does not give any advantage in the game)\n10. Wait until the race has started and the 3-2-1 GO! has passed\n\n**How to use this repo**\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/strcoder4007/Need-For-Speed-Self-driving.git\n   cd Need-For-Speed-Self-driving\n   ```\n\n2. Install the required dependencies:\n   ```bash\n   pip install -r requirements.txt\n   ```\n   This command will install all necessary packages including `opencv-python`, `pypiwin32`, and `tensorflow`.\n\n3. To capture screen and gather data for training, first start the game and run `main.py`:\n   ```bash\n   python main.py\n   ```\n   The `.npy` data file will be generated and saved in the root of the folder\n\n4. Using the training data to train the model run:\n   ```bash\n   python train_model.py\n   ```\n   The model weights file `.h5` will be generated in the root of the folder\n   \n6. To do inference on the model. Run the game and then run the following:\n   ```bash\n   python test_model.py\n   ```\n\n7. Monitor training progress and visualize results using Tensorboard visualizations. Logs are stored in the `board` folder. Use it by running:\n    ```bash\n    tensorboard --logdir \"log\"\n\n    \n    ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrcoder4007%2Fneed-for-speed-self-driving","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrcoder4007%2Fneed-for-speed-self-driving","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrcoder4007%2Fneed-for-speed-self-driving/lists"}