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
Merge requests
!124
Remove get_valid_fonts function
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Remove get_valid_fonts function
remove-get-valid-fonts-function
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Thibault Lavigne
requested to merge
remove-get-valid-fonts-function
into
main
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#68 (closed)
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
42e152ae
1 commit,
1 year ago
1 file
+
0
−
31
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
dan/manager/ocr.py
+
0
−
31
Options
@@ -9,7 +9,6 @@ import torch
from
fontTools.ttLib
import
TTFont
from
PIL
import
Image
,
ImageDraw
,
ImageFont
from
dan
import
logger
from
dan.manager.dataset
import
DatasetManager
,
GenericDataset
,
apply_preprocessing
from
dan.ocr.utils
import
LM_str_to_ind
from
dan.utils
import
(
@@ -42,8 +41,6 @@ class OCRDatasetManager(DatasetManager):
and
self
.
params
[
"
config
"
][
"
synthetic_data
"
]
):
self
.
synthetic_data
=
self
.
params
[
"
config
"
][
"
synthetic_data
"
]
if
"
config
"
in
self
.
synthetic_data
:
self
.
synthetic_data
[
"
config
"
][
"
valid_fonts
"
]
=
self
.
get_valid_fonts
()
if
"
new_tokens
"
in
params
:
self
.
charset
=
sorted
(
@@ -104,34 +101,6 @@ class OCRDatasetManager(DatasetManager):
[
s
[
"
img
"
].
shape
[
1
]
for
s
in
self
.
train_dataset
.
samples
]
)
def
get_valid_fonts
(
self
):
"""
Select fonts that are compatible with the alphabet
"""
font_path
=
self
.
synthetic_data
[
"
font_path
"
]
alphabet
=
self
.
charset
.
copy
()
special_chars
=
[
"
\n
"
]
alphabet
=
[
char
for
char
in
alphabet
if
char
not
in
special_chars
]
valid_fonts
=
list
()
for
fold_detail
in
os
.
walk
(
font_path
):
if
fold_detail
[
2
]:
for
font_name
in
fold_detail
[
2
]:
if
"
.ttf
"
not
in
font_name
:
continue
font_path
=
os
.
path
.
join
(
fold_detail
[
0
],
font_name
)
to_add
=
True
if
alphabet
is
not
None
:
for
char
in
alphabet
:
if
not
char_in_font
(
char
,
font_path
):
to_add
=
False
break
if
to_add
:
valid_fonts
.
append
(
font_path
)
else
:
valid_fonts
.
append
(
font_path
)
logger
.
info
(
f
"
Found
{
len
(
valid_fonts
)
}
fonts.
"
)
return
valid_fonts
class
OCRDataset
(
GenericDataset
):
"""
Loading