Skip to content

Commit

Permalink
feat(bin): add cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitMY committed Feb 9, 2024
1 parent 1f469a8 commit 8067383
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ class_probabilities = predict(pose)
gloss = predict(pose, label=True)
```

Or in CLI, given a `.pose` file, and an ELAN file with a `SIGN` tier:

```bash
sign_language_recognition --model="kaggle_asl_signs" --pose="sign.pose" --elan="sign.eaf"
```
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ dependencies = [
"pose-format>=0.3.2",
"numpy",
"tflite-runtime",
# for inference using a huggingface hosted model
"huggingface-hub",
"pympi-ling", # Working with ELAN files in CLI
"huggingface-hub", # for inference using a huggingface hosted model
]

[project.optional-dependencies]
Expand Down Expand Up @@ -48,4 +48,7 @@ sign_language_recognition = ["**/*.json"]

[tool.pytest.ini_options]
addopts = "-v"
testpaths = ["sign_language_recognition"]
testpaths = ["sign_language_recognition"]

[project.scripts]
sign_language_recognition = "sign_language_recognition.bin:main"
55 changes: 55 additions & 0 deletions sign_language_recognition/bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python

import argparse
import importlib
import math

from pose_format.pose import Pose
from tqdm import tqdm
import pympi


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--model', required=True, type=str,
choices=['kaggle_asl_signs'],
help='model to use')
parser.add_argument('--pose', required=True, type=str, help='path to input pose file')
parser.add_argument('--elan', required=True, type=str, help='path to elan file')

return parser.parse_args()


def main():
args = get_args()

module = importlib.import_module(f"sign_language_recognition.{args.model}")

print('Loading input pose...')
with open(args.pose, 'rb') as pose_file:
pose = Pose.read(pose_file.read())

print('Loading ELAN file...')
eaf = pympi.Elan.Eaf(file_path=args.elan, author="sign-langauge-processing/recognition")
sign_annotations = eaf.get_annotation_data_for_tier('SIGN')

print('Predicting signs...')
for segment in tqdm(sign_annotations):
start_frame = int((segment[0] / 1000) * pose.body.fps)
end_frame = math.ceil((segment[1] / 1000) * pose.body.fps)

cropped_pose = Pose(
header=pose.header,
body=pose.body[start_frame:end_frame]
)
segment[2] = module.predict(cropped_pose, label=True)
eaf.remove_annotation('SIGN', segment[0])
eaf.add_annotation('SIGN', segment[0], segment[1], segment[2])

print('Saving ELAN file...')
eaf.to_file(args.elan)


if __name__ == '__main__':
main()
# python -m sign_language_recognition.bin --model="kaggle_asl_signs" --pose="sign.pose" --elan="sign.eaf"

0 comments on commit 8067383

Please sign in to comment.