You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
help="Perform dry-run to verify options prior to running. Also useful to instantiate cuda/tensorflow cache prior to running multiple times.")
142
124
143
-
ifos.path.isfile(args.file):
144
-
input_file=args.file
145
-
print("\nInput file:", input_file)
125
+
#Files that should be supplied
126
+
#File no longer required here, but will check manually later
127
+
#Basically EITHER file OR dry-run is sufficient
128
+
parser.add_argument('--file', required=False,
129
+
help='Input video file')
130
+
parser.add_argument('--model', required=False,
131
+
help='Input *.pbmm model file')
132
+
parser.add_argument('--scorer', required=False,
133
+
help='Input *.scorer file')
134
+
135
+
args=parser.parse_args()
136
+
137
+
#Please keep the following because I need it for verifying dockerfiles.
138
+
print(sys.argv[0:])
139
+
print("ARGS:", args)
140
+
141
+
defgetmodel(args, arg_name):
142
+
#prioritize supplied argument
143
+
144
+
ifarg_name=='model':
145
+
arg_extension='.pbmm'
146
+
elifarg_name=='scorer':
147
+
arg_extension='.scorer'
148
+
else:
149
+
print("Coding Error. This function only accepts model or scorer for arg_name.")
150
+
sys.exit(1)
151
+
152
+
arg=args.__getattribute__(arg_name)
153
+
154
+
ifargisnotNone:
155
+
model=os.path.abspath(arg)
156
+
ifnotos.path.isfile(model):
157
+
print(f"Error. Supplied file {arg} doesn't exist. Please supply a valid {arg_name} file via the --{arg_name} flag.")
158
+
sys.exit(1)
159
+
else:
160
+
#try to find local models
161
+
models_=os.listdir()
162
+
models= []
163
+
forfileinmodels_:
164
+
iffile.endswith(arg_extension):
165
+
models.append(file)
166
+
del(models_)
167
+
168
+
num_models=len(models)
169
+
170
+
ifnum_models==0:
171
+
print(f"Warning no {arg_name}s specified via --{arg_name} and none found in local directory. Please run getmodel.sh convenience script from autosub repo to get some.")
172
+
ifarg_name=='model':
173
+
print("Error: Must have pbmm model. Exiting")
174
+
sys.exit(1)
175
+
else:
176
+
model=''
177
+
elifnum_models!=1:
178
+
print(f"Warning. Detected multiple *{arg_extension} files in local dir. You must specify which one you wish to use via the --{arg_name} field. Details: \n{num_models}{models}")
179
+
ifarg_name=='model':
180
+
print("Error: Must specify pbmm model. Exiting")
181
+
sys.exit(1)
182
+
else:
183
+
print("Since I cannot know which scorer you wish to use, I just won't use any and try to run inference without it.")
184
+
model=''
185
+
else:
186
+
model=os.path.abspath(models[0])
187
+
188
+
print(f"{arg_name}: ", model)
189
+
return(model)
190
+
191
+
defInstantiateModel(model, scorer):
192
+
# Load DeepSpeech model
193
+
try:
194
+
ds=Model(model)
195
+
except:
196
+
print("Invalid model file. Exiting\n")
197
+
sys.exit(1)
198
+
199
+
try:
200
+
ds.enableExternalScorer(scorer)
201
+
except:
202
+
print("Invalid scorer file. Running inference using only model file\n")
203
+
return(ds)
204
+
205
+
206
+
ds_model=getmodel(args, 'model')
207
+
ds_scorer=getmodel(args, 'scorer')
208
+
209
+
ifargs.dry_run:
210
+
InstantiateModel(ds_model, ds_scorer)
211
+
ifargs.fileisnotNone:
212
+
ifnotos.path.isfile(args.file):
213
+
print(f"Error: {args.file}: No such file exists")
214
+
sys.exit(0)
215
+
216
+
#Not a dry-run
217
+
ifargs.fileisnotNone:
218
+
ifos.path.isfile(args.file):
219
+
input_file=args.file
220
+
print("\nInput file:", input_file)
221
+
else:
222
+
print(args.file, ": No such file exists")
223
+
sys.exit(1)
146
224
else:
147
-
print(args.file, ": No such file exists")
225
+
print("Error. You must supply a file with --file or to instantiate cuda cache you must supply a --dry-run.")
0 commit comments