File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
examples/research_projects/robust-speech-event Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 3
3
import re
4
4
from typing import Dict
5
5
6
+ import torch
6
7
from datasets import Audio , Dataset , load_dataset , load_metric
7
8
8
9
from transformers import AutoFeatureExtractor , pipeline
@@ -78,7 +79,9 @@ def main(args):
78
79
dataset = dataset .cast_column ("audio" , Audio (sampling_rate = sampling_rate ))
79
80
80
81
# load eval pipeline
81
- asr = pipeline ("automatic-speech-recognition" , model = args .model_id )
82
+ if args .device is None :
83
+ args .device = 0 if torch .cuda .is_available () else - 1
84
+ asr = pipeline ("automatic-speech-recognition" , model = args .model_id , device = args .device )
82
85
83
86
# map function to decode audio
84
87
def map_to_pred (batch ):
@@ -123,6 +126,12 @@ def map_to_pred(batch):
123
126
parser .add_argument (
124
127
"--log_outputs" , action = "store_true" , help = "If defined, write outputs to log file for analysis."
125
128
)
129
+ parser .add_argument (
130
+ "--device" ,
131
+ type = int ,
132
+ default = None ,
133
+ help = "The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on." ,
134
+ )
126
135
args = parser .parse_args ()
127
136
128
137
main (args )
You can’t perform that action at this time.
0 commit comments