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
df229f93
Commit
df229f93
authored
1 year ago
by
Manon Blanco
Committed by
Solene Tarride
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Enable to use GPU for teklia_dan_predict
parent
be01536c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!192
Enable to use GPU for teklia_dan_predict
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dan/predict/__init__.py
+6
-0
6 additions, 0 deletions
dan/predict/__init__.py
dan/predict/prediction.py
+4
-1
4 additions, 1 deletion
dan/predict/prediction.py
with
10 additions
and
1 deletion
dan/predict/__init__.py
+
6
−
0
View file @
df229f93
...
...
@@ -148,4 +148,10 @@ def add_predict_parser(subcommands) -> None:
type
=
int
,
default
=
0
,
)
parser
.
add_argument
(
"
--gpu-device
"
,
help
=
"
Use a specific GPU if available.
"
,
type
=
int
,
required
=
False
,
)
parser
.
set_defaults
(
func
=
run
)
This diff is collapsed.
Click to expand it.
dan/predict/prediction.py
+
4
−
1
View file @
df229f93
...
...
@@ -391,6 +391,7 @@ def run(
threshold_method
,
threshold_value
,
image_extension
,
gpu_device
,
):
"""
Predict a single image save the output
...
...
@@ -411,13 +412,15 @@ def run(
:param predict_objects: Whether to extract objects.
:param threshold_method: Thresholding method. Should be in [
"
otsu
"
,
"
simple
"
].
:param threshold_value: Thresholding value to use for the
"
simple
"
thresholding method.
:param gpu_device: Use a specific GPU if available.
"""
# Create output directory if necessary
if
not
os
.
path
.
exists
(
output
):
os
.
makedirs
(
output
,
exist_ok
=
True
)
# Load model
device
=
"
cuda
"
if
torch
.
cuda
.
is_available
()
else
"
cpu
"
cuda_device
=
f
"
:
{
gpu_device
}
"
if
gpu_device
is
not
None
else
""
device
=
f
"
cuda
{
cuda_device
}
"
if
torch
.
cuda
.
is_available
()
else
"
cpu
"
dan_model
=
DAN
(
device
,
temperature
)
dan_model
.
load
(
model
,
parameters
,
charset
,
mode
=
"
train
"
)
if
image
:
...
...
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