Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
142c26fe
Commit
142c26fe
authored
1 year ago
by
Yoann Schneider
Committed by
Bastien Abadie
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Expose element confidence on CreateElementTranscriptions helper
parent
1c6d4463
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!323
Expose element confidence on CreateElementTranscriptions helper
Pipeline
#80214
passed
1 year ago
Stage: release
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker/transcription.py
+9
-0
9 additions, 0 deletions
arkindex_worker/worker/transcription.py
tests/test_elements_worker/test_transcriptions.py
+27
-0
27 additions, 0 deletions
tests/test_elements_worker/test_transcriptions.py
with
36 additions
and
0 deletions
arkindex_worker/worker/transcription.py
+
9
−
0
View file @
142c26fe
...
...
@@ -227,6 +227,8 @@ class TranscriptionMixin(object):
Required. Confidence score between 0 and 1.
orientation ([TextOrientation][arkindex_worker.worker.transcription.TextOrientation])
Optional. Orientation of the transcription
'
s text.
element_confidence (float)
Optional. Confidence score of the element between 0 and 1.
:returns: A list of dicts as returned by the ``CreateElementTranscriptions`` API endpoint.
"""
...
...
@@ -278,6 +280,12 @@ class TranscriptionMixin(object):
assert
all
(
isinstance
(
coord
,
(
int
,
float
))
for
point
in
polygon
for
coord
in
point
),
f
"
Transcription at index
{
index
}
in transcriptions: polygon points should be lists of two numbers
"
element_confidence
=
transcription
.
get
(
"
element_confidence
"
)
assert
element_confidence
is
None
or
(
isinstance
(
element_confidence
,
float
)
and
0
<=
element_confidence
<=
1
),
f
"
Transcription at index
{
index
}
in transcriptions: element_confidence should be either null or a float in [0..1] range
"
if
self
.
is_read_only
:
logger
.
warning
(
"
Cannot create transcriptions as this worker is in read-only mode
"
...
...
@@ -327,6 +335,7 @@ class TranscriptionMixin(object):
"
image_id
"
:
element
.
image_id
,
"
polygon
"
:
transcription
[
"
polygon
"
],
"
worker_run_id
"
:
self
.
worker_run_id
,
"
confidence
"
:
transcription
.
get
(
"
element_confidence
"
),
}
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_elements_worker/test_transcriptions.py
+
27
−
0
View file @
142c26fe
...
...
@@ -22,6 +22,7 @@ TRANSCRIPTIONS_SAMPLE = [
"
polygon
"
:
[[
0
,
0
],
[
2000
,
0
],
[
2000
,
3000
],
[
0
,
3000
]],
"
confidence
"
:
0.75
,
"
text
"
:
"
first
"
,
"
element_confidence
"
:
0.75
,
},
{
"
polygon
"
:
[[
1000
,
300
],
[
1200
,
300
],
[
1200
,
500
],
[
1000
,
500
]],
...
...
@@ -1244,6 +1245,29 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
==
"
Transcription at index 1 in transcriptions: orientation shouldn
'
t be null and should be of type TextOrientation
"
)
with
pytest
.
raises
(
AssertionError
)
as
e
:
mock_elements_worker
.
create_element_transcriptions
(
element
=
elt
,
sub_element_type
=
"
page
"
,
transcriptions
=
[
{
"
polygon
"
:
[[
0
,
0
],
[
2000
,
0
],
[
2000
,
3000
],
[
0
,
3000
]],
"
confidence
"
:
0.75
,
"
text
"
:
"
The
"
,
},
{
"
polygon
"
:
[[
100
,
150
],
[
700
,
150
],
[
700
,
200
],
[
100
,
200
]],
"
confidence
"
:
0.75
,
"
text
"
:
"
word
"
,
"
element_confidence
"
:
"
not a confidence
"
,
},
],
)
assert
(
str
(
e
.
value
)
==
"
Transcription at index 1 in transcriptions: element_confidence should be either null or a float in [0..1] range
"
)
def
test_create_element_transcriptions_api_error
(
responses
,
mock_elements_worker
):
elt
=
Element
({
"
id
"
:
"
12341234-1234-1234-1234-123412341234
"
})
...
...
@@ -1326,6 +1350,7 @@ def test_create_element_transcriptions(responses, mock_elements_worker):
"
confidence
"
:
0.75
,
"
text
"
:
"
first
"
,
"
orientation
"
:
TextOrientation
.
HorizontalLeftToRight
.
value
,
"
element_confidence
"
:
0.75
,
},
{
"
polygon
"
:
[[
1000
,
300
],
[
1200
,
300
],
[
1200
,
500
],
[
1000
,
500
]],
...
...
@@ -1411,6 +1436,7 @@ def test_create_element_transcriptions_with_cache(
"
confidence
"
:
0.75
,
"
text
"
:
"
first
"
,
"
orientation
"
:
TextOrientation
.
HorizontalLeftToRight
.
value
,
"
element_confidence
"
:
0.75
,
},
{
"
polygon
"
:
[[
1000
,
300
],
[
1200
,
300
],
[
1200
,
500
],
[
1000
,
500
]],
...
...
@@ -1454,6 +1480,7 @@ def test_create_element_transcriptions_with_cache(
type
=
"
page
"
,
polygon
=
"
[[0, 0], [2000, 0], [2000, 3000], [0, 3000]]
"
,
worker_run_id
=
UUID
(
"
56785678-5678-5678-5678-567856785678
"
),
confidence
=
0.75
,
),
]
assert
list
(
CachedTranscription
.
select
())
==
[
...
...
This diff is collapsed.
Click to expand it.
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