Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
196cce6e
Unverified
Commit
196cce6e
authored
Jan 27, 2022
by
Anton Lozhkov
Committed by
GitHub
Jan 27, 2022
Browse files
Add a device argument to the eval script (#15371)
* Device argument for the eval script * Default to none * isort
parent
6beae766
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletion
+10
-1
examples/research_projects/robust-speech-event/eval.py
examples/research_projects/robust-speech-event/eval.py
+10
-1
No files found.
examples/research_projects/robust-speech-event/eval.py
View file @
196cce6e
...
...
@@ -3,6 +3,7 @@ import argparse
import
re
from
typing
import
Dict
import
torch
from
datasets
import
Audio
,
Dataset
,
load_dataset
,
load_metric
from
transformers
import
AutoFeatureExtractor
,
pipeline
...
...
@@ -78,7 +79,9 @@ def main(args):
dataset
=
dataset
.
cast_column
(
"audio"
,
Audio
(
sampling_rate
=
sampling_rate
))
# load eval pipeline
asr
=
pipeline
(
"automatic-speech-recognition"
,
model
=
args
.
model_id
)
if
args
.
device
is
None
:
args
.
device
=
0
if
torch
.
cuda
.
is_available
()
else
-
1
asr
=
pipeline
(
"automatic-speech-recognition"
,
model
=
args
.
model_id
,
device
=
args
.
device
)
# map function to decode audio
def
map_to_pred
(
batch
):
...
...
@@ -123,6 +126,12 @@ if __name__ == "__main__":
parser
.
add_argument
(
"--log_outputs"
,
action
=
"store_true"
,
help
=
"If defined, write outputs to log file for analysis."
)
parser
.
add_argument
(
"--device"
,
type
=
int
,
default
=
None
,
help
=
"The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on."
,
)
args
=
parser
.
parse_args
()
main
(
args
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment