Code Monkey home page Code Monkey logo

tetris-deep-q-learning-pytorch's Introduction

[PYTORCH] Deep Q-learning for playing Tetris

Introduction

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


Tetris demo

The demo could also be found at youtube demo

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/tetris

Requirements

  • python 3.6
  • PIL
  • cv2
  • pytorch
  • numpy
  • matplotlib

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

tetris-deep-q-learning-pytorch's Issues

Training Time

Thank you very much for sharing! I am just wondering how many epochs did you train to reach the checkpoint that you posted.

DeepQNetwork has no attribute "fc1"

hey there buddy, I get this error while trying to run test.py.
AttributeError: 'DeepQNetwork' object has no attribute 'fc1'

Checking your class, there's an fc1 attribute but you're using it as a function?

image

requirement.txt

Hey! Great work, that could be a great example in ML courses.
It would maybe benefit from having a pip requirement.txt files that would automatize the install:

Pillow==7.0.0
opencv-python==4.2.0.32
torch==1.4.0
numpy==1.18.2
matplotlib==3.0.3

and the installation would sum up to:

python3 -m pip install -r requirement.txt

What does env.get_next_states() return?

What does env.get_next_states() return?

'next_state' shows
tensor([ 0., 75., 5., 107.], device='cuda:0')

'next_actions' shows
((0, 0),
(1, 0),
... ,
(8, 3))

Blurry Tetris Pieces

Found that when running this on my machine the Tetris pieces were incredibly blurry.

image

Changing Line 242 in src/tetris.py from

img = img.resize((self.width * self.block_size, self.height * self.block_size))

to

img = img.resize((self.width * self.block_size, self.height * self.block_size),0)

solved the issue by forcing 0 antialiasing on resize.

Python 3.8
Mac OS 10.15.3

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.