jeu_du_semaphore_dans_le_blender_game_engine
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
jeu_du_semaphore_dans_le_blender_game_engine [2019/02/06 15:07] – [Création de 70 000 images] serge | jeu_du_semaphore_dans_le_blender_game_engine [2020/12/27 15:06] (Version actuelle) – serge | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Jeu du sémaphore dans le Blender Game Engine ====== | ====== Jeu du sémaphore dans le Blender Game Engine ====== | ||
- | <WRAP center round box 80% centeralign> | + | |
- | **{{tagpage> | + | <WRAP center round box 60% centeralign> |
+ | **{{tagpage> | ||
</ | </ | ||
+ | <WRAP center round box 60% centeralign> | ||
+ | **[[les_pages_intelligence_artificielle_en_details|Les Pages Intelligence Artificielle en détails]]** | ||
+ | </ | ||
+ | |||
+ | <WRAP center round box 60% centeralign> | ||
+ | **{{tagpage> | ||
+ | </ | ||
+ | <WRAP center round box 60% centeralign> | ||
+ | C'est quoi un sémaphore ? | ||
+ | {{ youtube> | ||
+ | </ | ||
+ | {{ media_05: | ||
+ | \\ \\ \\ | ||
+ | <WRAP center round box 60% centeralign> | ||
+ | Des images pour l' | ||
+ | {{media_01: | ||
+ | {{media_01: | ||
+ | {{media_01: | ||
+ | </ | ||
+ | |||
+ | |||
- | Une image pour l' | ||
- | Une image à décrypter {{shot_98_e.png? | ||
===== Le projet sur Github ===== | ===== Le projet sur Github ===== | ||
* **[[https:// | * **[[https:// | ||
+ | * **Réalisé sur Debian 10 Buster**, ne fonctionne pas sur Win$ | ||
+ | * **python 3.7** | ||
- | ===== Etape 1 ===== | ||
- | ====Création de 70 000 images==== | ||
- | Dans un jeu Blender, 70 000 images sont créées, 60 0000 pour entraîner l'IA, 10 000 pour la tester. | ||
- | Ce jeu lit des textes en latin, sans caractères accentués ni spéciaux. Chaque lettre est affiché dans le jeu, puis une capture de la fenêtre est enregistrée. La fréquence est maxi de 6 fps, en allant plus vite l' | ||
- | ====Retaillage, flou et compression==== | + | ====Installation==== |
- | Les images sont en noir et blanc, 320x320. Il faut les retailler en 40x40 et les flouter, puis les compresser. | + | * Blender 2.79b |
+ | * opencv | ||
+ | * numpy | ||
+ | * mon module perso pymultilame | ||
+ | |||
- | Le Blender Game Engine 2.79 permet un affichage mini de 320x280. Les images du jeu sont donc en 320x320. Un script | + | sudo apt install |
+ | sudo pip3 install numpy | ||
+ | sudo pip3 install | ||
+ | sudo apt install blender | ||
+ | Mon module personnel: | ||
+ | sudo pip3 install -e git+https:// | ||
+ | Mise à jour: | ||
+ | sudo pip3 install --upgrade git+https://github.com/ | ||
+ | |||
+ | ====Excécution==== | ||
+ | Lancer | ||
- | {{:2019_01:shot_8_i.png?100|}} {{:2019_01: | + | et faire les 5 étapes, 3 heures et demi pour 1, et un certain temps pour les autres .... |
- | {{:2019_01: | + | |
- | {{:2019_01: | + | Bug connu: le treminal se ferme à la fin de la création des shots avec Blender ! Relancer le terminal et continuer avec 2 |
- | {{:2019_01: | + | ===== L' |
+ | <WRAP group> | ||
+ | <WRAP third column> | ||
+ | Sortie Blender 320x320\\ | ||
+ | {{media_01:shot_0_a_320.png? | ||
+ | {{media_01:shot_1_space_320.png?100|}} | ||
+ | {{media_01:shot_2_b_320.png?100|}} | ||
+ | </ | ||
+ | <WRAP third column> | ||
+ | 40x40, floue en gris\\ | ||
+ | {{media_01:shot_0_a_gray.png?100|}} | ||
+ | {{media_01:shot_1_space_gray.png? | ||
+ | {{media_01:shot_2_b_gray.png?100|}} | ||
+ | </ | ||
+ | <WRAP third column> | ||
+ | 40x40 en Noir et Blanc\\ | ||
+ | {{media_01:shot_0_a.png? | ||
+ | {{media_01:shot_1_.png?100|}} | ||
+ | {{media_01:shot_2_b.png?100|}} | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====1 - Création de 70 000 images==== | ||
+ | Dans un jeu Blender, 70 000 images sont créées, 60 0000 pour entraîner l'IA, 10 000 pour la tester. | ||
+ | Ce jeu lit soit un texte en latin de Cicéron, sans caractères accentués ni spéciaux, soit l' | ||
+ | |||
+ | Chaque lettre est affiché dans le jeu, puis une capture de la fenêtre est enregistrée. La fréquence est maxi de 6 fps, en allant plus vite l' | ||
+ | |||
+ | <wrap em> | ||
+ | <wrap hi> | ||
+ | Ne jamais déplacer ou réduire la fenêtre de Blender pendant la création des images ! | ||
+ | </ | ||
+ | </ | ||
+ | ====2 - Retaillage et flou==== | ||
+ | Le Blender Game Engine 2.79b permet un affichage mini de 320x280. Les images du jeu sont donc en 320x320. Un script python3 avec opencv resize les images à 40x40, les floutent. | ||
- | ====IA==== | ||
- | Ensuite faire l' | ||
+ | ====3 - Compression==== | ||
+ | Pour avoir une excécution plus rapide pour les étapes suivantes. | ||
+ | ====4 - Création du fichier de poids de l' | ||
* **[[l_intelligence_du_semaphore|L' | * **[[l_intelligence_du_semaphore|L' | ||
- | ===== Etape 2 ===== | + | ====5 - Test de l' |
- | En arrière plan, défile le documentaire | + | Le résultat s' |
- | {{ youtube>djbwzEIv7gE? | + | |
+ | ====6 - Modification de la configuration==== | ||
+ | Choisir au moins 60000 images au total, avec: | ||
+ | <WRAP group> | ||
+ | <WRAP third column> | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | <WRAP third column> | ||
+ | | ||
+ | | ||
+ | </WRAP> | ||
+ | <WRAP third column> | ||
+ | * training = 60000 | ||
+ | * testing | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Les meilleurs résultats sont obtenu avec: | ||
+ | * gray = 0 | ||
+ | * blur = 6 | ||
+ | * learningrate = 0.022 | ||
+ | ====Recherche de la meilleure configuration possible==== | ||
+ | **Les hyperparamètres sont tous les paramètres à optimiser : learningrate, | ||
+ | |||
+ | * **[[https:// | ||
+ | * http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | Le fichier best_config_search.py fait ce boulot en autodidacte, | ||
+ | |||
+ | ====Molière==== | ||
+ | **Le chemin est long du projet à la chose.** | ||
+ | |||
+ | |||
===== Ressources sur les sémaphores et le télégraphe de Chappe ===== | ===== Ressources sur les sémaphores et le télégraphe de Chappe ===== | ||
Ligne 39: | Ligne 141: | ||
==== Un alphabet possible ==== | ==== Un alphabet possible ==== | ||
- | {{semaphore_am.png? | + | {{media_12:semaphore_am.png? |
==== Notre alphabet ==== | ==== Notre alphabet ==== | ||
+ | **j = &** | ||
<WRAP group> | <WRAP group> | ||
<WRAP quarter column> | <WRAP quarter column> | ||
- | * **a** {{shot_0_a.png? | + | * **a** {{media_03:shot_0_a.png? |
- | * **b** {{shot_1_b.png? | + | * **b** {{media_03:shot_1_b.png? |
- | * **c** {{shot_2_c.png? | + | * **c** {{media_03:shot_2_c.png? |
- | * **d** {{shot_3_d.png? | + | * **d** {{media_03:shot_3_d.png? |
- | * **e** {{shot_4_e.png? | + | * **e** {{media_03:shot_4_e.png? |
- | * **f** {{shot_5_f.png? | + | * **f** {{media_03:shot_5_f.png? |
- | * **g** {{shot_6_g.png? | + | * **g** {{media_03:shot_6_g.png? |
</ | </ | ||
<WRAP quarter column> | <WRAP quarter column> | ||
- | * **h** {{shot_7_h.png? | + | * **h** {{media_03:shot_7_h.png? |
- | * **i** {{shot_8_i.png? | + | * **i** {{media_03:shot_8_i.png? |
- | * **j** {{shot_9_j.png? | + | * **j** {{media_03:shot_9_j.png? |
- | * **k** {{shot_10_k.png? | + | * **k** {{media_03:shot_10_k.png? |
- | * **l** {{shot_11_l.png? | + | * **l** {{media_03:shot_11_l.png? |
- | * **m** {{shot_12_m.png? | + | * **m** {{media_03:shot_12_m.png? |
- | * **n** {{shot_13_n.png? | + | * **n** {{media_03:shot_13_n.png? |
</ | </ | ||
<WRAP quarter column> | <WRAP quarter column> | ||
- | * **o** {{shot_14_o.png? | + | * **o** {{media_03:shot_14_o.png? |
- | * **p** {{shot_15_p.png? | + | * **p** {{media_03:shot_15_p.png? |
- | * **q** {{shot_16_q.png? | + | * **q** {{media_03:shot_16_q.png? |
- | * **r** {{shot_17_r.png? | + | * **r** {{media_03:shot_17_r.png? |
- | * **s** {{shot_18_s.png? | + | * **s** {{media_03:shot_18_s.png? |
- | * **t** {{shot_19_t.png? | + | * **t** {{media_03:shot_19_t.png? |
- | * **u** {{shot_20_u.png? | + | * **u** {{media_03:shot_20_u.png? |
</ | </ | ||
<WRAP quarter column> | <WRAP quarter column> | ||
- | * **v** {{shot_21_v.png? | + | * **v** {{media_03:shot_21_v.png? |
- | * **w** {{shot_22_w.png? | + | * **w** {{media_03:shot_22_w.png? |
- | * **x** {{shot_23_x.png? | + | * **x** {{media_03:shot_23_x.png? |
- | * **y** {{shot_24_y.png? | + | * **y** {{media_03:shot_24_y.png? |
- | * **z** {{shot_25_z.png? | + | * **z** {{media_03:shot_25_z.png? |
- | * **espace** {{shot_26_ .png?30|}} | + | * **espace** {{media_03:shot_26_.png? |
</ | </ | ||
</ | </ | ||
- | {{tag> | + | {{tag> bge ia sb semaphore }} |
- | + | ||
- | =====Code qui marche de 80 à 88 %===== | + | |
- | <code python> | + | |
- | import numpy as np, cv2 | + | |
- | + | ||
- | def sigmoid(x): return 1 / (1 + np.exp(-x)) | + | |
- | def sigmoid_prime(z): | + | |
- | def relu(x): return np.maximum(0, | + | |
- | def relu_prime(z): | + | |
- | layers = [1600, 100, 100, 27] | + | |
- | activations, | + | |
- | + | ||
- | f = np.load('/ | + | |
- | x_train, y_train = f[' | + | |
- | x_train = 1 - x_train | + | |
- | x_test, y_test = x_train[50000:,: | + | |
- | x_train, y_train = x_train[: | + | |
- | Y = np.eye(27, 27) | + | |
- | activations_prime = [globals()[f.__name__ + ' | + | |
- | A = {} | + | |
- | W = [np.random.randn(layers[k+1], | + | |
- | + | ||
- | print(" | + | |
- | cv2.namedWindow(' | + | |
- | for epoch in range(1): | + | |
- | for i, (a, d) in enumerate(zip(x_train, | + | |
- | if i % 100 == 0: | + | |
- | print(epoch, | + | |
- | cv2.imshow(" | + | |
- | cv2.waitKey(1) | + | |
- | a = np.array(a, ndmin=2).T | + | |
- | A[0] = a | + | |
- | for k in range(len(layers)-1): | + | |
- | z = np.dot(W[k], | + | |
- | a = activations[k](z) | + | |
- | A[k+1] = a | + | |
- | delta_a = a - Y[:,[d]] | + | |
- | for k in range(len(layers)-2, | + | |
- | dz = delta_a * activations_prime[k](A[k+1]) | + | |
- | dW = np.dot(dz, A[k].T) | + | |
- | delta_a = np.dot(W[k].T, | + | |
- | W[k] -= learningrate * dW | + | |
- | print(" | ||
- | S = 0 | ||
- | for a, d in zip(x_test, y_test): | ||
- | for k in range(len(layers)-1): | ||
- | a = activations[k](np.dot(W[k], | ||
- | if np.argmax(a) == d: | ||
- | S += 1 | ||
- | print(" | ||
- | np.save(' | ||
- | </ | ||
jeu_du_semaphore_dans_le_blender_game_engine.1549465635.txt.gz · Dernière modification : 2019/02/06 15:07 de serge