Git Product home page Git Product logo

chessboard_classification's Introduction

Classification of chess boards using TensorFlow

Summary

This repository explores the ability of a convolutional neural network (TensorFlow) to classify chess board images into a vector ([0,1]^64) that encodes whether or not a piece is on a given square. Input images are 180x180px gray scale pngs and the output is a vector of 1's and 0's of length 64. Training/validation/test data is gathered artificially using a python library that produces chessboard images. Images are rotated by a random amount (both positive and negative) to increase generalizability of the model. The neural network was trained using ~1 million examples and tested on new unseen boards (again generated by a random artificial method). The overall accuracy of the model was 91% and 72%, at the grid and board level respectively.

Data Generation

For this particular project we used the python-chess package to generate random chessboards for train, test and validation sets. The generation algorithm with randomly select (or not) a chess piece of any type from both colors and place it on a given grid. We enforce that both color kings are present on the board and that no pawns exists on the 1st and 8th rank. We save the board on disk with a specific filename such that we can encode the type and location of each piece. The names of each image is 64 characters long with each character of the name corresponding to a given square on the chessboard. The specific character encodes the actual piece while the case encodes the color of the piece. For example, a capital Q corresponds to a black queen where a lower-case k corresponds to a white king. Knights are assigned the character N or n for black or white respectively. We also append the angle of rotation to the end of the filename. From this naming convention we can extract the output vector that we will use as the target of this neural network. Each output vector element encodes the boolean occupancy of an individual square within the 8x8 chessboard grid. For example, the first element in the 64 element vector may correspond to the square A1, such that, if a piece exists on that square that element would be 1 and 0 otherwise. Using the method above we generate approx 1 million images for training and generate approx 10,000 images for both validation and test.

Image Examples

QxxbxxxxxqxxnNqxxxRqxxxxxrxQxxxxxkbrxxxxPxrxxKxxrxxxxxxxqBnRxrxx QBkqRBrQPQQpPKqrBnrNPQrNrrbRbpbpBNnNBNBBnNpbRrpqnbpnbBQpqBqRRRbb xxNnxxxxxrPRxKxxxrRxxxNxxxBxxxxxPnxxkRbNqxxxxqxxBrxnxrpxxqxbNxNQ xxxxxxkxxBxqxxxxNxxxxxxrxxxxxxxpxKxxxxxxxxxQxxqxxxxpxxxxxRxxbbxx

Results

We report two test set accuracies here. The first accuracy is on the square level, which is defined as sum(correct square prediction)/total_number_of_squares. The second accuracy is on the board level. The board level accuracy is much more demanding than the square level and its defined as total_number_of_entire_boards_correct/total_number_of_boards. For example assume the algorithm correctly identifies pieces on 60/64 squares, the square level accuracy would be 60/64 but the board level accuracy would be 0 for that particular board since it didn’t guess the entire board correctly.

Type Train Set Accuracy Test Set Accuracy
Square 97% 96%
Board 76% 72%

chessboard_classification's People

Contributors

arbitamrazian avatar

Watchers

James Cloos avatar

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.