Commit
·
ac197d4
verified
·
0
Parent(s):
Duplicate from HichTala/draw
Browse files- .gitattributes +36 -0
- README.md +201 -0
- beit_ygo_fusion.pth +3 -0
- beit_ygo_monster.pth +3 -0
- beit_ygo_normal_monster.pth +3 -0
- beit_ygo_ritual.pth +3 -0
- beit_ygo_spell.pth +3 -0
- beit_ygo_trap.pth +3 -0
- config.json +0 -0
- model.safetensors +3 -0
- training_args.bin +3 -0
- yolo_ygo.pt +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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 |
+
figures/banner-draw.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 4 |
+
- en
|
| 5 |
+
---
|
| 6 |
+
<div align="center">
|
| 7 |
+
<p>
|
| 8 |
+
<a href="https://www.github.com/hichtala/draw" target="_blank">
|
| 9 |
+
<img src="https://raw.githubusercontent.com/HichTala/draw/master/figures/banner-draw.png">
|
| 10 |
+
</p>
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
DRAW (which stands for **D**etect and **R**ecognize **A** **W**ild range of cards) is the very first object detector
|
| 14 |
+
trained to detect _Yu-Gi-Oh!_ cards in all types of images, and in particular in dueling images.
|
| 15 |
+
|
| 16 |
+
Other works exist (see [Related Works](#div-aligncenterrelated-worksdiv)) but none is capable of recognizing cards during a duel.
|
| 17 |
+
|
| 18 |
+
DRAW is entirely open source and all contributions are welcome.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
</div>
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
## <div align="center">📄Documentation</div>
|
| 25 |
+
|
| 26 |
+
<details open>
|
| 27 |
+
<summary>
|
| 28 |
+
Install
|
| 29 |
+
</summary>
|
| 30 |
+
|
| 31 |
+
Both a docker installation and a more conventional installation are available. If you're not very familiar with all the code,
|
| 32 |
+
docker installation is recommended. Otherwise, opt for the classic installation.
|
| 33 |
+
|
| 34 |
+
#### Docker installation
|
| 35 |
+
|
| 36 |
+
If you are familiar with docker, the docker image is available [here](https://hub.docker.com/r/hichtala/draw).
|
| 37 |
+
|
| 38 |
+
Otherwise, I recommend you to download [DockerDesktop](https://www.docker.com/products/docker-desktop/) if you are on Windows.
|
| 39 |
+
If you are on Linux, you can refer to the documentation [here](https://docs.docker.com/engine/install/).
|
| 40 |
+
|
| 41 |
+
Once it is done, you simply have to execute the following command,
|
| 42 |
+
```shell
|
| 43 |
+
docker run -p 5000:5000 --name draw hichtala/draw:latest
|
| 44 |
+
```
|
| 45 |
+
Your installation is now completed. You can press `Ctrl+C` and continue to Usage section.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
#### Classic installation
|
| 49 |
+
|
| 50 |
+
You need python to be installed. Python installation isn't going to be detailed here, you can refer to the [documentation](https://www.python.org/).
|
| 51 |
+
|
| 52 |
+
We first need to install pytorch. It is recommended to use a package manager such as [miniconda](https://docs.conda.io/projects/miniconda/en/latest/).
|
| 53 |
+
Please refer to the [documentation](https://docs.conda.io/projects/miniconda/en/latest/).
|
| 54 |
+
|
| 55 |
+
When everything is set up you can run the following command to install pytorch:
|
| 56 |
+
```shell
|
| 57 |
+
python -m pip install torch torchvision
|
| 58 |
+
```
|
| 59 |
+
If you want to use you gpus to make everything run faster, please refer the [documentation](https://pytorch.org/get-started/locally/)
|
| 60 |
+
|
| 61 |
+
Then you just have to clone the repo and install `requirements`:
|
| 62 |
+
```shell
|
| 63 |
+
git clone https://github.com/HichTala/draw
|
| 64 |
+
cd draw
|
| 65 |
+
python -m pip install -r requirements.txt
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
Your installation is now completed.
|
| 69 |
+
|
| 70 |
+
</details>
|
| 71 |
+
|
| 72 |
+
<details open>
|
| 73 |
+
<summary>Usage</summary>
|
| 74 |
+
|
| 75 |
+
Now to use it you need to download the models and the data, in section [Models and Data](#div-aligncentermodels-and-datadiv).
|
| 76 |
+
|
| 77 |
+
Once you have it, follow instruction depending on you have docker or classic installation.
|
| 78 |
+
Put all the model in the same folder, and keep the dataset as it is
|
| 79 |
+
|
| 80 |
+
#### Docker installation
|
| 81 |
+
|
| 82 |
+
You have to copy the data and models in the container. Execute the following command:
|
| 83 |
+
|
| 84 |
+
```shell
|
| 85 |
+
docker cp path/to/dataset/club_yugioh_dataset draw:/data
|
| 86 |
+
docker cp path/to/model/folder draw:/models
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
Once it is done you just have to run the command:
|
| 90 |
+
```shell
|
| 91 |
+
docker start draw
|
| 92 |
+
```
|
| 93 |
+
open the adress `localhost:5000`, and enjoy the maximum. Refer [bellow](#both) for details about parameters
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
#### Classic installation
|
| 97 |
+
|
| 98 |
+
You need to modify the `config.json` file by putting the paths of you dataset folder in `"data_path"` parameter
|
| 99 |
+
and the path to model folder in `"trained_models"` parameter.
|
| 100 |
+
|
| 101 |
+
Once done, just run:
|
| 102 |
+
```shell
|
| 103 |
+
flask --app app.py run
|
| 104 |
+
```
|
| 105 |
+
open the adress `localhost:5000`, and enjoy the maximum. Refer [bellow](#both) for details about parameters
|
| 106 |
+
|
| 107 |
+
#### Both
|
| 108 |
+
|
| 109 |
+
* In the first parameter, the one with gears, put the `config.json` file
|
| 110 |
+
* In the second parameter, the one with a camera, put the video you want to process (leave it empty to use your webcam)
|
| 111 |
+
* In the last one, put your deck list in the format `ydk`
|
| 112 |
+
|
| 113 |
+
Then you can press the button and start the process !
|
| 114 |
+
|
| 115 |
+
</details>
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
## <div align="center">⚙️Models and Data</div>
|
| 119 |
+
|
| 120 |
+
<details open>
|
| 121 |
+
<summary>Models</summary>
|
| 122 |
+
|
| 123 |
+
In this project, the tasks were divided so that one model would locate the card and another model would classify them.
|
| 124 |
+
Similarly, to classify the cards, I divided the task so that there is one model for each type of card,
|
| 125 |
+
and the model to be used was determined by the color of the card.
|
| 126 |
+
|
| 127 |
+
Models can be downloaded in <a href="https://huggingface.co/HichTala/draw">Hugging Face</a>.
|
| 128 |
+
Models starting with `beit` stands for classification and the one starting with `yolo` for localization.
|
| 129 |
+
|
| 130 |
+
[](https://huggingface.co/HichTala/draw)
|
| 131 |
+
|
| 132 |
+
For now only models for "retro" gameplay are available but the ones for classic format play will be added soon.
|
| 133 |
+
I considered "retro" format all cards before the first _syncro_ set, so all the cards edited until Light of Destruction set (LODT - 05/13/2008) set and all speed duel cards.
|
| 134 |
+
|
| 135 |
+
</details>
|
| 136 |
+
|
| 137 |
+
<details open>
|
| 138 |
+
<summary>Data</summary>
|
| 139 |
+
|
| 140 |
+
To create a dataset, the <a href="https://ygoprodeck.com/api-guide/">YGOPRODeck</a> api was used. Two datasets were thus created,
|
| 141 |
+
one for "retro" play and the other for classic format play. Just as there is a model for each type of card,
|
| 142 |
+
there is a dataset for each type of card.
|
| 143 |
+
|
| 144 |
+
Dataset can be downloaded in <a href="">Hugging Face</a>.
|
| 145 |
+
|
| 146 |
+
[](https://huggingface.co/datasets/HichTala/yugioh_dataset)
|
| 147 |
+
|
| 148 |
+
For now only "retro" dataset is available, but the one for classic format play will be added soon.
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
</details>
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
## <div align="center">💡Inspiration</div>
|
| 156 |
+
|
| 157 |
+
This project is inspired by content creator [SuperZouloux](https://www.youtube.com/watch?v=64-LfbggqKI)'s idea of a hologram bringing _Yu-Gi-Oh!_ cards to life.
|
| 158 |
+
His project uses chips inserted under the sleeves of each card,
|
| 159 |
+
which are read by the play mat, enabling the cards to be recognized.
|
| 160 |
+
|
| 161 |
+
Inserting the chips into the sleeves is not only laborious, but also poses another problem:
|
| 162 |
+
face-down cards are read in the same way as face-up ones.
|
| 163 |
+
So an automatic detector is a really suitable solution.
|
| 164 |
+
|
| 165 |
+
Although this project was discouraged by _KONAMI_ <sup>®</sup>, the game's publisher (which is quite understandable),
|
| 166 |
+
we can nevertheless imagine such a system being used to display the cards played during a live duel,
|
| 167 |
+
to allow spectators to read the cards.
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
## <div align="center">🔗Related Works</div>
|
| 171 |
+
|
| 172 |
+
Although to my knowledge `draw` is the first detector capable of locating and detecting _Yu-Gi-Oh!_ cards in a dueling environment,
|
| 173 |
+
other works exist and were a source of inspiration for this project. It's worth mentioning them here.
|
| 174 |
+
|
| 175 |
+
[Yu-Gi-Oh! NEURON](https://www.konami.com/games/eu/fr/products/yugioh_neuron/) is an official application developed by _KONAMI_ <sup>®</sup>.
|
| 176 |
+
It's packed with features, including cards recognition. The application is capable of recognizing a total of 20 cards at a time, which is very decent.
|
| 177 |
+
The drawback is that the cards must be of good quality to be recognized, which is not necessarily the case in a duel context.
|
| 178 |
+
What's more, it can't be integrated, so the only way to use it is to use the application.
|
| 179 |
+
|
| 180 |
+
[yugioh one shot learning](https://github.com/vanstorm9/yugioh-one-shot-learning) made by `vanstorm9` is a
|
| 181 |
+
Yu-Gi-Oh! cards classification program that allow you to recognize cards. It uses siamese network to train its classification
|
| 182 |
+
model. It gives very impressive results on images with a good quality but not that good on low quality images, and it
|
| 183 |
+
can't localize cards.
|
| 184 |
+
|
| 185 |
+
[Yolov8](https://github.com/ultralytics/ultralytics) is the last version of the very famous `yolo` family of object detector models.
|
| 186 |
+
I think it doesn't need to be presented today, it represents state-of-the-art real time object detection model.
|
| 187 |
+
|
| 188 |
+
[BEiT](https://arxiv.org/pdf/2106.08254.pdf) is a pre-trained model for image classification. It uses image transofrmers
|
| 189 |
+
which are based on attention mechanism. It suits our problem because authors also propose a pre-trained model in `Imagenet-22K`.
|
| 190 |
+
It is a dataset with 22k classes (more than most classifiers) which is interesting for our case since there is mode than 11k cards in _Yu-Gi-Oh!_.
|
| 191 |
+
|
| 192 |
+
---
|
| 193 |
+
## <div align="center">🔍Method Overview</div>
|
| 194 |
+
|
| 195 |
+
A medium blog will soon be written and published, explaining the main process from data collection to final prediction.
|
| 196 |
+
If you have any questions, don't hesitate to open an issue.
|
| 197 |
+
|
| 198 |
+
---
|
| 199 |
+
## <div align="center">💬Contact</div>
|
| 200 |
+
|
| 201 |
+
You can reach me on Twitter [@tiazden](https://twitter.com/tiazden) or by email at [hich.tala.phd@gmail.com](mailto:hich.tala.phd@gmail.com).
|
beit_ygo_fusion.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ea22dacc507b1a20c844595fa6171e1a370aca565e470c91f5337ae778254da
|
| 3 |
+
size 1034425794
|
beit_ygo_monster.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a81514741748d1d04102cf300f1d1172ee02d6486cd2ca13059011faa38e89f7
|
| 3 |
+
size 1046228418
|
beit_ygo_normal_monster.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9e5b6d025af25245e79d72db583a4c031714b28746d318433fe2fa8c945bcdc
|
| 3 |
+
size 1037406594
|
beit_ygo_ritual.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:afc52b14fc7d3390cb7d86c3030c5d237d4f04ec9ac97047943ad3a63a3700bf
|
| 3 |
+
size 1033410818
|
beit_ygo_spell.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5009d87242428c46dd199fafe1dbdfa4233b0992e1f36f2a7ad498fa4ef9a8c4
|
| 3 |
+
size 1039999554
|
beit_ygo_trap.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:037093e2a70354dde01d7e8a722034ea71a12aa0e340b2477167f4fab02935fb
|
| 3 |
+
size 1038689090
|
config.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:abf9c3d0a71ee7a1bc1c570052b596b06393af3e4ba17e9093552acf0afb4aef
|
| 3 |
+
size 383698080
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65a1e0c5a18ede65469ee0067bf2bfc71ff7cddef36449f66f5f0fb7f1b89069
|
| 3 |
+
size 5304
|
yolo_ygo.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c11d56b91853ae00a0c2c387fb8e567342aa4a06c65f1f3ea08720334d50eeee
|
| 3 |
+
size 6223907
|