Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qbe
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
A
Anaïs Halftermeyer
queryByExample
qbe
Commits
aa8bb297
Commit
aa8bb297
authored
Jun 25, 2025
by
Elias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
script added
parent
b62ee38e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
0 deletions
+124
-0
TrainValTest2_Random.py
TrainValTest2_Random.py
+124
-0
No files found.
TrainValTest2_Random.py
0 → 100755
View file @
aa8bb297
import
csv
import
os
import
random
repertoire
=
"textGridEnCSV"
# Fichiers placés directement en val et test
fichiers_test_direct
=
{
"1023-FA.csv"
,
"1029-HB2.csv"
}
fichiers_val_direct
=
{
"1014-SZ.csv"
,
"1021_bis-TA.csv"
,
"1021-TA.csv"
}
# Stockage
decoupes
=
[]
restant
=
[]
# lignes à répartir
# Stats
total_lignes_global
=
0
val_direct
=
[]
test_direct
=
[]
# Collecter toutes les lignes
for
fichier
in
os
.
listdir
(
repertoire
):
if
not
fichier
.
endswith
(
".csv"
):
continue
chemin
=
os
.
path
.
join
(
repertoire
,
fichier
)
with
open
(
chemin
,
mode
=
"r"
,
newline
=
""
)
as
f
:
reader
=
csv
.
reader
(
f
)
next
(
reader
)
# pour ignorer l'en-tête
lignes
=
[
row
for
row
in
reader
if
row
[
2
]
.
strip
()]
total
=
len
(
lignes
)
total_lignes_global
+=
total
lignes_bounds
=
[(
float
(
row
[
0
]),
float
(
row
[
1
]),
row
[
2
]
.
strip
())
for
row
in
lignes
]
if
fichier
in
fichiers_test_direct
:
decoupes
.
append
({
"fichier"
:
fichier
,
"Train"
:
[],
"Val"
:
[],
"Test"
:
lignes_bounds
})
test_direct
.
extend
(
lignes_bounds
)
elif
fichier
in
fichiers_val_direct
:
decoupes
.
append
({
"fichier"
:
fichier
,
"Train"
:
[],
"Val"
:
lignes_bounds
,
"Test"
:
[]
})
val_direct
.
extend
(
lignes_bounds
)
else
:
# À répartir plus tard dans le global
restant
.
append
((
fichier
,
lignes_bounds
))
# Constitution du global
all_restant
=
[]
fichier_to_rows
=
{}
for
fichier
,
lignes
in
restant
:
for
ligne
in
lignes
:
all_restant
.
append
((
fichier
,
ligne
))
fichier_to_rows
[
fichier
]
=
[]
# Mélange et découpage global
random
.
shuffle
(
all_restant
)
reste
=
total_lignes_global
-
len
(
val_direct
)
-
len
(
test_direct
)
n_val_cible
=
int
(
total_lignes_global
*
0.10
)
-
len
(
val_direct
)
n_test_cible
=
int
(
total_lignes_global
*
0.10
)
-
len
(
test_direct
)
n_train_cible
=
reste
-
n_val_cible
-
n_test_cible
train
,
val
,
test
=
[],
[],
[]
for
fichier
,
ligne
in
all_restant
:
if
len
(
train
)
<
n_train_cible
:
train
.
append
((
fichier
,
ligne
))
elif
len
(
val
)
<
n_val_cible
:
val
.
append
((
fichier
,
ligne
))
else
:
test
.
append
((
fichier
,
ligne
))
# Regrouper par fichier
fichier_to_bounds
=
{
fichier
:
{
"Train"
:
[],
"Val"
:
[],
"Test"
:
[]}
for
fichier
in
fichier_to_rows
}
for
fichier
,
ligne
in
train
:
fichier_to_bounds
[
fichier
][
"Train"
]
.
append
(
ligne
)
for
fichier
,
ligne
in
val
:
fichier_to_bounds
[
fichier
][
"Val"
]
.
append
(
ligne
)
for
fichier
,
ligne
in
test
:
fichier_to_bounds
[
fichier
][
"Test"
]
.
append
(
ligne
)
# Ajouter à la sortie finale
for
fichier
in
fichier_to_bounds
:
decoupes
.
append
({
"fichier"
:
fichier
,
"Train"
:
fichier_to_bounds
[
fichier
][
"Train"
],
"Val"
:
fichier_to_bounds
[
fichier
][
"Val"
],
"Test"
:
fichier_to_bounds
[
fichier
][
"Test"
],
})
# Affichage
for
d
in
decoupes
:
print
(
f
"
\n
{d['fichier']}"
)
print
(
" Train :"
,
d
[
"Train"
])
print
(
" Val :"
,
d
[
"Val"
])
print
(
" Test :"
,
d
[
"Test"
])
# Statistiques
nb_train
=
sum
(
len
(
d
[
"Train"
])
for
d
in
decoupes
)
nb_val
=
sum
(
len
(
d
[
"Val"
])
for
d
in
decoupes
)
nb_test
=
sum
(
len
(
d
[
"Test"
])
for
d
in
decoupes
)
print
(
"
\n
--- STATISTIQUES ---"
)
print
(
f
"Total lignes : {total_lignes_global}"
)
print
(
f
"Train : {nb_train} lignes ({nb_train / total_lignes_global * 100:.2f}
%
)"
)
print
(
f
"Val : {nb_val} lignes ({nb_val / total_lignes_global * 100:.2f}
%
)"
)
print
(
f
"Test : {nb_test} lignes ({nb_test / total_lignes_global * 100:.2f}
%
)"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment