in ocr/utils/sclite_helper.py [0:0]
def _run_sclite(self, predicted_filename, actual_filename, mode, output):
'''
Run command line for sclite.
Parameters
---------
predicted_filename: str
file containing output string of the network
actual_filename: str
file containing string of the label
mode: string, Options = ["CER", "WER"]
Choose between CER or WER
output: string, Options = ["print", "string"]
Choose between printing the output or returning a string
Returns
-------
stdoutput
If string was chosen as the output option, this function will return a file
containing the stdout
'''
assert mode in ["CER", "WER"], "mode {} is not in ['CER', 'WER]".format(mode)
assert output in ["print", "string"], "output {} is not in ['print', 'string']".format(
output)
command_line = [os.path.join(self.sclite_location, "sclite"),
"-h", os.path.join(self.tmp_file_location, predicted_filename),
"-r", os.path.join(self.tmp_file_location, actual_filename),
"-i", "rm"]
if mode == "WER":
pass # Word error rate is by default
retries = 10
for i in range(retries):
try:
if mode == "CER":
command_line.append("-c")
if output == "print":
subprocess.call(command_line)
elif output == "string":
cmd = subprocess.Popen(command_line, stdout=subprocess.PIPE)
return cmd.stdout
except:
print("There was an error")