Giter Site home page Giter Site logo

javirk / dino-ai Goto Github PK

View Code? Open in Web Editor NEW
19.0 6.0 1.0 44 KB

An AI to teach Google Chrome's dinosaur to jump obstacles.

Python 100.00%
neural-network artificial-neural-networks artificial-intelligence genetic-algorithm evolutionary-algorithm dinosaur-game python

dino-ai's Introduction

Dino-AI

An AI to teach Google Chrome's dinosaur to jump obstacles. The sample of a working model can be viewed at https://www.linkedin.com/feed/update/urn:li:activity:6439502467947331584

Getting started

All the code was written on Python, using Tensorflow.

Prerequisites

This program has been succesfully built using:

dash_core_components==0.26.0
tensorflow==1.10.0
numpy==1.15.0
dash_html_components==0.11.0
dash==0.23.1
plotly==3.1.0
pynput==1.4
selenium==3.13.0

Together with Python 3.6.

Installation

  1. Install python 3.6
  2. Install all dependencies
  3. Clone/download this folder
  4. Modify parameters at your taste (number of cells in each layer, hyperparameters...)
  5. Run Main.py (python Main.py) to start the program without the GUI
  6. Run also gui_v2.py (python gui_v2.py) to establish a connection with the GUI
  7. Navigate to 127.0.0.1:8050 on your browser to open the GUI

You have to note that all the key press work with Selenium, so you can move around and minimise windows while the program is running.

On PyCharm it is possible to create a Multirun configuration that runs first the GUI and then the Main program, so it is easier.

Both programs work independently, so Main will work perfectly without the GUI.

To quit the program, you can press the "End" key, it will stop when the current generation has finished and after saving all the models in use.

Details

In every iteration, while the dinosaur is not crashed, the program reads 4 inputs:

  1. Distance until next object (X)
  2. Y position of next object
  3. Current speed, adjusting the "Speed offset", if any
  4. Size

There is only output, ranging from 0 to 1:

  1. output < 0.45: Press DOWN key
  2. output > 0.55: Press UP key
  3. default: pass

This version uses a genetic algorithm to evolve the network from random weights and biases to working parameters. Each generation has a number of genomes, and each of them is tested until it crashes. When this happens, the score is saved as the fitness of that genome.

When all the genomes in a generation are completed, the highest scores are selected and kept for the next generation. The rest of genomes are calculated by crossover and/or mutating them. The genomes that take part in these processes of crossover and mutation are chosen at random, but attending to the score each one has achieved. To reach this, a very simple probability distribution is calculated, so the highest score gets more probability of being chosen as a basis for next generations.

Implementation

The implementation has been done entirely on Python, using Tensorflow and Selenium to interact with the JS of the game.

These are the files on the project:

  • Dino.py: it contains two classes: Game and Dino. The first is responsible for communicating with the browser. The latter gets the inputs of the game and sends them to the controller.
  • Main.py: it joins all the other scripts
  • genome.py: This script does everything: mutation, crossover, control of generations...
  • gui_v2.py: All the gui related functions
  • keys.py: A short script to stop the program by pressing End key
  • perceptron_2l.py: Makes the Neural Networks, gets dictionaries to use them, etc.

dino-ai's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

vickyjnv

dino-ai's Issues

no attribute named session

my command line output

(base) C:\Users\finnx\Dino-AI>python Main.py
2021-06-07 11:07:49.704221: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-06-07 11:07:49.704373: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
0
Traceback (most recent call last):
  File "Main.py", line 27, in <module>
    genome = Genome(numGenes, mutationProb, selection, folder,  nGenerations)
  File "C:\Users\finnx\Dino-AI\genome.py", line 31, in __init__
    self.build_genome()
  File "C:\Users\finnx\Dino-AI\genome.py", line 37, in build_genome
    network = Perceptron(self.folder, len(self.genes))
  File "C:\Users\finnx\Dino-AI\perceptron_2l.py", line 24, in __init__
    sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))
AttributeError: module 'tensorflow' has no attribute 'Session'

help!

Add "How to build/run" on README

Hi @javirk ๐Ÿ‘‹

I suggest you add to the README information on how to build/run this project locally, also the versions of any dependencies, so anyone who'd like to contribute finds it easier to test locally.

Nice project ๐Ÿ‘ ๐Ÿ‘

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.