{"id":15674493,"url":"https://github.com/elucidation/chessboardfentensorflowjs","last_synced_at":"2025-07-02T09:33:15.561Z","repository":{"id":140524050,"uuid":"138824027","full_name":"Elucidation/ChessboardFenTensorflowJs","owner":"Elucidation","description":"Find chessboard FEN from a screenshot using TensorflowJs","archived":false,"fork":false,"pushed_at":"2024-02-29T22:24:05.000Z","size":16673,"stargazers_count":23,"open_issues_count":5,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T22:11:36.413Z","etag":null,"topics":["chess","chessboard","tensorflow","tensorflow-examples","tensorflow-js"],"latest_commit_sha":null,"homepage":"http://www.tetralark.com/ChessboardFenTensorflowJs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Elucidation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-06-27T03:16:13.000Z","updated_at":"2025-04-19T20:37:08.000Z","dependencies_parsed_at":"2024-02-29T23:37:04.630Z","dependency_job_id":null,"html_url":"https://github.com/Elucidation/ChessboardFenTensorflowJs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Elucidation/ChessboardFenTensorflowJs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elucidation%2FChessboardFenTensorflowJs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elucidation%2FChessboardFenTensorflowJs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elucidation%2FChessboardFenTensorflowJs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elucidation%2FChessboardFenTensorflowJs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Elucidation","download_url":"https://codeload.github.com/Elucidation/ChessboardFenTensorflowJs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elucidation%2FChessboardFenTensorflowJs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263111647,"owners_count":23415496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chess","chessboard","tensorflow","tensorflow-examples","tensorflow-js"],"created_at":"2024-10-03T15:45:38.242Z","updated_at":"2025-07-02T09:33:15.499Z","avatar_url":"https://github.com/Elucidation.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TensorflowJs Chessboard Prediction from Screenshots in HTML5\n\nGiven 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/).\n\n![image](https://github.com/Elucidation/ChessboardFenTensorflowJs/assets/434925/c6b0b2a3-452e-49b9-b59b-dd41efad217c)\n\n## How it works\n\nThis 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. \n\n### Board detection\n\nFinds and separates out the chessboard into a 256x256 px image containing the 32x32 tiles of the chessboard.\nA 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)\n\nThe 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.\n\n\u003cimg src=\"readme_gradient_find.png\" width=300px\u003e\n\n### ML Prediction\n\nGiven 256x256px aligned chessboard image, it runs a TensorflowJs model to predict pieces on it.\n\nThe 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.\n\nWe 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.\n\n![image](https://github.com/Elucidation/ChessboardFenTensorflowJs/assets/434925/ca922b19-5d97-48dd-9bf5-4cffe56db79d)\n\n## Running locally\n\nA web server of some sort is needed to allow cross-origin sharing when running locally.\n\nFor example, one can use \n\n```python -m http.server```\n\nor\n\n```\nhttp-server -o --cors -c-1 -a localhost\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felucidation%2Fchessboardfentensorflowjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felucidation%2Fchessboardfentensorflowjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felucidation%2Fchessboardfentensorflowjs/lists"}