Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elucidation/chessboardfentensorflowjs
Find chessboard FEN from a screenshot using TensorflowJs
https://github.com/elucidation/chessboardfentensorflowjs
chess chessboard tensorflow tensorflow-examples tensorflow-js
Last synced: 2 months ago
JSON representation
Find chessboard FEN from a screenshot using TensorflowJs
- Host: GitHub
- URL: https://github.com/elucidation/chessboardfentensorflowjs
- Owner: Elucidation
- License: mit
- Created: 2018-06-27T03:16:13.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T22:24:05.000Z (11 months ago)
- Last Synced: 2024-11-02T06:31:07.064Z (3 months ago)
- Topics: chess, chessboard, tensorflow, tensorflow-examples, tensorflow-js
- Language: JavaScript
- Homepage: http://www.tetralark.com/ChessboardFenTensorflowJs/
- Size: 15.9 MB
- Stars: 19
- Watchers: 3
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TensorflowJs Chessboard Prediction from Screenshots in HTML5
Given a screenshot of a chessboard from lichess.org/chess.com, it tries to find the chessboard and pieces on it, [*Try it yourself*](http://elucidation.github.io/ChessboardFenTensorflowJs/).
![image](https://github.com/Elucidation/ChessboardFenTensorflowJs/assets/434925/c6b0b2a3-452e-49b9-b59b-dd41efad217c)
## How it works
This uses a frozen [Tensorflow Chessbot](https://github.com/Elucidation/tensorflow_chessbot/tree/chessfenbot) model. Unlike that repo this runs completely in javascript using [TensorflowJs](https://js.tensorflow.org/), all client-side.
### Board detection
Finds and separates out the chessboard into a 256x256 px image containing the 32x32 tiles of the chessboard.
A very simplified chessboard detector is implemented. It requires the board to mostly fill up the image, be very well aligned and centered. In comparison chessfenbot can find aligned chessboards all around the image. [Issue #2](https://github.com/Elucidation/ChessboardScreenshotHtml5/issues/2)The image is blurred and then the sobel gradients X and Y are used to find strong vertical and horizontal edges in the image corresponding to the chessboard. This is used to guess the bounds of the chessboard, and then generate a 256x256 px grayscale image as input for the tensorflow model.
### ML Prediction
Given 256x256px aligned chessboard image, it runs a TensorflowJs model to predict pieces on it.
The model was trained using 32x32 px grayscale tiles of chessboard pieces. For each tile it independently predicts one of 13 classes, 6 white pieces, 6 black pieces, or an empty tile.
We freeze the model graph and weights from [Tensorflow Chessbot](https://github.com/Elucidation/tensorflow_chessbot/tree/chessfenbot), and load it up in Javascript using TensorflowJs, allowing everything to run without a server.
![image](https://github.com/Elucidation/ChessboardFenTensorflowJs/assets/434925/ca922b19-5d97-48dd-9bf5-4cffe56db79d)
## Running locally
A web server of some sort is needed to allow cross-origin sharing when running locally.
For example, one can use
```python -m http.server```
or
```
http-server -o --cors -c-1 -a localhost
```