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
!311
Make normalization optional
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Make normalization optional
optional-normalization
into
main
Overview
3
Commits
2
Pipelines
0
Changes
2
All threads resolved!
Show all comments
Merged
Manon Blanco
requested to merge
optional-normalization
into
main
1 year ago
Overview
3
Commits
2
Pipelines
0
Changes
2
All threads resolved!
Show all comments
Expand
Closes
#216 (closed)
0
0
Merge request reports
Compare
main
version 2
259df647
1 year ago
version 1
6d9a1591
1 year ago
main (base)
and
latest version
latest version
c05ca47c
2 commits,
1 year ago
version 2
259df647
2 commits,
1 year ago
version 1
6d9a1591
1 commit,
1 year ago
2 files
+
38
−
8
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
dan/ocr/predict/inference.py
+
16
−
6
Options
@@ -109,8 +109,8 @@ class DAN:
)
self
.
mean
,
self
.
std
=
(
torch
.
tensor
(
parameters
[
"
mean
"
])
/
255
,
torch
.
tensor
(
parameters
[
"
std
"
])
/
255
,
torch
.
tensor
(
parameters
[
"
mean
"
])
/
255
if
"
mean
"
in
parameters
else
None
,
torch
.
tensor
(
parameters
[
"
std
"
])
/
255
if
"
std
"
in
parameters
else
None
,
)
self
.
preprocessing_transforms
=
get_preprocessing_transforms
(
parameters
.
get
(
"
preprocessings
"
,
[])
@@ -124,11 +124,21 @@ class DAN:
"""
image
=
read_image
(
path
)
preprocessed_image
=
self
.
preprocessing_transforms
(
image
)
normalized_image
=
torch
.
zeros
(
preprocessed_image
.
shape
)
for
ch
in
range
(
preprocessed_image
.
shape
[
0
]):
if
self
.
mean
is
None
and
self
.
std
is
None
:
return
preprocessed_image
,
preprocessed_image
size
=
preprocessed_image
.
shape
normalized_image
=
torch
.
zeros
(
size
)
mean
=
self
.
mean
if
self
.
mean
is
not
None
else
torch
.
zeros
(
size
[
0
])
std
=
self
.
std
if
self
.
std
is
not
None
else
torch
.
ones
(
size
[
0
])
for
ch
in
range
(
size
[
0
]):
normalized_image
[
ch
,
:,
:]
=
(
preprocessed_image
[
ch
,
:,
:]
-
self
.
mean
[
ch
]
)
/
self
.
std
[
ch
]
preprocessed_image
[
ch
,
:,
:]
-
mean
[
ch
]
)
/
std
[
ch
]
return
preprocessed_image
,
normalized_image
def
predict
(
Loading