Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Commits
b080ea98
Unverified
Commit
b080ea98
authored
1 year ago
by
Mélodie Boillet
Committed by
Yoann Schneider
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for prediction code
parent
15e907b5
No related branches found
No related tags found
No related merge requests found
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/data/training/training_dataset/labels.json
+26
-0
26 additions, 0 deletions
tests/data/training/training_dataset/labels.json
tests/test_prediction.py
+55
-0
55 additions, 0 deletions
tests/test_prediction.py
tests/test_training.py
+1
-1
1 addition, 1 deletion
tests/test_training.py
with
82 additions
and
1 deletion
tests/data/training
_page
/labels.json
→
tests/data/training
/training_dataset
/labels.json
+
26
−
0
View file @
b080ea98
{
"test"
:
{
"tests/data/training
_page
/images/fb3edb59-3678-49f8-8e16-8e32e3b0f051.png"
:
{
"tests/data/training
/training_dataset
/images/fb3edb59-3678-49f8-8e16-8e32e3b0f051.png"
:
{
"text"
:
"Both her wrists bore"
},
"tests/data/training
_page
/images/fe498de2-ece4-4fbe-8b53-edfce1b820f0.png"
:
{
"tests/data/training
/training_dataset
/images/fe498de2-ece4-4fbe-8b53-edfce1b820f0.png"
:
{
"text"
:
"SOME years ago a contemporary"
}
},
"train"
:
{
"tests/data/training
_page
/images/0a34e13a-4ab0-4a91-8d7c-b1d8fee32628.png"
:
{
"tests/data/training
/training_dataset
/images/0a34e13a-4ab0-4a91-8d7c-b1d8fee32628.png"
:
{
"text"
:
"The latter do not regard"
},
"tests/data/training
_page
/images/0a70e14f-feda-4607-989c-36cf581ddff5.png"
:
{
"tests/data/training
/training_dataset
/images/0a70e14f-feda-4607-989c-36cf581ddff5.png"
:
{
"text"
:
"At the beginning of"
}
},
"val"
:
{
"tests/data/training
_page
/images/0a576062-303c-4893-a729-c09c92865d31.png"
:
{
"tests/data/training
/training_dataset
/images/0a576062-303c-4893-a729-c09c92865d31.png"
:
{
"text"
:
"One can remember with"
},
"tests/data/training
_page
/images/0b2457c8-81f1-4600-84d9-f8bf2822a991.png"
:
{
"tests/data/training
/training_dataset
/images/0b2457c8-81f1-4600-84d9-f8bf2822a991.png"
:
{
"text"
:
"The play was no more"
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/test_prediction.py
0 → 100644
+
55
−
0
View file @
b080ea98
# -*- coding: utf-8 -*-
import
pytest
import
torch
from
dan.predict.prediction
import
DAN
from
dan.utils
import
read_image
@pytest.mark.parametrize
(
"
image_name, expected_prediction
"
,
(
(
"
0a56e8b3-95cd-4fa5-a17b-5b0ff9e6ea84.png
"
,
{
"
text
"
:
[
"
ⓈBellisson ⒻGeorges Ⓑ91 ⓁP ⒸM ⓀCh ⓄPlombier ⓅPatron?12241
"
]},
),
(
"
0dfe8bcd-ed0b-453e-bf19-cc697012296e.png
"
,
{
"
text
"
:
[
"
ⓈTemplié ⒻMarcelle Ⓑ93 ⓁS Ⓚch ⓄE dactylo Ⓟ18376
"
]},
),
(
"
2c242f5c-e979-43c4-b6f2-a6d4815b651d.png
"
,
{
"
text
"
:
[
"
Ⓢd ⒻCharles Ⓑ11 ⓁP ⒸC ⓀF Ⓞd Ⓟ14 31
"
]},
),
(
"
ffdec445-7f14-4f5f-be44-68d0844d0df1.png
"
,
{
"
text
"
:
[
"
ⓈNaudin ⒻMarie Ⓑ53 ⓁS Ⓒv ⓀBelle mère
"
]},
),
),
)
def
test_predict
(
image_name
,
expected_prediction
,
prediction_data_path
,
):
device
=
"
cpu
"
dan_model
=
DAN
(
device
)
dan_model
.
load
(
prediction_data_path
/
"
popp_line_model.pt
"
,
prediction_data_path
/
"
parameters.yml
"
,
prediction_data_path
/
"
charset.pkl
"
,
mode
=
"
eval
"
,
)
image
=
read_image
(
prediction_data_path
/
"
images
"
/
image_name
)
image
=
dan_model
.
preprocess
(
image
)
input_tensor
=
torch
.
tensor
(
image
).
permute
(
2
,
0
,
1
).
unsqueeze
(
0
)
input_tensor
=
input_tensor
.
to
(
device
)
input_sizes
=
[
image
.
shape
[:
2
]]
prediction
=
dan_model
.
predict
(
input_tensor
,
input_sizes
)
assert
prediction
==
expected_prediction
This diff is collapsed.
Click to expand it.
tests/test_training.py
+
1
−
1
View file @
b080ea98
...
...
@@ -57,7 +57,7 @@ def test_train_and_test(
# Check that the trained model is correct
for
model_name
in
[
expected_best_model_name
,
expected_last_model_name
]:
expected_model
=
torch
.
load
(
FIXTURES
/
"
training
"
/
model_name
)
expected_model
=
torch
.
load
(
FIXTURES
/
"
training
"
/
"
models
"
/
model_name
)
trained_model
=
torch
.
load
(
Path
(
"
outputs
"
,
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment