README
Browse files- .gitattributes +1 -0
- README.md +58 -0
- exampleImageMahjongSoul.jpg +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Mahjong Vision Assistant
|
| 2 |
+
|
| 3 |
+
This project uses computer vision and machine learning to provide real-time discard suggestions for the game Mahjong Soul.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
* **Tile Recognition:** Identifies Mahjong tiles from the Mahjong Soul game window using a fine-tuned Vision Transformer model (`pjura/mahjong_soul_vision`).
|
| 8 |
+
* **Game State Analysis:** Parses the recognized tiles to understand the current game state (player's hand, melds, discard pools).
|
| 9 |
+
* **Discard Suggestion:** Employs a neural network (`ImprovedNN`) to predict the optimal discard based on the analyzed game state.
|
| 10 |
+
* **Live Overlay:** Captures the game window and overlays suggestions directly onto the screen, highlighting the recommended discard tile.
|
| 11 |
+
|
| 12 |
+

|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
## Project Structure
|
| 16 |
+
|
| 17 |
+
* `live_feed.py`: The main script to run the live assistant. It captures the screen, performs tile recognition, predicts discards, and displays the overlay.
|
| 18 |
+
* `hf_vision_model.ipynb`: Jupyter notebook detailing the training process for the Hugging Face Vision Transformer used for tile recognition.
|
| 19 |
+
* `tools.py`: Contains utility functions for data processing, model prediction, loss calculation, MLflow interaction, and tile representation translation used by `live_feed.py`. Many cross repo functions.
|
| 20 |
+
* `model.safetensors`: Saved weights for the discard prediction neural network (`ImprovedNN`).
|
| 21 |
+
|
| 22 |
+
## Setup
|
| 23 |
+
|
| 24 |
+
1. **Environment:** Ensure you have Python installed along with necessary libraries. Key libraries include:
|
| 25 |
+
* `torch` (with CUDA support if available)
|
| 26 |
+
* `transformers`
|
| 27 |
+
* `datasets`
|
| 28 |
+
* `evaluate`
|
| 29 |
+
* `opencv-python` (`cv2`)
|
| 30 |
+
* `Pillow` (`PIL`)
|
| 31 |
+
* `pygetwindow`
|
| 32 |
+
* `numpy`
|
| 33 |
+
* `pyautogui`
|
| 34 |
+
* `keyboard`
|
| 35 |
+
* `safetensors`
|
| 36 |
+
* `mlflow` (Optional, used in `tools.py`, you can use whatever you like to serve the model)
|
| 37 |
+
* `scipy`
|
| 38 |
+
* `matplotlib`
|
| 39 |
+
*(A `requirements.txt` file would be beneficial here, but didn't made one at the time)*
|
| 40 |
+
|
| 41 |
+
2. **Models:**
|
| 42 |
+
* The tile recognition model (`pjura/mahjong_soul_vision`) will be downloaded automatically by the `transformers` library.
|
| 43 |
+
* The discard prediction model (`model.safetensors`) should be present in the root directory.
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
1. Ensure the Mahjong Soul game window is open and titled "MahjongSoul".
|
| 48 |
+
2. Run the main script:
|
| 49 |
+
```bash
|
| 50 |
+
python live_feed.py
|
| 51 |
+
```
|
| 52 |
+
3. The script will capture the game window, analyze the tiles, and highlight the suggested discard tile in the player's hand region. The color of the highlight indicates the model's confidence (Green=High, Red=Low).
|
| 53 |
+
4. Press 'q' to quit the application.
|
| 54 |
+
|
| 55 |
+
## Notes
|
| 56 |
+
|
| 57 |
+
* The script relies on specific window coordinates and aspect ratios which might need adjustment depending on screen resolution and game layout.
|
| 58 |
+
* The discard prediction model (`ImprovedNN` loaded from `model.safetensors`) is based on the [pjura/mahjong_ai](https://huggingface.co/pjura/mahjong_ai) model from Hugging Face. It was trained on the `pjura/mahjong_board_states` dataset, primarily using the `tenhou_prediction_deepLearning_basic.ipynb` notebook as detailed on the model card. The local `model.safetensors` may not be the latest version available on the Hub. You can add your own logic
|
exampleImageMahjongSoul.jpg
ADDED
|
Git LFS Details
|