Jules Musquin commited on
Commit ·
f0064c6
1
Parent(s): 0f6542f
[ADD] Adding a inference script to validate performance of models compared to each other.
Browse files
.gitignore
CHANGED
|
@@ -30,4 +30,5 @@ lib64/
|
|
| 30 |
#website
|
| 31 |
generated_html/
|
| 32 |
annotations/
|
| 33 |
-
dataset/
|
|
|
|
|
|
| 30 |
#website
|
| 31 |
generated_html/
|
| 32 |
annotations/
|
| 33 |
+
dataset/
|
| 34 |
+
test/
|
inference.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import glob
|
| 3 |
+
import os
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
from ultralytics import YOLO
|
| 7 |
+
|
| 8 |
+
# uv run predict.py path_to_model.pt path_to_images ./test
|
| 9 |
+
def parse_args() -> argparse.Namespace:
|
| 10 |
+
parser = argparse.ArgumentParser(
|
| 11 |
+
description="Prédiction YOLO sur un dossier d'images avec sauvegarde des résultats annotés."
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
parser.add_argument(
|
| 15 |
+
"model_path",
|
| 16 |
+
type=str,
|
| 17 |
+
help="Chemin vers le modèle YOLO (.pt)",
|
| 18 |
+
)
|
| 19 |
+
parser.add_argument(
|
| 20 |
+
"images_path",
|
| 21 |
+
type=str,
|
| 22 |
+
help="Dossier contenant les images à traiter",
|
| 23 |
+
)
|
| 24 |
+
parser.add_argument(
|
| 25 |
+
"output_path",
|
| 26 |
+
type=str,
|
| 27 |
+
help="Dossier de sortie pour les images annotées",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
return parser.parse_args()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def predict(model_path:str, images_path:str, output_path:str):
|
| 34 |
+
model = YOLO(model_path)
|
| 35 |
+
images = glob.glob(os.path.join(images_path, "*.jpg"))
|
| 36 |
+
selection = images[:25]
|
| 37 |
+
print(selection)
|
| 38 |
+
results = model(selection)
|
| 39 |
+
name_model = model_path.split('/')
|
| 40 |
+
|
| 41 |
+
output_dir = output_path
|
| 42 |
+
model_dir = name_model[0]
|
| 43 |
+
|
| 44 |
+
if not os.path.isdir(output_dir):
|
| 45 |
+
os.mkdir(output_dir)
|
| 46 |
+
|
| 47 |
+
for i, result in enumerate(results):
|
| 48 |
+
boxes = result.boxes
|
| 49 |
+
im_array = result.plot() # retourne un array numpy BGR avec les boxes dessinées
|
| 50 |
+
|
| 51 |
+
plt.figure(figsize=(10, 10))
|
| 52 |
+
plt.imshow(im_array[..., ::-1]) # conversion BGR -> RGB pour matplotlib
|
| 53 |
+
plt.axis("off")
|
| 54 |
+
plt.show()
|
| 55 |
+
|
| 56 |
+
result.save(filename=os.path.join(output_dir, model_dir, f"result_{i}.jpg")) # sauvegarde avec nom unique
|
| 57 |
+
|
| 58 |
+
def main() -> None:
|
| 59 |
+
args = parse_args()
|
| 60 |
+
predict(args.model_path, args.images_path, args.output_path)
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
main()
|
| 64 |
+
|
predict.ipynb
DELETED
|
File without changes
|
requirement.txt
CHANGED
|
@@ -1,76 +1,128 @@
|
|
| 1 |
anyio==4.14.2
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
exceptiongroup==1.3.1
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
fsspec==2026.6.0
|
| 19 |
h11==0.16.0
|
| 20 |
-
hf==1.24.0
|
| 21 |
-
hf-xet==1.5.2
|
| 22 |
httpcore==1.0.9
|
| 23 |
-
httplib2==0.20.2
|
| 24 |
httpx==0.28.1
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
packaging==26.2
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
ptyprocess==0.7.0
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
anyio==4.14.2
|
| 2 |
+
argon2-cffi==25.1.0
|
| 3 |
+
argon2-cffi-bindings==25.1.0
|
| 4 |
+
arrow==1.4.0
|
| 5 |
+
asttokens==3.0.2
|
| 6 |
+
async-lru==2.3.0
|
| 7 |
+
attrs==26.1.0
|
| 8 |
+
babel==2.18.0
|
| 9 |
+
beautifulsoup4==4.15.0
|
| 10 |
+
bleach==6.4.0
|
| 11 |
+
certifi==2026.7.22
|
| 12 |
+
cffi==2.1.0
|
| 13 |
+
charset-normalizer==3.4.9
|
| 14 |
+
comm==0.2.3
|
| 15 |
+
cuda-bindings==13.3.1
|
| 16 |
+
cuda-pathfinder==1.6.0
|
| 17 |
+
cuda-toolkit==13.0.3.0
|
| 18 |
+
debugpy==1.8.21
|
| 19 |
+
decorator==5.3.1
|
| 20 |
+
defusedxml==0.7.1
|
| 21 |
exceptiongroup==1.3.1
|
| 22 |
+
executing==2.2.1
|
| 23 |
+
fastjsonschema==2.21.2
|
| 24 |
+
filelock==3.32.0
|
| 25 |
+
fqdn==1.5.1
|
| 26 |
fsspec==2026.6.0
|
| 27 |
h11==0.16.0
|
|
|
|
|
|
|
| 28 |
httpcore==1.0.9
|
|
|
|
| 29 |
httpx==0.28.1
|
| 30 |
+
idna==3.18
|
| 31 |
+
ipykernel==7.3.0
|
| 32 |
+
ipython==8.39.0
|
| 33 |
+
ipywidgets==8.1.8
|
| 34 |
+
isoduration==20.11.0
|
| 35 |
+
jedi==0.20.0
|
| 36 |
+
jinja2==3.1.6
|
| 37 |
+
json5==0.15.0
|
| 38 |
+
jsonpointer==3.1.1
|
| 39 |
+
jsonschema==4.26.0
|
| 40 |
+
jsonschema-specifications==2025.9.1
|
| 41 |
+
jupyter==1.1.1
|
| 42 |
+
jupyter-builder==1.1.1
|
| 43 |
+
jupyter-client==8.9.1
|
| 44 |
+
jupyter-console==6.6.3
|
| 45 |
+
jupyter-core==5.9.1
|
| 46 |
+
jupyter-events==0.12.1
|
| 47 |
+
jupyter-lsp==2.3.1
|
| 48 |
+
jupyter-server==2.20.0
|
| 49 |
+
jupyter-server-terminals==0.5.4
|
| 50 |
+
jupyterlab==4.6.2
|
| 51 |
+
jupyterlab-pygments==0.3.0
|
| 52 |
+
jupyterlab-server==2.28.0
|
| 53 |
+
jupyterlab-widgets==3.0.16
|
| 54 |
+
lark==1.3.1
|
| 55 |
+
markupsafe==3.0.3
|
| 56 |
+
matplotlib-inline==0.2.2
|
| 57 |
+
mistune==3.3.4
|
| 58 |
+
mpmath==1.3.0
|
| 59 |
+
nbclient==0.11.0
|
| 60 |
+
nbconvert==7.17.1
|
| 61 |
+
nbformat==5.10.4
|
| 62 |
+
nest-asyncio2==1.7.2
|
| 63 |
+
networkx==3.4.2
|
| 64 |
+
notebook==7.6.1
|
| 65 |
+
notebook-shim==0.2.4
|
| 66 |
+
numpy==2.2.6
|
| 67 |
+
nvidia-cublas==13.1.1.3
|
| 68 |
+
nvidia-cuda-cupti==13.0.85
|
| 69 |
+
nvidia-cuda-nvrtc==13.0.88
|
| 70 |
+
nvidia-cuda-runtime==13.0.96
|
| 71 |
+
nvidia-cudnn-cu13==9.20.0.48
|
| 72 |
+
nvidia-cufft==12.0.0.61
|
| 73 |
+
nvidia-cufile==1.15.1.6
|
| 74 |
+
nvidia-curand==10.4.0.35
|
| 75 |
+
nvidia-cusolver==12.0.4.66
|
| 76 |
+
nvidia-cusparse==12.6.3.3
|
| 77 |
+
nvidia-cusparselt-cu13==0.8.1
|
| 78 |
+
nvidia-nccl-cu13==2.29.7
|
| 79 |
+
nvidia-nvjitlink==13.3.33
|
| 80 |
+
nvidia-nvshmem-cu13==3.4.5
|
| 81 |
+
nvidia-nvtx==13.0.85
|
| 82 |
+
overrides==7.7.0
|
| 83 |
packaging==26.2
|
| 84 |
+
pandocfilters==1.5.1
|
| 85 |
+
parso==0.8.7
|
| 86 |
+
pexpect==4.9.0
|
| 87 |
+
pillow==12.3.0
|
| 88 |
+
platformdirs==4.11.0
|
| 89 |
+
prometheus-client==0.25.0
|
| 90 |
+
prompt-toolkit==3.0.52
|
| 91 |
+
psutil==7.2.2
|
| 92 |
ptyprocess==0.7.0
|
| 93 |
+
pure-eval==0.2.3
|
| 94 |
+
pycparser==3.0
|
| 95 |
+
pygments==2.20.0
|
| 96 |
+
python-dateutil==2.9.0.post0
|
| 97 |
+
python-json-logger==4.1.0
|
| 98 |
+
pyyaml==6.0.3
|
| 99 |
+
pyzmq==27.1.0
|
| 100 |
+
referencing==0.37.0
|
| 101 |
+
requests==2.34.2
|
| 102 |
+
rfc3339-validator==0.1.4
|
| 103 |
+
rfc3986-validator==0.1.1
|
| 104 |
+
rfc3987-syntax==1.1.0
|
| 105 |
+
rpds-py==0.30.0
|
| 106 |
+
send2trash==2.1.0
|
| 107 |
+
setuptools==83.0.0
|
| 108 |
+
six==1.17.0
|
| 109 |
+
soupsieve==2.9.1
|
| 110 |
+
stack-data==0.6.3
|
| 111 |
+
sympy==1.14.0
|
| 112 |
+
terminado==0.18.1
|
| 113 |
+
tinycss2==1.5.1
|
| 114 |
+
tomli==2.4.1
|
| 115 |
+
torch==2.13.0
|
| 116 |
+
torchvision==0.28.0
|
| 117 |
+
tornado==6.5.7
|
| 118 |
+
traitlets==5.15.1
|
| 119 |
+
triton==3.7.1
|
| 120 |
+
typing-extensions==4.16.0
|
| 121 |
+
tzdata==2026.3
|
| 122 |
+
uri-template==1.3.0
|
| 123 |
+
urllib3==2.7.0
|
| 124 |
+
wcwidth==0.8.2
|
| 125 |
+
webcolors==25.10.0
|
| 126 |
+
webencodings==0.5.1
|
| 127 |
+
websocket-client==1.9.0
|
| 128 |
+
widgetsnbextension==4.0.15
|
{test → test_images}/wit396_pdf545/images/1.jpg
RENAMED
|
File without changes
|
{test → test_images}/wit396_pdf545/images/2.jpg
RENAMED
|
File without changes
|
{test → test_images}/wit396_pdf545/labels/1.txt
RENAMED
|
File without changes
|
{test → test_images}/wit396_pdf545/labels/2.txt
RENAMED
|
File without changes
|