Giter VIP home page Giter VIP logo

flappy-bird-deep-q-learning-pytorch's Introduction

[PYTORCH] Deep Q-learning for playing Flappy Bird

Introduction

Here is my python source code for training an agent to play flappy bird. It could be seen as a very basic example of Reinforcement Learning's application.


Result

How to use my code

With my code, you can:

  • Train your model from scratch by running python train.py
  • Test your trained model by running python test.py

Trained models

You could find my trained model at trained_models/flappy_bird

Requirements

  • python 3.6
  • pygame
  • cv2
  • pytorch
  • numpy

flappy-bird-deep-q-learning-pytorch's People

Contributors

uvipen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flappy-bird-deep-q-learning-pytorch's Issues

Error Running Train.py

Flappy-bird-deep-Q-learning-pytorch/src/deep_q_network.py:21: UserWarning: nn.init.uniform is now deprecated in favor of nn.init.uniform_.
nn.init.uniform(m.weight, -0.01, 0.01)
Perform a random action
Iteration: 2/2000000, Action: 1, Loss: 0.010123813524842262, Epsilon 0.1, Reward: 0.1, Q-value: 0.0005683371564373374
Traceback (most recent call last):
File "train.py", line 133, in
train(opt)
File "train.py", line 74, in train
action = torch.argmax(prediction)[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
(python36) bash-3.2$

Error in dimension of image tensor

First of all, thanks for taking the time to put this pytorch implementation together. I am getting the following error. Also can you explain what the purpose of the torch.cat line is?

Traceback (most recent call last):
File "train.py", line 133, in
train(opt)
File "train.py", line 58, in train
state = torch.cat(tuple(image for _ in range(4)))[None, :, :, :]
IndexError: too many indices for tensor of dimension 2

IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

I'm trying out your code and I followed the instructions to leave the environment compatable, I have the following modules installed:

numpy==1.16.3
opencv-contrib-python==4.1.0.25
opencv-python==4.1.0.25
Pillow==6.0.0
protobuf==3.7.1
pygame==1.9.6
six==1.12.0
tensorboardX==1.6
torch==1.0.1
torchvision==0.2.2.post3

But with minor nuances, as I'm using virtualenv to isolate the installed modules.

When executing your code I get the following message:

$ python train.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
.\workspace\MachineLearning\Flappy-bird-deep-Q-learning-pytorch\src\deep_q_network.py:21: UserWarning: nn.init.uniform is now deprecated in favor of nn.init.uniform_.
  nn.init.uniform(m.weight, -0.01, 0.01)
tensor(0)
Traceback (most recent call last):
  File "train.py", line 133, in <module>
    train(opt)
  File "train.py", line 74, in train
    action = torch.argmax(prediction)[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

What I suggest to fix this problem, I have not programmed with Python for some years, and I do not know the frameworks used with Python. I have already used OpenCV with pure C / C ++ on board and succeeded.

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.