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
5d8a8cf8
Unverified
Commit
5d8a8cf8
authored
1 year ago
by
Yoann Schneider
Browse files
Options
Downloads
Patches
Plain Diff
Remove obsolete format module
parent
1392f95f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!272
Remove obsolete format module
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dan/datasets/format/atr.py
+0
-84
0 additions, 84 deletions
dan/datasets/format/atr.py
with
0 additions
and
84 deletions
dan/datasets/format/atr.py
deleted
100644 → 0
+
0
−
84
View file @
1392f95f
# -*- coding: utf-8 -*-
import
json
import
pickle
import
re
from
collections
import
defaultdict
from
pathlib
import
Path
from
tqdm
import
tqdm
def
remove_spaces
(
text
):
# remove begin/ending spaces
text
=
text
.
strip
()
# replace \t with regular space
text
=
re
.
sub
(
"
\t
"
,
"
"
,
text
)
# remove consecutive spaces
text
=
re
.
sub
(
"
+
"
,
"
"
,
text
)
return
text
class
ATRDatasetFormatter
:
"""
Global pipeline/functions for dataset formatting
"""
def
__init__
(
self
,
dataset
:
Path
,
image_format
:
str
,
remove_spaces
:
bool
):
self
.
dataset
=
dataset
self
.
set_names
=
[
"
train
"
,
"
val
"
,
"
test
"
]
self
.
remove_spaces
=
remove_spaces
self
.
image_folder
=
self
.
dataset
/
"
images
"
self
.
labels_folder
=
self
.
dataset
/
"
labels
"
self
.
image_format
=
image_format
if
self
.
image_format
.
startswith
(
"
.
"
):
self
.
image_format
=
self
.
image_format
[
1
:]
def
format
(
self
):
"""
Format ATR dataset
"""
ground_truth
=
defaultdict
(
dict
)
charset
=
set
()
for
set_name
in
self
.
set_names
:
set_folder
=
self
.
labels_folder
/
set_name
for
file_name
in
tqdm
(
set_folder
.
iterdir
(),
desc
=
"
Formatting
"
+
set_name
):
data
=
self
.
parse_labels
(
set_name
,
file_name
)
charset
=
charset
.
union
(
set
(
data
[
"
label
"
]))
ground_truth
[
set_name
][
data
[
"
img_path
"
]]
=
{
"
text
"
:
data
[
"
label
"
],
}
return
ground_truth
,
charset
def
read_file
(
self
,
file_name
:
Path
):
text
=
file_name
.
read_text
()
if
self
.
remove_spaces
:
text
=
remove_spaces
(
text
)
return
text
.
strip
()
def
parse_labels
(
self
,
set_name
:
str
,
file_name
:
Path
):
return
{
"
img_path
"
:
(
self
.
image_folder
/
set_name
/
file_name
.
stem
)
.
with_suffix
(
self
.
image_format
)
.
resolve
(),
"
label
"
:
self
.
read_file
(
self
.
labels_folder
/
set_name
/
file_name
.
name
),
}
def
run
(
self
):
ground_truth
,
charset
=
self
.
format
()
(
self
.
dataset
/
"
labels.json
"
).
write_text
(
json
.
dumps
(
ground_truth
,
sort_keys
=
True
,
indent
=
4
,
)
)
(
self
.
dataset
/
"
charset.pkl
"
).
write_bytes
(
pickle
.
dumps
(
sorted
(
list
(
charset
))))
def
run
(
dataset
,
image_format
,
keep_spaces
):
ATRDatasetFormatter
(
dataset
=
dataset
,
image_format
=
image_format
,
remove_spaces
=
not
keep_spaces
).
run
()
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