Live at https://natpat.net/boggle
A Web App for solving Boggle Boards. No server-side processing is required - everything runs in browser.
Technologies used:
- FastAPI
- PyTorch
- OpenCV
- OnnxRuntime
No front end framework - just vanilla HTML/CSS/JS.
At a high level, the app does the following:
- Takes an image of a Boggle board as input - a grid is overlaid on the image to help the user align it properly
- The image is split into individual dice
- Each die is pre-processed using OpenCV
- The pre-processed images are passed through a CNN to recognize the letters on the dice
- The detected letters are shown to the user for confirmation
- The letters are passed to a word search algorithm that finds all valid words on the board
- The found words are displayed to the user, sorted by length and score
- The user can tap on words to see their paths on the board
The letter recognition model is a small, custom CNN trained on a dataset of Boggle dice images. The dataset was created by taking photos of Boggle boards, splitting the images into individual dice, and labeling the letters on each die.
The model was trained using PyTorch and then converted to ONNX format for use in the web app with OnnxRuntime. The model achieves around 95% accuracy on a validation set.
This repository uses uv for local development.
The Web App can be served by serving everything in the static/ directory. For convenience, the development server (used for collecting training data and labelling) will also serve the static files. Run
uv run fastapi dev main.py --port 8000And navigate to http://localhost:8000/ to see the app.
In order to run, the app requires:
- A trained letter recognition model in ONNX format, named
boggle_cnn.onnxin thestatic/directory. You can:- train your own using the code in
train_model.py(see the Training section below) - contact me (find my email on e.g. my website) if you want the dataset used to train - download the model here
- train your own using the code in
- At least one trie file in
static/tries/, along with a metadata file- these can be generated using the code in
make_word_lsit.pyandgenerate_tries.py- this also assumes you have a copy of SCOWL downloaded - or contact me if you want the tries I generated
- these can be generated using the code in
To train the letter recognition model, you will need:
- a folder containing images of individual Boggle dice, pre-processed and named
<image_id>_processed.png(e.g.0001_processed.png), atimages/ - a
labels.jsonfile mapping image ids to their corresponding letters, e.g.{"0001": "A", "0002": "B", ...}
You can then run
uv run model.pyto train the model. The trained model will be saved as boggle_cnn.onnx.
A server is provided to collect training data and help label it.
To run the server, use:
uv run fastapi dev main.py --port 8000In static/script.js, set DATA_COLLECTION to true to enable data collection mode. This will store the raw and processed images of each die, along with a unique id, in the images/ folder.
To label the collected data, navigate to http://localhost:8000/static/labeller.html on the running server. This page will show each collected image and allow you to enter the corresponding letter. The labels will be saved in labels.json.
