====== AI Vision ======
Voir aussi:
* [[/informatique/ign_bdortho|IGN BdOrtho]]
===== llama.cpp =====
Il y a YOLO et tout plein d'outils dédiés à la détection dans des images. Là je teste avec des modèles multimodaux, sans entraînement spécifique.
Le prompt demande s'il y a des panneaux solaire dans l'image fournie, avec sa bbox, et si "oui" de calculer les coordonnées géographiques de l'objet trouvé. Les 2 instructions permettent d'éliminer des faux positifs.
Par exemple le modèle trouve un panneau solaire dans cette image, mais ne trouve pas les coordonnées géo, on peut donc l'évacuer des positifs.
{{:informatique:ai_lm:ai_vision:champ-avec-rayures_18-131487-91478.jpeg?direct&140|champ avec rayures}}
* [[https://github.com/ggml-org/llama.cpp/tree/master/tools/mtmd|Multimodal Support in llama.cpp]]
Nécessite un modèle multimodal et un fichier ''mmproj'' approprié.
==== Tentatives ====
* ticket ouvert: https://github.com/ggml-org/llama.cpp/issues/19639
Avec **llama-mtmd-cli** et **gemma-3-4b-it** :
* [[https://huggingface.co/ggml-org/gemma-3-4b-it-GGUF/resolve/main/gemma-3-4b-it-Q4_K_M.gguf|gemma-3-4b-it-Q4_K_M.gguf]]
* [[https://huggingface.co/ggml-org/gemma-3-4b-it-GGUF/resolve/main/mmproj-model-f16.gguf|mmproj-model-f16.gguf]]
# gemma-3-4b-it-UD-Q8_K_XL
$ time ~/llama.cpp/build/bin/llama-mtmd-cli --log-timestamps \
-m ~/Data/gemma-3-4b-it-UD-Q8_K_XL.gguf \
--mmproj ~/Data/mmproj-model-f16.gguf \
--image ~/Data/screenshot_20260214-141126.png -p 'Vois tu des panneaux solaires sur cette image ?'
main: loading model: ~/Data/gemma-3-4b-it-UD-Q8_K_XL.gguf
WARN: This is an experimental CLI for testing multimodal capability.
For normal use cases, please use the standard llama-cli
encoding image slice...
image slice encoded in 789 ms
decoding image batch 1/1, n_tokens_batch = 256
sched_reserve: reserving ...
sched_reserve: CUDA0 compute buffer size = 517.12 MiB
sched_reserve: CUDA_Host compute buffer size = 269.02 MiB
sched_reserve: graph nodes = 1369
sched_reserve: graph splits = 2
sched_reserve: reserve took 109.44 ms, sched copies = 1
image decoded (batch 1/1) in 201 ms
sched_reserve: reserving ...
sched_reserve: CUDA0 compute buffer size = 517.12 MiB
sched_reserve: CUDA_Host compute buffer size = 269.02 MiB
sched_reserve: graph nodes = 1369
sched_reserve: graph splits = 2
sched_reserve: reserve took 188.38 ms, sched copies = 1
Oui, je vois des panneaux solaires sur l'image. Ils sont disposés sur le toit du bâtiment principal au centre de l'image.
llama_perf_context_print: load time = 2846.21 ms
llama_perf_context_print: prompt eval time = 852.69 ms / 278 tokens ( 3.07 ms per token, 326.03 tokens per second)
llama_perf_context_print: eval time = 542.06 ms / 30 runs ( 18.07 ms per token, 55.34 tokens per second)
llama_perf_context_print: total time = 2344.07 ms / 308 tokens
llama_perf_context_print: graphs reused = 29
real 0m8,165s
user 0m4,880s
sys 0m3,269s
# gemma-3-4b-it-Q4_K_M.gguf
Oui, je vois des panneaux solaires sur l'image. Ils sont installés sur le toit du bâtiment principal, qui est une grande structure rectangulaire.
llama_perf_context_print: load time = 1614.35 ms
llama_perf_context_print: prompt eval time = 856.85 ms / 278 tokens ( 3.08 ms per token, 324.45 tokens per second)
llama_perf_context_print: eval time = 359.10 ms / 33 runs ( 10.88 ms per token, 91.90 tokens per second)
llama_perf_context_print: total time = 2049.84 ms / 311 tokens
llama_perf_context_print: graphs reused = 32
real 0m6,531s
user 0m3,426s
sys 0m3,041s
Avec **llama-mtmd-cli** et **SmolVLM2-2.2B-Instruct** :
# SmolVLM2-2.2B-Instruct-Q4_0
time ~/llama.cpp/build/bin/llama-mtmd-cli -m ~/Data/SmolVLM2-2.2B-Instruct-Q4_0.gguf --mmproj ~/Data/mmproj-SmolVLM2-2.2B-Instruct-f16.gguf --image ~/Data/screenshot_20260214-141126.png -p 'Vois tu des panneaux solaires sur cette image ?' --log-timestamps
build: 7971 (5fa1c190d) with GNU 13.3.0 for Linux x86_64
common_init_result: fitting params to device memory, for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on
gguf_init_from_file_impl: invalid magic characters: 'Entr', expected 'GGUF'
llama_model_load: error loading model: llama_model_loader: failed to load model from ~/Data/SmolVLM2-2.2B-Instruct-Q4_0.gguf
llama_model_load_from_file_impl: failed to load model
llama_params_fit: encountered an error while trying to fit params to free device memory: failed to load model
llama_params_fit: fitting params to free memory took 0.10 seconds
Erreur de segmentation (core dumped)
Avec **llama-mtmd-cli** et **Qwen2-VL-2B-Instruct** :
# Qwen2-VL-2B-Instruct-Q4_0
time ~/llama.cpp/build/bin/llama-mtmd-cli -m ~/Data/Qwen2-VL-2B-Instruct-Q4_0.gguf --mmproj ~/Data/mmproj-Qwen2-VL-2B-Instruct-f16.gguf --image ~/Data/screenshot_20260214-141126.png -p 'Vois tu des panneaux solaires sur cette image ?' --log-timestamps -ngl 99
ggml_cuda_init: found 1 CUDA devices:
Device 0: NVIDIA GeForce RTX 3060, compute capability 8.6, VMM: yes
build: 7971 (5fa1c190d) with GNU 13.3.0 for Linux x86_64
common_init_result: fitting params to device memory, for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on
gguf_init_from_file_impl: invalid magic characters: 'Entr', expected 'GGUF'
llama_model_load: error loading model: llama_model_loader: failed to load model from ~/Data/Qwen2-VL-2B-Instruct-Q4_0.gguf
llama_model_load_from_file_impl: failed to load model
llama_params_fit: encountered an error while trying to fit params to free device memory: failed to load model
llama_params_fit: fitting params to free memory took 0.09 seconds
Erreur de segmentation (core dumped)
Avec **llama-mtmd-cli** et **MobileVLM-3B** :
$ time ~/llama.cpp/build/bin/llama-mtmd-cli -m ~/Data/MobileVLM-3B-q3_K_S.gguf --mmproj ~/Data/MobileVLM-3B-mmproj-f16.gguf --image ~/Data/screenshot_20260214-141126.png -p 'Vois tu des panneaux solaires sur cette image ?' --log-timestamps -ngl 99
ggml_cuda_init: found 1 CUDA devices:
Device 0: NVIDIA GeForce RTX 3060, compute capability 8.6, VMM: yes
build: 7971 (5fa1c190d) with GNU 13.3.0 for Linux x86_64
common_init_result: fitting params to device memory, for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on
gguf_init_from_file_impl: invalid magic characters: 'Repo', expected 'GGUF'
llama_model_load: error loading model: llama_model_loader: failed to load model from ~/Data/MobileVLM-3B-q3_K_S.gguf
llama_model_load_from_file_impl: failed to load model
llama_params_fit: encountered an error while trying to fit params to free device memory: failed to load model
llama_params_fit: fitting params to free memory took 0.09 seconds
Erreur de segmentation (core dumped)
===== Yolo =====
* https://docs.ultralytics.com/models/yolo26/
Comparaison de perf avec le modèle ''yolo26x.pt'' sur 1521 tuiles de 640 pixels:
^ ^ real ^ user ^ sys ^
| CUDA RTX 3060 | 0m25,625s | 0m22,140s | 0m3,480s |
| 13th i7-1360P | 6m3,403s | 48m3,806s | 0m2,906s |
==== Entraînement ====
Construction du jeu de données d’entraînement avec [[https://labelstud.io/|Label Studio]].
Export au format "Yolo + images". Attention, il faut ensuite répartir les images et labels entre "train" et "val".
uv run yolo detect train \
data=dataset_s4-project-1-at-2026-03-07-15-33-9190b7c5.yml \
model=~/Data/AI_ModelsVision/yolo26l.pt \
epochs=130 lr0=0.0005 cos_lr=True augment=True optimizer=AdamW
==== panneaux solaires photovoltaïques ====
Spécialisation à la détection de panneaux solaires photovoltaïques sur les tuiles de [[/informatique/ign_bdortho|IGN BdOrtho]]. Essentiellement les grandes installation comme la bâtis agricoles et toitures d'écoles et bâtiment industriels. Les petits panneaux sur toitures habitation résidentielles sont difficiles à différencier et peuvent être pour chauffer l'eau et pas pour générer de l'électricité. Il y a encore quelques faux positifs, mais à la marge. 😉
Le dataset avec 286 images pour "train" et 50 pour "val" :
{{ :informatique:ai_lm:ai_vision:yolo:solar-panels_project-s4_2026-03-07.zip |}}
Le modèle résultant à partir de **Yolo26L** : {{ :informatique:ai_lm:ai_vision:yolo:yolo26l_solar_panel-s4.pt.zip |}}
=== Détections par départements ===
Les rectangles ont 2 propriétés: la "confidence" de la détection et "file" pour le nom de la tuile.
* 03 Allier {{ :informatique:ai_lm:ai_vision:yolo:bdortho_tuiles-640_03.geojson.zip |}}
* [[https://maproulette.org/browse/challenges/54541|Challenge maproulette]]
* 05 Hautes-Alpes {{ :informatique:ai_lm:ai_vision:yolo:bdortho_tuiles-640_05.geojson.zip |}}
* le modèle hallucine en haute-montagne, mais pas suffisamment de faux-positifs pour justifier un nouvel entraînement
* [[https://maproulette.org/browse/challenges/54542|Challenge maproulette]]
* 09 Ariège {{ :informatique:ai_lm:ai_vision:yolo:bdortho_tuiles-640_09.geojson.zip |}}
* [[https://maproulette.org/browse/challenges/54545|Challenge maproulette]]
* 10 Aube {{ :informatique:ai_lm:ai_vision:yolo:bdortho_tuiles-640_10.geojson.zip |}}
* [[https://maproulette.org/browse/challenges/54550|Challenge maproulette]]
* 22 Côtes-d'Armor {{ :informatique:ai_lm:ai_vision:yolo:bdortho_tuiles-640_22.geojson.zip |}}
* [[https://maproulette.org/browse/challenges/54551|Challenge maproulette]]
* 32 Gers {{ :informatique:ai_lm:ai_vision:yolo:bdortho_tuiles-640_32.geojson.zip |}}
* [[https://maproulette.org/browse/challenges/54538|Challenge maproulette]]
* 37 Indre-et-Loire
* 42 Loire {{ :informatique:ai_lm:ai_vision:yolo:solar-panels_42.geojson.zip |}}
* [[https://maproulette.org/browse/challenges/54565|Challenge maproulette]]
* 43 Haute-Loire
* 44 Loire-Atlantique
* 46 Lot
* 48 Lozère
* 49 Maine-et-Loire
* 50 Manche
* 59 Nord {{ :informatique:ai_lm:ai_vision:yolo:bdortho_tuiles-640_59.geojson.zip |}}
* [[https://maproulette.org/browse/challenges/54555|Challenge maproulette]]
* 63 Puy-de-Dôme
* 65 Hautes-Pyrénées
* 82 Tar-et-Garonne