Last active
August 28, 2022 20:55
-
-
Save czming/ea66c623f2fe2688ac7eb34ef1a77f81 to your computer and use it in GitHub Desktop.
Processes ground truth label files into HTK labels #aits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
files = glob.glob("*_raw.txt") | |
for file in files: | |
with open(file, "r") as infile: | |
phrase = infile.read().strip() | |
with open(file.replace("_raw.txt", "_place.lab"), "w") as outfile: | |
#prepend sil for HTK formatting | |
outfile.write("sil\n") | |
for token_index in range(0, len(phrase), 2): | |
token = phrase[token_index: token_index + 2] | |
if token[0] == "r": | |
#red object pick and carry | |
outfile.write("b\nf\n") | |
elif token[0] == "b": | |
#blue object pick and carry | |
outfile.write("c\ng\n") | |
elif token[0] == "g": | |
#green object pick and carry | |
outfile.write("d\nh\n") | |
else: | |
raise Exception(f"No such letter found for token[0]: {token}") | |
if token[1] == "1": | |
#place in object bin 1 | |
outfile.write("j\n") | |
elif token[1] == "2": | |
#place in object bin 2 | |
outfile.write("k\n") | |
elif token[1] == "3": | |
#place in object bin 3 | |
outfile.write("l\n") | |
else: | |
raise Exception(f"No such integer found for token[1]: {token}") | |
outfile.write("m\n") | |
#append sil to end the file | |
outfile.write("sil") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment